-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_pgsql.lua
More file actions
67 lines (58 loc) · 1.48 KB
/
test_pgsql.lua
File metadata and controls
67 lines (58 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env luajit
-- for debug
local _tostring = require('logging').tostring
local write = function(s) io.stdout:write(s) end
local print = function(...)
print(_tostring{...})
end
local PQ = require('everlooping.pgsql')
local cosocket = require('everlooping.cosocket')
local ioloop = require('everlooping.ioloop')
function showResult(res)
for _, ret in ipairs(res) do
for _, name in ipairs(ret.fieldnames) do
write(string.format('%-15s', name))
end
write('\n' .. string.rep('=', 15 * #ret.fieldnames) .. '\n')
for _, row in ipairs(ret.resultset) do
for _, val in pairs(row) do
write(string.format('%-15s', val))
end
write('\n')
end
write('\n')
end
end
cosocket.register(function()
print('request thread:', coroutine.running())
write('\n')
p = PQ.pgsql()
local ok, err = p:connect('dbname=teamconnected')
if not ok then
write(err)
end
ok, err = p:query('select * from msg_entity limit 2; select * from account_entity limit 3')
if not ok then
write(err)
else
showResult(ok)
end
ok, err = p:query('select 1+3 * 7')
if not ok then
write(err)
else
showResult(ok)
end
ok, err = p:query("copy (select * from msg_entity order by id) to '/tmp/testdata'")
if not ok then
write(err)
end
write('\nexpecting error messages:\n\n')
ok, err = p:query('select * from notthere')
if not ok then
write(err)
end
p:close()
print('Request complete.')
end)
ioloop.defaultIOLoop():start()