]> jfr.im git - irc/quakenet/newserv.git/blob - lua/lib/db.lua
LUA: port luadb to dbapi2 to drop postgres dependency
[irc/quakenet/newserv.git] / lua / lib / db.lua
1 function db_queryiter()
2 local f = db_numfields() - 1
3 local gb = db_getvalue
4
5 return function()
6 if not db_nextrow() then
7 return nil
8 end
9
10 local t = {}
11 for j=0,f do
12 local v = gb(j)
13 table.insert(t, v)
14 end
15
16 return unpack(t)
17 end
18 end
19
20 local realquery = db_query
21
22 function db_query(x, fn, t)
23 if not fn then
24 realquery(x)
25 elseif not t then
26 realquery(x, fn, nil)
27 else
28 realquery(x, fn, t)
29 end
30 end