lua-users home
lua-l archive

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


In my ODBC[1] binding I use

 local sql = 'select ID, NAME from Clients where NAME = :NAME'
 local params = {NAME='ALEX'}
 for ID,NAME in db:rows(sql,params) do print(ID,NAME) end
 for r in db:irows(sql,params) do print(r[1],r[2]) end
 for r in db:nrows(sql,params) do print(r.ID,r.NAME) end

`rows` is to mimic basic iterator
`irows` is just like `table.foreachi` (indexed?)
`nrows` is `named rows`

[1] http://moteus.github.io/dba/modules/Connection.html#Connection:rows

> Hi,

> When you access a database, you might want to receive results from
> a query as a multiple return value, an array, or as a table with column names.  For example:

>     for first, last in db:rows“SELECT first, last FROM people” do print(first, last) end

> or

>     for array in db:rows“SELECT first, last FROM people” do print(array[1], array[2]) end

> or

>     for table in db:rows“SELECT first, last FROM people” do
> print(table.first, table.last) end

> I find that I use the first and last example, but not so much the
> middle, array, form (but that’s just me).

> What should each of these functions be called?  The database
> binding I use frequently that actually offers a “rows" iterator [1] calls them:
>  - “rows” for the array case that I don’t really use
>  - “nrows” for the table case (I guess that stands for “named rows”?)
>  - “urows” for the multiple return case (I’m not sure what the u stands for)

> Can anyone suggest a better naming convention?  I ask because I’ve
> written myself a yet-another database-adapter on top of the other
> database adapters [2] to make them look the same, and (to my eyes at least) slightly more pleasant.

> Cheers,
> Geoff

> [1] lsqlite3[3].  luapqsql[4] and luasql[5] offer primitives that
> allow you to build your own iterators
> [2] https://github.com/geoffleyland/lua-patengi
> [3] https://github.com/LuaDist/lsqlite3
> [4] https://github.com/mbalmer/luapgsql
> [5]
> https://keplerproject.github.io/luasql/doc/us/manual.html#introduction





--
С уважением,
 Alexey                          mailto:alexeymelnichuck@gmail.com


---
Это сообщение проверено на вирусы антивирусом Avast.
https://www.avast.com/antivirus