@@ -6,32 +6,32 @@ using [libpq] with asynchronousity in mind.
6
6
Besides binary module you'll probably need to add [ ` async_postgres.lua ` ] [ lua module ] to your project.
7
7
8
8
## Features
9
- * Fully asynchronous, yet allows to wait a query to finish
9
+ * Fully asynchronous, yet allows to wait for a query to finish
10
10
* Provides full simplified [ libpq] interface
11
- * Simple, robust and efficient
11
+ * Simple, robust, and efficient
12
12
* Flexible [ lua module] which extends functionality
13
- * [ Type friendly] [ LuaLS ] [ lua module] with documentatio
13
+ * [ Type friendly] [ LuaLS ] [ lua module] with documentation
14
14
15
15
## Installation
16
16
1 . Go to [ releases] ( https://github.com/Pika-Software/gmsv_async_postgres/releases )
17
17
2 . Download ` async_postgres.lua ` and ` gmsv_async_postgres_xxx.dll ` files
18
18
> [ !NOTE]
19
- > If are unsure which binary to download, you can run this command inside console of your server
19
+ > If you are unsure which binary to download, you can run this command inside the console of your server
20
20
> ``` lua
21
21
> lua_run print (" gmsv_async_postgres_" .. (system .IsWindows () and " win" or system .IsOSX () and " osx" or " linux" ) .. (jit .arch == " x64" and " 64" or not system .IsLinux () and " 32" or " " ) .. " .dll" )
22
22
> ` ` `
23
- 3. Put ` gmsv_async_postgres_xxx.dll` inside ` garrysmod/lua/bin/` folder (if folder does not exists , create it )
23
+ 3. Put ` gmsv_async_postgres_xxx.dll` inside the ` garrysmod/lua/bin/` folder (if the folder does not exist , create it )
24
24
4. Put ` async_postgres.lua` inside ` garrysmod/lua/autorun/server/` or inside your project folder
25
25
5. Profit 🎉
26
26
27
27
## Caveats
28
- * when ` queryParams` is used and parameters is ` string` , then string will be sent as bytes !<br>
29
- You ' ll need to convert numbers **exclipitly ** to `number` type, otherwise
30
- PostgreSQL will interpent parameter as binary integer , and will return error
31
- or unexpected results may happend .
28
+ * When ` queryParams` is used and the parameter is ` string` , then the string will be sent as bytes !<br>
29
+ You ' ll need to convert numbers **explicitly ** to the `number` type, otherwise
30
+ PostgreSQL will interpret the parameter as a binary integer , and will return an error
31
+ or unexpected results may happen .
32
32
33
33
* Result rows are returned as strings , you ' ll need to convert them to numbers if needed.
34
- * You ' ll need to use `Client:unescapeBytea(...)` to convert bytea data to string from reuslt .
34
+ * You ' ll need to use `Client:unescapeBytea(...)` to convert bytea data to string from the result .
35
35
36
36
## Usage
37
37
` async_postgres.Client` usage example
@@ -49,11 +49,11 @@ client:connect(function(ok, err)
49
49
end )
50
50
51
51
-- PostgreSQL can only process one query at a time,
52
- -- but async_postgres.Client has internal queue for queries
52
+ -- but async_postgres.Client has an internal queue for queries
53
53
-- so you can queue up as many queries as you want
54
54
-- and they will be executed one by one when possible
55
55
--
56
- -- For example this query will be executed after the connection is established
56
+ -- For example, this query will be executed after the connection is established
57
57
client :query (" select now()" , function (ok , res )
58
58
assert (ok , res )
59
59
print (" Current time is " .. res .rows [1 ].now )
@@ -88,7 +88,7 @@ client:close() -- passing true will wait for all queries to finish, but we did w
88
88
``` lua
89
89
local pool = async_postgres .Pool (" postgresql://postgres:postgres@localhost" )
90
90
91
- -- You can make same queries as with Client
91
+ -- You can make the same queries as with Client
92
92
-- but with Pool you don't need to worry about connection
93
93
-- Pool will manage connections for you
94
94
pool :query (" select now()" , function (ok , res )
@@ -110,13 +110,13 @@ pool:transaction(function(ctx)
110
110
print (" Value in transaction is: " .. res .rows [1 ].value ) -- will output "Value in transaction is barfoo"
111
111
112
112
-- If error happens in transaction, it will be rolled back
113
- error (" welp something went wrong :p)
113
+ error (" welp something went wrong :p" )
114
114
115
- -- if no error happens, transaction will be commited
115
+ -- if no error happens, transaction will be committed
116
116
end )
117
117
118
- -- Or you can use :connect() to create your own transactions or for smth else
119
- -- :connect() will acquire first available connected Client from the Pool
118
+ -- Or you can use :connect() to create your own transactions or for something else
119
+ -- :connect() will acquire the first available connected Client from the Pool
120
120
-- and you'll need to call client:release() when you're done
121
121
pool :connect (function (client )
122
122
client :query (" select now()" , function (ok , res )
174
174
- ` Client:parameterStatus(paramName) ` : Looks up a current parameter setting
175
175
- ` Client:protocolVersion() ` : Interrogates the frontend/backend protocol being used
176
176
- ` Client:serverVersion() ` : Returns the server version as integer
177
- - ` Client:errorMessage() ` : Returns last error message
177
+ - ` Client:errorMessage() ` : Returns the last error message
178
178
- ` Client:backendPID() ` : Returns the backend process ID
179
179
- ` Client:sslInUse() ` : Returns true if SSL is used
180
180
- ` Client:sslAttribute(name) ` : Returns SSL-related information
0 commit comments