lua-users home
lua-l archive

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


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
>

I would guess the u stands for "unpacked" since that's the operation
that would transform a row stored in an array into multiple returns.

Personally I would offer rows() as the array version and then extend
that with adapters, such as rows():asTable() or rows():asValues().

/s/ Adam