libusual  0.1
Enumerations | Functions
usual/pgsocket.h File Reference

Async Postgres connection framework. More...

Enumerations

enum  PgEvent {
  PGS_CONNECT_OK, PGS_CONNECT_FAILED, PGS_RESULT_OK, PGS_RESULT_BAD,
  PGS_TIMEOUT
}
 Event types reported to user handler function. More...

Functions

struct PgSocket * pgs_create (const char *connstr, pgs_handler_f fn, void *arg)
 Create PgSocket.
void pgs_free (struct PgSocket *db)
 Release PgSocket.
void pgs_set_event_base (struct PgSocket *pgs, struct event_base *base)
 Change the event base for PgSocket.
void pgs_set_lifetime (struct PgSocket *pgs, double lifetime)
 Set connection lifetime (in seconds)
void pgs_connect (struct PgSocket *db)
 Launch connection.
void pgs_disconnect (struct PgSocket *db)
 Drop connection.
void pgs_send_query_simple (struct PgSocket *db, const char *query)
 Send simple query.
void pgs_send_query_params (struct PgSocket *db, const char *query, int nargs,...)
 Send extended query, args from varargs.
void pgs_send_query_params_list (struct PgSocket *db, const char *query, int nargs, const char *argv[])
 Send extended query, args from list.
void pgs_sleep (struct PgSocket *db, double timeout)
 Ignore the connection for specified time.
void pgs_reconnect (struct PgSocket *db, double timeout)
 Disconnect, sleep, reconnect.
int pgs_connection_valid (struct PgSocket *db)
 Does PgSocket have established connection.
PGconn * pgs_get_connection (struct PgSocket *db)
 Return underlying Postgres connection.

Detailed Description

Async Postgres connection framework.


Enumeration Type Documentation

enum PgEvent

Event types reported to user handler function.

Enumerator:
PGS_CONNECT_OK 

Connection establishing finished.

PGS_CONNECT_FAILED 

Connection establishing failed.

PGS_RESULT_OK 

Got result from query either resultset or DB error.

PGS_RESULT_BAD 

Query execution failed.

PGS_TIMEOUT 

Wakeup from timed sleep.


Function Documentation

struct PgSocket* pgs_create ( const char *  connstr,
pgs_handler_f  fn,
void *  arg 
) [read]

Create PgSocket.

It does not launch connection yet, use pgs_connect() for that.

Parameters:
connstrlibpq connect string
fncallback function for event handling
argextra context for callback
Returns:
Initialized PgSocket structure
void pgs_free ( struct PgSocket *  db)

Release PgSocket.

void pgs_set_event_base ( struct PgSocket *  pgs,
struct event_base *  base 
)

Change the event base for PgSocket.

void pgs_set_lifetime ( struct PgSocket *  pgs,
double  lifetime 
)

Set connection lifetime (in seconds)

void pgs_connect ( struct PgSocket *  db)

Launch connection.

void pgs_disconnect ( struct PgSocket *  db)

Drop connection.

void pgs_send_query_simple ( struct PgSocket *  db,
const char *  query 
)

Send simple query.

void pgs_send_query_params ( struct PgSocket *  db,
const char *  query,
int  nargs,
  ... 
)

Send extended query, args from varargs.

void pgs_send_query_params_list ( struct PgSocket *  db,
const char *  query,
int  nargs,
const char *  argv[] 
)

Send extended query, args from list.

void pgs_sleep ( struct PgSocket *  db,
double  timeout 
)

Ignore the connection for specified time.

void pgs_reconnect ( struct PgSocket *  db,
double  timeout 
)

Disconnect, sleep, reconnect.

int pgs_connection_valid ( struct PgSocket *  db)

Does PgSocket have established connection.

PGconn* pgs_get_connection ( struct PgSocket *  db)

Return underlying Postgres connection.