[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Lua and Postgres
- From: Ed <spied@...>
- Date: Sat, 15 Jan 2011 23:53:26 +0300
On 01/14/11 10:48, Marc Balmer wrote:
The road we went is to write our own PostgreSQL interface, because we
don't need portability, we just need a solid interface to PostgreSQL:
local res = db:exec("SELECT name FROM persons WHERE id = " .. id)
for n = 1, res:ntuples() do
print(res:getvalue(n, 1)
end
https://github.com/STPeters/luapgsql
local res = db:exec("SELECT name FROM persons WHERE id = $1", {id})
for r in res:rows()
print(r.name)
end
You get the idea... Currently we are trying to make use of PostgreSQL's
asynchronous notification feature, linking a notificatin to the
execution of a Lua function:
db:listen('AN_EVENT', function()
print('Event AN_EVENT was signalled')
end)
Then when e.g. on a psql prompt you enter 'notify AN_EVENT;', above
function would be called.
my fork of luapgsql:
https://github.com/edo1/luapgsql
db:exec('LISTEN somenotify')
-- wait indefinitely for NOTIFY:
db:notifywait()
-- OR wait for NOTIFY, up to six seconds
db:notifywait(6)
for my needs NOTIFY-wait function is better, but if someone need
NOTIFY-driven callback - it can be added as well.