You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@groovy.apache.org by Wilson MacGyver <wm...@gmail.com> on 2016/06/22 17:36:57 UTC

@compileStatic and groovy.sql

Hi,

If I want to use compileStatic with groovy.sql, how would I do that?


the problem as far as I can tell is

sql.eachRow("select id,.... from whatever") { foo ->
...
  foo.id
}

returns data that is known at runtime

but at compile time. there is no way to know that the SQL statement returns
a
id column.

is there a way to do it?

Thanks,
Mac

-- 
Omnem crede diem tibi diluxisse supremum.

Re: @compileStatic and groovy.sql

Posted by Wilson MacGyver <wm...@gmail.com>.
I've been playing around with sql2o actually.

http://www.sql2o.org/

it has very good performance for read. https://github.com/aaberg/sql2o

and 99% of my SQL needs are read only.


On Fri, Jun 24, 2016 at 9:34 AM, Cédric Champeau <ce...@gmail.com>
wrote:

> For type safe sql those days I would recommend to use jOOQ.
> Le 23 juin 2016 06:58, "Wilson MacGyver" <wm...@gmail.com> a écrit :
>
>> Ouch.... I will continue to embrace dynamic then :)
>>
>> On Wed, Jun 22, 2016 at 1:56 PM Guillaume Laforge <gl...@gmail.com>
>> wrote:
>>
>>> Perhaps a custom type checker extension could be fed with the jdbc
>>> metadata...
>>> Le 22 juin 2016 7:41 PM, "Shil Sinha" <sh...@gmail.com> a écrit :
>>>
>>>> Hi Marc,
>>>>
>>>> You could use the map access syntax i.e. foo['id'] instead and
>>>> cast/coerce the result to the appropriate type.
>>>>
>>>> On Wed, Jun 22, 2016 at 1:37 PM Wilson MacGyver <wm...@gmail.com>
>>>> wrote:
>>>>
>>>>> Hi,
>>>>>
>>>>> If I want to use compileStatic with groovy.sql, how would I do that?
>>>>>
>>>>>
>>>>> the problem as far as I can tell is
>>>>>
>>>>> sql.eachRow("select id,.... from whatever") { foo ->
>>>>> ...
>>>>>   foo.id
>>>>> }
>>>>>
>>>>> returns data that is known at runtime
>>>>>
>>>>> but at compile time. there is no way to know that the SQL statement
>>>>> returns a
>>>>> id column.
>>>>>
>>>>> is there a way to do it?
>>>>>
>>>>> Thanks,
>>>>> Mac
>>>>>
>>>>> --
>>>>> Omnem crede diem tibi diluxisse supremum.
>>>>>
>>>>


-- 
Omnem crede diem tibi diluxisse supremum.

Re: @compileStatic and groovy.sql

Posted by Cédric Champeau <ce...@gmail.com>.
For type safe sql those days I would recommend to use jOOQ.
Le 23 juin 2016 06:58, "Wilson MacGyver" <wm...@gmail.com> a écrit :

> Ouch.... I will continue to embrace dynamic then :)
>
> On Wed, Jun 22, 2016 at 1:56 PM Guillaume Laforge <gl...@gmail.com>
> wrote:
>
>> Perhaps a custom type checker extension could be fed with the jdbc
>> metadata...
>> Le 22 juin 2016 7:41 PM, "Shil Sinha" <sh...@gmail.com> a écrit :
>>
>>> Hi Marc,
>>>
>>> You could use the map access syntax i.e. foo['id'] instead and
>>> cast/coerce the result to the appropriate type.
>>>
>>> On Wed, Jun 22, 2016 at 1:37 PM Wilson MacGyver <wm...@gmail.com>
>>> wrote:
>>>
>>>> Hi,
>>>>
>>>> If I want to use compileStatic with groovy.sql, how would I do that?
>>>>
>>>>
>>>> the problem as far as I can tell is
>>>>
>>>> sql.eachRow("select id,.... from whatever") { foo ->
>>>> ...
>>>>   foo.id
>>>> }
>>>>
>>>> returns data that is known at runtime
>>>>
>>>> but at compile time. there is no way to know that the SQL statement
>>>> returns a
>>>> id column.
>>>>
>>>> is there a way to do it?
>>>>
>>>> Thanks,
>>>> Mac
>>>>
>>>> --
>>>> Omnem crede diem tibi diluxisse supremum.
>>>>
>>>

