Skip to content

Commit

Permalink
readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Disinterpreter committed Jan 9, 2021
1 parent fae6ab8 commit 06ae6ef
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 44 deletions.
44 changes: 0 additions & 44 deletions README

This file was deleted.

68 changes: 68 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# MTA PostgreSQL driver

# Decription
Just a pgsql module for mta.
I accept any help with developing the module. Feel free to make PRs and Issues.

# Installation
### Windows
Put misc files from Releases to `server\x64\` make a `modules` directory and put the `ml_pgsql.dll` file there.
### Linux
Not yet.

# Functions
## userdata pg_conn(string connection)
Make a connect to your postgres server.
String can be like:
`postgresql://USER:PASSWORD@IP:PORT/dbname?connect_timeout=3`
or
`hostaddr=IP port=5432 dbname=DBNAME user=USERNAME password=PASSWORD`
**return** userdata with connect in sucsessful connection. or bool and string with error otherwise.
```lua
local conn,err = pg_conn("postgresql://user:[email protected]:5432/mydb?connect_timeout=3");
if (err ~= nil) then
print(error)
return 1;
end
```
## userdata pg_query(userdata connection, string query)
Query data from a query string. String escaping is support.
**return** userdata with a query. Otherwise bool and string error.
```lua
local query,qerr = pg_query(conn, "SELECT $1 as a, $2 as b", -67, 2)
if (query == false) then
iprint(qerr)
end
```
## table pg_poll(userdata query)
Get data from the userdata to the array
**return** a table or TODO
```lua
local query,qerr = pg_query(conn, "SELECT $1 as a, $2 as b", -67, 2)
if (query == false) then
iprint(qerr)
end
iprint(pg_poll(query));
```
## bool pg_free(userdata query)
Free a memory after executing query (if it don't happens)
**return** true
```lua
local query,qerr = pg_query(conn, "SELECT $1 as a, $2 as b", -67, 2)
pg_free(quey)
```
## bool pg_exec(userdata connection, string query)
Like a pg_query it make a query, but do not return any data.
**return** bool as a result of executing the query. Otherwise bool and string error.
```lua
local exec = pg_exec(conn, "INSERT INTO users (name, password, money) VALUES ($1,$2,$3)", "a man", "mypasswd", "13");
iprint(exec);
```
## bool pg_close(userdata connection);
Close a database connection.
**return** boolean
```lua
local conn,err = pg_conn("postgresql://user:[email protected]:5432/mydb?connect_timeout=3");
...
pg_close(conn);
```

0 comments on commit 06ae6ef

Please sign in to comment.