lua-users home
lua-l archive

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


I might call them rows (hashed tables), and rowvals or values or something similar (multi returns). I probably wouldn't ever use the array indexed style, unless it was actually meaningful to the data. And in that case, it would probably be a list packed into single column, so it would look more like:

   for t in db:rows("...") do print(table.unpack(t.phonenumbers)) end

But that feels pretty janky anyway, and I'd probably slap my DBA for doing something like that.

On Wed, Jun 17, 2015 at 2:43 PM, Geoff Leyland <geoff_leyland@fastmail.fm> wrote:
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





--
Brigham Toskin