[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: RE: Result sets - what's the "Lua way"
- From: Tomas Guisasola Gorham <tomas@...>
- Date: Thu, 5 May 2011 11:26:17 -0300 (BRT)
Can you show how you'd like the code to look? That's what I'm trying to work out. I can code behind it but I'm not sure on how it should look.
Take a look at LuaSQL (http://www.keplerproject.org/luasql/). It has
a very simple API over which it is not difficult to write a higher level
one such as Dado (http://www.ccpa.puc-rio.br/software/dado/).
result, err = sql.exec("select min(wage) as minwage, max(wage) as maxwage from employee")
print("minimum wage is ", result.minwage)
print("maximum wage is ", result.maxwage)
result, err = sql.exec("select id, name, wage from employee order by name")
for id,name,wage in pairs(result)
print(id, name, wage)
minwage, maxwage, err = sql.exec("select min(wage) as minwage, max(wage) as maxwage from employee")
print("minimum wage is ", minwage)
print("maximum wage is ", maxwage)
Sorry if I'm being vague but what I'm trying to get at is as a developer, what would you want the API to look like? What would your side of the code look like?
I am very used to the above APIs thus my opinion could be biased :-)
I think that an API that gives you a table with the whole result
set is very flexible, but for a large amount of data, this could consume
too much memory unnecessarily. An alternative for that is to return a
proxy that retrieves data on demand, but it also has some disadvantages.
Another polemical decision is whether convert the data to native Lua types or not. LuaSQL does not define anything, thus the drivers behave differently which could be annoying for some people.