-
Notifications
You must be signed in to change notification settings - Fork 5
ev_postgres
Implementation if Postgresql client prototcol for evlua.
The module uses the underlying evpoco postgresql client to fulfill the functionality of the interface.
The calling program should have access to a running Posgresql database instance. The connection parameters to the database should be configured.
Datatypes needed to interace with the system are either lua datatypes or those defined as part of lua_schema
- int8_t: userdata, CDATA
- int16_t: userdata, CDATA
- int32_t: userdata, CDATA
- int64_t: userdata, CDATA
- float: userdata, CDATA
- string: lua string
- double: lua number
- boolean: lua boolean
- binary data: hex_data_s_type: userdata, CDATA
- date: dt_s_type: userdata, CDATA
- datetime: dt_s_type: userdata, CDATA
- timestamp: dt_s_type: userdata, CDATA
- duration: dur_s_type: userdata, CDATA
- numeric: userdata, CDATA (big decimal implementation)
local ev_postgres_db = require("service_utils.db.ev_postgres");
The client implementation provides five classes, viz. ev_postgres_conn, ev_postgres_stmt, ev_postgres_cursor, ev_postgres_cursor_res and ev_postgres_db, these classes represent, connection, statement, cursor, cursor set and database handle respectively.
Opens a new connection to the Postgresql database server instance
conn: table, connection handle
params: table, parameter data
Throws exceptions if any, which can be caught by pcall/xpcall mechanism
Starts a database transaction using the underlying connection (session)
none
flg: boolean, true - successful, false - unsuccessful
msg: string, error message in case of flg being falseThrows exceptions if any, which can be caught by pcall/xpcall mechanism
Commits the insert(s), update(s) and delete(s) done in the transaction
none
flg: boolean, true - successful, false - unsuccessful
msg: string, error message in case of flg being falseThrows exceptions if any, which can be caught by pcall/xpcall mechanism
Rolls back the insert(s), update(s) and delete(s) done in the transaction
none
flg: boolean, true - successful, false - unsuccessful
msg: string, error message in case of flg being falseThrows exceptions if any, which can be caught by pcall/xpcall mechanism
Resets the connection handle so that it can be reused for other operations
none
none
Throws exceptions if any, which can be caught by pcall/xpcall mechanism
Prepares the input SQL statement for execution in the database reuses the cached statement if already present and the prepared statment is cached for further usage
sql_statement: string
stmt: table, prepared statement
Throws exceptions if any, which can be caught by pcall/xpcall mechanism
Closes any open cursors in the database transaction session
none
flg: boolean, true - successful, false - unsuccessful
msg: string, error message in case of flg being falseThrows exceptions if any, which can be caught by pcall/xpcall mechanism
Gets the current system time, it is expected that the clock on host on which application service is running is synchronized with that of the host on which database is running
none
time: userdata, CDATA of type (char*) representing "datetime|tz"
Throws exceptions if any, which can be caught by pcall/xpcall mechanism
Gets the current system date, it is expected that the clock on host on which application service is running is synchronized with that of the host on which database is running
none
date: userdata, CDATA of type (char*) representing "date|tz"
Throws exceptions if any, which can be caught by pcall/xpcall mechanism
Gets the next value of the given sequence definied in the database
seq_name: string, name of the sequence
nextval: userdata, CDATA of type (int64_t)
Throws exceptions if any, which can be caught by pcall/xpcall mechanism
Prepares the input SQL statement for execution and opens a cursor with the SQL statement and identified by the passed cursor_id
cusor_id: string
sql_statement: stringcur: table, cusror handle
Throws exceptions if any, which can be caught by pcall/xpcall mechanism
Executes the prepared statement using the bind variables passed as arguments
...: vararg, bind variables of various types, which will be used to execute the SQL statement
flg: boolean, true - successful, false - unsuccessful
msg: string, error message in case of flg being falseThrows exceptions if any, which can be caught by pcall/xpcall mechanism
Returns the number of rows affected by the SQL statement that has got executed, this is applicable in case of INSERT, UPDATE and DELETE operations
none
num: number
Throws exceptions if any, which can be caught by pcall/xpcall mechanism
Fetches the next incremental record from the result set, if the record exists
none
rec: table, tuple (array) of result fields
Throws exceptions if any, which can be caught by pcall/xpcall mechanism
Fetches the column names returned by the ev_postgres_stmt.fetch_result operation
none
columns: table, array of column names
Throws exceptions if any, which can be caught by pcall/xpcall mechanism
Maps the data returned by ev_postgre_stmt.fetch_result to the fields mentioned in col_map according to position
res_tuple: table, tuple returned from ev_postgre_stmt.fetch_result col_map: table, tuple of field names
record: table, result object, indexed by field names
Throws exceptions if any, which can be caught by pcall/xpcall mechanism
Closes the Postgresql statement and initiates garbage collection
none
none
Throws exceptions if any, which can be caught by pcall/xpcall mechanism
A cursor is opened using the function ev_postgres_conn:get_sequence_nextval(seq_name)
Fetches all the records as reclared by the cursor in a single go
none
cur_res: table, cursor result that can be iterated over
Throws exceptions if any, which can be caught by pcall/xpcall mechanism
Fetches a set of records from the cursor based on parameters given in the argument
- If props is passed as nil then all the records of the cursor are fetched from the starting position in the cursor
- If props.num_\recs is is passed as nil or 0, then all the records of the cursor are fetched from the current position in the cursor, else as many records will be fetched
- If props.offset is is passed as nil or 0, then fetch will be commenced from the first record, else fetch will commence from the mentioned offset.
props: table, {offset, num_recs}
cur_res: table, cursor result that can be iterated over
Throws exceptions if any, which can be caught by pcall/xpcall mechanism
Fetches an incremental record from the cusror from the current position in the cursor
none
cur_rec: table, tuple of fields as retured based on the SQL query of the cursor.
Throws exceptions if any, which can be caught by pcall/xpcall mechanism
Closes the open cursor
none
none
Throws exceptions if any, which can be caught by pcall/xpcall mechanism
The cursor result is obtained by calling the function ev_postgres_cursor:fetch_next_set(props)
Fetches an incremental record from the cusror from the current position in the cursor
none
cur_rec: table, tuple of fields as retured based on the SQL query of the cursor.
Throws exceptions if any, which can be caught by pcall/xpcall mechanism
Maps the data returned by ev_postgres_cursor_res:fetch_rec to the fields mentioned in col_map according to position
res_tuple: table, tuple returned from ev_postgre_stmt.fetch_result col_map: table, tuple of field names
record: table, result object, indexed by field names
Throws exceptions if any, which can be caught by pcall/xpcall mechanism
Closes the open cursor
none
none
Throws exceptions if any, which can be caught by pcall/xpcall mechanism