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

Asynchronous query class. More...

#include <query.hpp>

Public Member Functions

 query (dbalias const &alias, std::string const &expression)
 Construct a query. More...
 
template<typename... T>
 query (dbalias const &alias, std::string const &expression, T const &...params)
 Construct a prepared query with params to bind. More...
 
 query (transaction_ptr tran, std::string const &expression)
 Construct a query. More...
 
template<typename... T>
 query (transaction_ptr tran, std::string const &expression, T const &...params)
 Construct a prepared query with params to bind. More...
 
template<typename... T>
querybind (T const &...params)
 Bind parameters for the query. More...
 
querybind ()
 Mark the query as prepared statement. More...
 
void run_async (query_result_callback const &result, error_callback const &error) const
 Start running the query. More...
 
void operator() (query_result_callback const &result, error_callback const &error) const
 

Detailed Description

Asynchronous query class.

Synopsis:

// Simple query
query (alias, "select * from pg_catalog.pg_tables")
([](result_ptr res, bool complete)
{
// process the query results
},
[](boost::system::error_code ec)
{
// handle the error here
});
// Extended query
query (alias, "select * from pg_catalog.pg_type where typelem = $1", 26)
([](result_ptr res, bool complete)
{
// process the query results
},
[](boost::system::error_code ec)
{
// handle the error here
});
See Also
Running queries
Processing query results

Definition at line 51 of file query.hpp.

Constructor & Destructor Documentation

tip::db::pg::query::query ( dbalias const &  alias,
std::string const &  expression 
)

Construct a query.

Query will start a transaction in a connection with the alias.

Parameters
aliasDatabase connection alias.
expressionSQL query expression
template<typename... T>
tip::db::pg::query::query ( dbalias const &  alias,
std::string const &  expression,
T const &...  params 
)

Construct a prepared query with params to bind.

Query will start a transaction in a connection with the alias.

Parameters
aliasdatabase alias
expressionSQL query expression
paramsparameters to bind
Template Parameters
Tquery parameter types

Definition at line 305 of file query.inl.

tip::db::pg::query::query ( transaction_ptr  tran,
std::string const &  expression 
)

Construct a query.

Precondition
Transaction must be started with a db_service::begin or another query.
Parameters
trantransaction object pointer
expressionSQL query expression
template<typename... T>
tip::db::pg::query::query ( transaction_ptr  tran,
std::string const &  expression,
T const &...  params 
)

Construct a prepared query with params to bind.

Precondition
Transaction must be started with a db_service::begin or another query.
Parameters
trantransaction object pointer
expressionSQL query expression
paramsparameters to bind
Template Parameters
Tquery parameter types

Definition at line 312 of file query.inl.

Member Function Documentation

template<typename... T>
query & tip::db::pg::query::bind ( T const &...  params)

Bind parameters for the query.

Precondition
Query constructed
Parameters
paramsprepared query parameters
Template Parameters
Tquery parameter types

Definition at line 343 of file query.inl.

Here is the call graph for this function:

query& tip::db::pg::query::bind ( )

Mark the query as prepared statement.

void tip::db::pg::query::operator() ( query_result_callback const &  result,
error_callback const &  error 
) const

Shortcut for tip::db::pg::query::run_async

Parameters
resultresult callback
errorerror callback
void tip::db::pg::query::run_async ( query_result_callback const &  result,
error_callback const &  error 
) const

Start running the query.

Precondition
If a query was constructed with an alias - the database connection with the alias must be registered with the database service.
Query has been constructed and parameters bound.
Parameters
resultresult callback
errorerror callback
See Also
Callback types

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