Re: @compileStatic and groovy.sql

Posted by Wilson MacGyver <wm...@gmail.com>.
Ouch.... I will continue to embrace dynamic then :)

On Wed, Jun 22, 2016 at 1:56 PM Guillaume Laforge <gl...@gmail.com>
wrote:

> Perhaps a custom type checker extension could be fed with the jdbc
> metadata...
> Le 22 juin 2016 7:41 PM, "Shil Sinha" <sh...@gmail.com> a écrit :
>
>> Hi Marc,
>>
>> You could use the map access syntax i.e. foo['id'] instead and
>> cast/coerce the result to the appropriate type.
>>
>> On Wed, Jun 22, 2016 at 1:37 PM Wilson MacGyver <wm...@gmail.com>
>> wrote:
>>
>>> Hi,
>>>
>>> If I want to use compileStatic with groovy.sql, how would I do that?
>>>
>>>
>>> the problem as far as I can tell is
>>>
>>> sql.eachRow("select id,.... from whatever") { foo ->
>>> ...
>>>   foo.id
>>> }
>>>
>>> returns data that is known at runtime
>>>
>>> but at compile time. there is no way to know that the SQL statement
>>> returns a
>>> id column.
>>>
>>> is there a way to do it?
>>>
>>> Thanks,
>>> Mac
>>>
>>> --
>>> Omnem crede diem tibi diluxisse supremum.
>>>
>>

Re: @compileStatic and groovy.sql

Posted by Guillaume Laforge <gl...@gmail.com>.
Perhaps a custom type checker extension could be fed with the jdbc
metadata...
Le 22 juin 2016 7:41 PM, "Shil Sinha" <sh...@gmail.com> a écrit :

> Hi Marc,
>
> You could use the map access syntax i.e. foo['id'] instead and cast/coerce
> the result to the appropriate type.
>
> On Wed, Jun 22, 2016 at 1:37 PM Wilson MacGyver <wm...@gmail.com>
> wrote:
>
>> Hi,
>>
>> If I want to use compileStatic with groovy.sql, how would I do that?
>>
>>
>> the problem as far as I can tell is
>>
>> sql.eachRow("select id,.... from whatever") { foo ->
>> ...
>>   foo.id
>> }
>>
>> returns data that is known at runtime
>>
>> but at compile time. there is no way to know that the SQL statement
>> returns a
>> id column.
>>
>> is there a way to do it?
>>
>> Thanks,
>> Mac
>>
>> --
>> Omnem crede diem tibi diluxisse supremum.
>>
>

Re: @compileStatic and groovy.sql

Posted by Shil Sinha <sh...@gmail.com>.
Hi Marc,

You could use the map access syntax i.e. foo['id'] instead and cast/coerce
the result to the appropriate type.

On Wed, Jun 22, 2016 at 1:37 PM Wilson MacGyver <wm...@gmail.com> wrote:

> Hi,
>
> If I want to use compileStatic with groovy.sql, how would I do that?
>
>
> the problem as far as I can tell is
>
> sql.eachRow("select id,.... from whatever") { foo ->
> ...
>   foo.id
> }
>
> returns data that is known at runtime
>
> but at compile time. there is no way to know that the SQL statement
> returns a
> id column.
>
> is there a way to do it?
>
> Thanks,
> Mac
>
> --
> Omnem crede diem tibi diluxisse supremum.
>