lua-users home
lua-l archive

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

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)

local res = db:exec("SELECT name FROM persons WHERE id = $1", {id})
for r in res:rows()

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')

Then when e.g. on a psql prompt you enter 'notify AN_EVENT;', above
function would be called.

my fork of luapgsql:

db:exec('LISTEN somenotify')
-- wait indefinitely for NOTIFY:
-- OR wait for NOTIFY, up to six seconds

for my needs NOTIFY-wait function is better, but if someone need
NOTIFY-driven callback - it can be added as well.