lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Dec 16, 2009, at 11:30 AM, Petite Abeille wrote:

> 
> On Dec 16, 2009, at 8:06 PM, Mark Hamburg wrote:
> 
>> 	for name in DBTable[ 'Customers' ]:where( 'Age', lessThan, 50 ):select( 'Name' ) do
>> 		-- database extraction
>> 	end
> 
> OMG, another (O)RM idiom! :P
> 
> Getting a hard time trying to comprehend what's the advantage of such baroque syntax over good, old, plain, byzantine SQL :)
> 
> FWIW, here is the syntax I tend to use:
> 
> local DB = require( 'DB' )
> local aDB = DB( 'sqlite3://localhost/test.db' )
> 
> for aCustomer in aDB( 'select name from customer where age < 50' ) do
>    print( aCustomer.name )
> end
> 
> (0) plain SQL, got tired of trying to reinvent that wheel :D
> (1) call db -> create a connection
> (2) call connection -> create a cursor containing the result of a statement
> (3) call cursor -> iterate over the cursor content
> 
> Just my 2¢.
> 
> P.S. What is it with December and language changes? Too much Glühwein or something?

Ah. But how did you know it was a SQL database? Maybe I just have an in memory database that also supports where and select. Using this sort of construct (essentially inspired by LINQ), we gain flexibility on data sources.

I also avoided generating a table per item in this case.

On the other hand, I've definitely seen ORMs where it fails to generate the efficient SQL.

Mark