[ 
https://issues.apache.org/jira/browse/GROOVY-9159?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Daniel Sun updated GROOVY-9159:
-------------------------------
    Description: 
_{color:#d04437}(Note: The exact syntax might be altered before introduction, 
currently working on the general principle){color}_

GINQ will reuse most of standard SQL syntax, which can make the learning curve 
smooth and avoid infringing the patent of Microsoft.

All GINQ related keywords are uppercase to avoid breaking existing source code 
as possible as we can, e.g. {{FROM}}, {{WHERE}}, {{SELECT}}, etc.

*EBNF*

    TBD 

*Examples*
1. Filtering
{code:java}
def numbers = [1, 2, 3]

def result =
        FROM numbers t       // t is an alias
        WHERE t.VALUE <= 2
        SELECT t.VALUE

assert [1, 2] == result
{code}
{code:java}
@groovy.transform.EqualsAndHashCode
class Person {
        String name
        int age
}

def persons = [new Person(name: 'Daniel', age: 35), new Person(name: 'Peter', 
age: 10), new Person(name: 'Alice', age: 22)]

def result =
        FROM persons p       // p is an alias
        WHERE p.age > 15 AND p.age <= 35
        SELECT p.name

assert ['Daniel', 'Alice'] == result

result =
        FROM persons p       // p is an alias
        WHERE p.age > 15 AND p.age <= 35
        SELECT p

assert [new Person(name: 'Daniel', age: 35), new Person(name: 'Alice', age: 
22)] == result
{code}
 

  was:
Reusing most of standard SQL syntax can make the learning curve smooth and 
avoid infringing the patent of Microsoft.
_{color:#d04437}(Note: The exact syntax might be altered before introduction, 
currently working on the general principle){color}_

All GINQ related keywords are uppercase to avoid breaking existing source code 
as possible as we can, e.g. {{FROM}}, {{WHERE}}, {{SELECT}}, etc.

Here are some examples to show the proposed syntax:
 *Filtering*
{code:java}
def numbers = [1, 2, 3]

def result =
        FROM numbers t       // t is an alias
        WHERE t.VALUE <= 2
        SELECT t.VALUE

assert [1, 2] == result
{code}
{code:java}
@groovy.transform.EqualsAndHashCode
class Person {
        String name
        int age
}

def persons = [new Person(name: 'Daniel', age: 35), new Person(name: 'Peter', 
age: 10), new Person(name: 'Alice', age: 22)]

def result =
        FROM persons p       // p is an alias
        WHERE p.age > 15 AND p.age <= 35
        SELECT p.name

assert ['Daniel', 'Alice'] == result

result =
        FROM persons p       // p is an alias
        WHERE p.age > 15 AND p.age <= 35
        SELECT p

assert [new Person(name: 'Daniel', age: 35), new Person(name: 'Alice', age: 
22)] == result
{code}
TBD EBNF


> [GEP] Support LINQ, aka GINQ
> ----------------------------
>
>                 Key: GROOVY-9159
>                 URL: https://issues.apache.org/jira/browse/GROOVY-9159
>             Project: Groovy
>          Issue Type: New Feature
>            Reporter: Daniel Sun
>            Priority: Major
>             Fix For: 4.x
>
>
> _{color:#d04437}(Note: The exact syntax might be altered before introduction, 
> currently working on the general principle){color}_
> GINQ will reuse most of standard SQL syntax, which can make the learning 
> curve smooth and avoid infringing the patent of Microsoft.
> All GINQ related keywords are uppercase to avoid breaking existing source 
> code as possible as we can, e.g. {{FROM}}, {{WHERE}}, {{SELECT}}, etc.
> *EBNF*
>     TBD 
> *Examples*
> 1. Filtering
> {code:java}
> def numbers = [1, 2, 3]
> def result =
>       FROM numbers t       // t is an alias
>       WHERE t.VALUE <= 2
>       SELECT t.VALUE
> assert [1, 2] == result
> {code}
> {code:java}
> @groovy.transform.EqualsAndHashCode
> class Person {
>       String name
>       int age
> }
> def persons = [new Person(name: 'Daniel', age: 35), new Person(name: 'Peter', 
> age: 10), new Person(name: 'Alice', age: 22)]
> def result =
>       FROM persons p       // p is an alias
>       WHERE p.age > 15 AND p.age <= 35
>       SELECT p.name
> assert ['Daniel', 'Alice'] == result
> result =
>       FROM persons p       // p is an alias
>       WHERE p.age > 15 AND p.age <= 35
>       SELECT p
> assert [new Person(name: 'Daniel', age: 35), new Person(name: 'Alice', age: 
> 22)] == result
> {code}
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to