|
| 1 | +# MTA PostgreSQL driver |
| 2 | + |
| 3 | +# Decription |
| 4 | +Just a pgsql module for mta. |
| 5 | +I accept any help with developing the module. Feel free to make PRs and Issues. |
| 6 | + |
| 7 | +# Installation |
| 8 | +### Windows |
| 9 | +Put misc files from Releases to `server\x64\` make a `modules` directory and put the `ml_pgsql.dll` file there. |
| 10 | +### Linux |
| 11 | +Not yet. |
| 12 | + |
| 13 | +# Functions |
| 14 | +## userdata pg_conn(string connection) |
| 15 | +Make a connect to your postgres server. |
| 16 | +String can be like: |
| 17 | +`postgresql://USER:PASSWORD@IP:PORT/dbname?connect_timeout=3` |
| 18 | +or |
| 19 | +`hostaddr=IP port=5432 dbname=DBNAME user=USERNAME password=PASSWORD` |
| 20 | +**return** userdata with connect in sucsessful connection. or bool and string with error otherwise. |
| 21 | +```lua |
| 22 | +local conn,err = pg_conn("postgresql://user:123qwe@127.0.03:5432/mydb?connect_timeout=3"); |
| 23 | +if (err ~= nil) then |
| 24 | + print(error) |
| 25 | + return 1; |
| 26 | +end |
| 27 | +``` |
| 28 | +## userdata pg_query(userdata connection, string query) |
| 29 | +Query data from a query string. String escaping is support. |
| 30 | +**return** userdata with a query. Otherwise bool and string error. |
| 31 | +```lua |
| 32 | +local query,qerr = pg_query(conn, "SELECT $1 as a, $2 as b", -67, 2) |
| 33 | +if (query == false) then |
| 34 | + iprint(qerr) |
| 35 | +end |
| 36 | +``` |
| 37 | +## table pg_poll(userdata query) |
| 38 | +Get data from the userdata to the array |
| 39 | +**return** a table or TODO |
| 40 | +```lua |
| 41 | +local query,qerr = pg_query(conn, "SELECT $1 as a, $2 as b", -67, 2) |
| 42 | +if (query == false) then |
| 43 | + iprint(qerr) |
| 44 | +end |
| 45 | +iprint(pg_poll(query)); |
| 46 | +``` |
| 47 | +## bool pg_free(userdata query) |
| 48 | +Free a memory after executing query (if it don't happens) |
| 49 | +**return** true |
| 50 | +```lua |
| 51 | +local query,qerr = pg_query(conn, "SELECT $1 as a, $2 as b", -67, 2) |
| 52 | +pg_free(quey) |
| 53 | +``` |
| 54 | +## bool pg_exec(userdata connection, string query) |
| 55 | +Like a pg_query it make a query, but do not return any data. |
| 56 | +**return** bool as a result of executing the query. Otherwise bool and string error. |
| 57 | +```lua |
| 58 | +local exec = pg_exec(conn, "INSERT INTO users (name, password, money) VALUES ($1,$2,$3)", "a man", "mypasswd", "13"); |
| 59 | +iprint(exec); |
| 60 | +``` |
| 61 | +## bool pg_close(userdata connection); |
| 62 | +Close a database connection. |
| 63 | +**return** boolean |
| 64 | +```lua |
| 65 | +local conn,err = pg_conn("postgresql://user:123qwe@127.0.03:5432/mydb?connect_timeout=3"); |
| 66 | +... |
| 67 | +pg_close(conn); |
| 68 | +``` |
0 commit comments