Simple module for MTA that provides Postgre.SQL client API.
I accept any support regarding the module development. Feel free to make PRs and Issues.
Information about Installation provided on the Releases page.
userdatapg_conn(stringconnection)Attempts to make connection with your Postgre.SQL server.
string connection - connection query string.
Might look like:
postgresql://USER:PASSWORD@IP:PORT/dbname?connect_timeout=3hostaddr=IP port=5432 dbname=DBNAME user=USERNAME password=PASSWORD
If the connection attempt is successfull, the function returns connection handle.
On the failure, the function returns 2 values:
false(bool)Error message(string)
localconn,err=pg_conn("postgresql://user:123qwe@127.0.03:5432/mydb?connect_timeout=3"); if (err~=nil) thenprint(err)
return1;
enduserdatapg_query(userdataconnection, stringquery)Sends query to the Postgre.SQL server with provided data. String escaping supports as well.
userdata connection - connection handle (see pg_conn).string query - query to send to the Postgre.SQL server.
If query was sent successfully, the function returns userdata with the query result handle.
On the failure, the function returns 2 values:
false(bool)Error message(string)
localquery,qerr=pg_query(conn, "SELECT $1 as a, $2 as b", -67, 2)
if (query==false) theniprint(qerr)
endtablepg_poll(userdataquery) Gets the data from the query result handle.
userdata query - query result handle (see pg_query).
On the success, the function returns a table.
On the failure, the function returns 1 value:
false(bool)
localquery,qerr=pg_query(conn, "SELECT $1 as a, $2 as b", -67, 2)
if (query==false) theniprint(qerr)
endiprint(pg_poll(query));boolpg_free(userdataquery)Frees memory after executing the query (in case it didn't happen before).
userdata query - query result handle (see pg_query).
If the query result handle is valid, the function returns true (bool).
Otherwise the function returns false (bool).
localquery,qerr=pg_query(conn, "SELECT $1 as a, $2 as b", -67, 2)
pg_free(query)boolpg_exec(userdataconnection, stringquery)Sends query to the Postgre.SQL server, except it doesn't return any data like pg_query.
userdata connection - connection handle (see pg_conn).string query - query to send to the Postgre.SQL server.
If query was successfully sent, the function returns userdata with the query result handle.
On the failure, the function returns 2 values:
false(bool)Error message(string)
localexec=pg_exec(conn, "INSERT INTO users (name, password, money) VALUES ($1,$2,$3)", "a man", "mypasswd", "13");
iprint(exec);boolpg_close(userdataconnection)Closes connection with the Posgre.SQL server.
userdata connection - connection handle (see pg_conn).
If connection was closed successfully, the function returns true (bool).
On the failure, the function returns false (bool).
localconn,err=pg_conn("postgresql://user:123qwe@127.0.03:5432/mydb?connect_timeout=3");
... (somecodehere)
pg_close(conn);