This repository has been archived by the owner on Sep 19, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.lua
78 lines (67 loc) · 2.01 KB
/
example.lua
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
68
69
70
71
72
73
74
75
76
77
78
--executed = 0
--received = 0
--
--local function Loop()
-- SetTimeout(2, function ()
---- Postgres.Sync.fetchAll('WRONG SQL QUERY', {})
--
-- Postgres.Sync.fetchScalar('SELECT @parameters', {
-- ['@parameters'] = 'string'
-- })
--
-- executed = executed + 1
--
-- Postgres.Async.fetchAll('SELECT "hello2" as world', {}, function(result)
-- received = received + 1
-- end)
--
-- if executed % 100 == 0 then
-- print(received .. "/" .. executed)
-- end
--
-- Loop()
-- end)
--end
--
--AddEventHandler('onPostgresReady', function ()
-- Loop()
--end)
Postgres.ready(function ()
print(Postgres.Sync.fetchScalar('SELECT @parameters', {
['@parameters'] = 1
}))
print(Postgres.Sync.fetchScalar('SELECT @parameters', {
['@parameters'] = 'string'
}))
Postgres.Async.fetchScalar('SELECT NOW() as world', {}, function(result)
print(result)
end)
Postgres.Async.execute('SELECT pg_sleep(5)', nil, function()
print("1")
end)
Postgres.Async.execute('SELECT pg_sleep(4)', nil, function()
print("2")
end)
Postgres.Async.execute('SELECT pg_sleep(3)', {}, function()
print("3")
end)
Postgres.Async.execute('SELECT pg_sleep(2)', nil, function()
print("4")
end)
Postgres.Async.execute('SELECT pg_sleep(1)', nil, function()
print("5")
end)
print(Postgres.Sync.fetchAll("SELECT 'hello1' as world", {})[1].world)
Postgres.Async.fetchAll("SELECT 'hello2' as world", {}, function(result)
print(result[1].world)
end)
print(Postgres.Sync.fetchScalar("SELECT 'hello3' as world", {}))
Postgres.Async.fetchScalar("SELECT 'hello4' as world", {}, function(result)
print(result)
end)
print(json.encode(Postgres.Sync.fetchScalar('SELECT null', {})))
Postgres.Async.fetchScalar('SELECT null', {}, function(result)
print(result)
end)
Postgres.Sync.fetchAll('WRONG SQL QUERY', {})
end)