pg_async
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Types | Static Public Member Functions | Static Public Attributes | List of all members
tip::db::pg::db_service Class Reference

#include <database.hpp>

Public Types

typedef boost::system::error_code error_code
 
typedef std::map< std::string,
std::string > 
connection_params
 
typedef boost::optional< size_t > optional_size
 

Static Public Member Functions

static void initialize (size_t pool_size, connection_params const &defaults)
 Initialize the database service with the default pool_size per alias and default connection parameters. More...
 
static void add_connection (std::string const &connection_string, optional_size pool_size=optional_size())
 Add a connection specification. More...
 
static void begin (dbalias const &, transaction_callback const &, error_callback const &)
 Create a connection or retrieve a connection from the connection pool and start a transaction. More...
 
static void run ()
 
static void stop ()
 
static boost::asio::io_service & io_service ()
 

Static Public Attributes

static const size_t DEFAULT_POOOL_SIZE = 4
 

Detailed Description

Database connection manager. Synopsis:

// set up connection
database::add_connection(connection_string);
// get connection with a connection string
database::get_connection_async(
connection_string,
// run queries here
},
[](boost::system::error_code) {
// handle the connection error here
}
);
// get a connection created with alias
database::get_connection_async(
dbalias,
// run queries here
},
[](boost::system::error_code) {
// handle the connection error here
}
);
//

Definition at line 57 of file database.hpp.

Member Typedef Documentation

typedef std::map< std::string, std::string > tip::db::pg::db_service::connection_params

Definition at line 62 of file database.hpp.

typedef boost::system::error_code tip::db::pg::db_service::error_code

Opaque connection pointer.

Definition at line 60 of file database.hpp.

typedef boost::optional<size_t> tip::db::pg::db_service::optional_size

Definition at line 63 of file database.hpp.

Member Function Documentation

static void tip::db::pg::db_service::add_connection ( std::string const &  connection_string,
optional_size  pool_size = optional_size() 
)
static

Add a connection specification.

Requires an alias, for the database to be referenced by it later.

Parameters
connection_string
pool_sizeA connection can have a pool size different from other connections.
Exceptions
tip::db::pg::error::connection_errorif the connection string cannot be used.
static void tip::db::pg::db_service::begin ( dbalias const &  ,
transaction_callback const &  ,
error_callback const &   
)
static

Create a connection or retrieve a connection from the connection pool and start a transaction.

Will lookup a connection by alias. If a new connection must be created, it will be created with the connection string associated with the alias. If there is an idle connection in the pool, will return it. If no idle connections are available, and the size of connection pool didn't reach it's limit, will create a new one. If the pool is full and no idle connections are available, will return the first connection that becomes idle.

Parameters
aliasdatabase alias
resultcallback function that will be called when a connection becomes available and transaction is started.
errorcallback function that will be called in case of an error.
Exceptions
tip::db::pg::error::connection_errorif the alias is not registered with the database service.
static void tip::db::pg::db_service::initialize ( size_t  pool_size,
connection_params const &  defaults 
)
static

Initialize the database service with the default pool_size per alias and default connection parameters.

Parameters
pool_sizenumber of connections per alias
defaultsdefault settings for the connection
static boost::asio::io_service& tip::db::pg::db_service::io_service ( )
static
static void tip::db::pg::db_service::run ( )
static
static void tip::db::pg::db_service::stop ( )
static

Member Data Documentation

const size_t tip::db::pg::db_service::DEFAULT_POOOL_SIZE = 4
static

Definition at line 65 of file database.hpp.


The documentation for this class was generated from the following file: