pg_async
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
query.hpp
Go to the documentation of this file.
1 
8 #ifndef TIP_DB_PG_QUERY_HPP_
9 #define TIP_DB_PG_QUERY_HPP_
10 
11 #include <tip/db/pg/common.hpp>
12 
13 #include <memory>
14 #include <functional>
15 #include <boost/system/error_code.hpp>
16 
17 namespace tip {
18 namespace db {
19 namespace pg {
20 
51 class query {
52 public:
60  query(dbalias const& alias, std::string const& expression);
61 
71  template < typename ... T >
72  query(dbalias const& alias, std::string const& expression,
73  T const& ... params);
74 
82  query(transaction_ptr tran, std::string const& expression);
83 
93  template < typename ... T >
94  query(transaction_ptr tran, std::string const& expression,
95  T const& ... params);
96 
103  template < typename ... T >
104  query&
105  bind(T const& ... params);
106 
110  query&
111  bind();
121  void
122  run_async(query_result_callback const& result, error_callback const& error) const;
128  void
129  operator()(query_result_callback const& result, error_callback const& error) const;
130 private:
131  typedef std::vector<byte> params_buffer;
132  struct impl;
133  typedef std::shared_ptr<impl> pimpl;
134 
136  param_types();
137  params_buffer&
138  buffer();
139  mutable pimpl pimpl_;
140 private:
141  template < typename ... T >
142  static pimpl
143  create_impl(dbalias const&, std::string const& expression,
144  T const& ... params);
145 
146  static pimpl
147  create_impl(dbalias const&, std::string const& expression,
148  type_oid_sequence&& param_types, params_buffer&& params);
149 
150  template < typename ... T >
151  static pimpl
152  create_impl(transaction_ptr, std::string const& expression,
153  T const& ... params);
154 
155  static pimpl
156  create_impl(transaction_ptr, std::string const& expression,
157  type_oid_sequence&& param_types, params_buffer&& params);
158 
159 };
160 
161 } // namespace pg
162 } // namespace db
163 } // namespace tip
164 
165 #include <tip/db/pg/query.inl>
166 
167 #endif /* TIP_DB_PG_QUERY_HPP_ */
query & bind()
Mark the query as prepared statement.
Short unique string to refer a database. Signature structure, to pass instead of connection string...
Definition: common.hpp:209
std::shared_ptr< transaction > transaction_ptr
Definition: common.hpp:340
Asynchronous query class.
Definition: query.hpp:51
std::function< void(error::db_error const &) > error_callback
Callback for error handling.
Definition: common.hpp:350
query(dbalias const &alias, std::string const &expression)
Construct a query.
void run_async(query_result_callback const &result, error_callback const &error) const
Start running the query.
void operator()(query_result_callback const &result, error_callback const &error) const
std::vector< oids::type::oid_type > type_oid_sequence
Definition: common.hpp:346
std::function< void(transaction_ptr, resultset, bool) > query_result_callback
Callback for query results.
Definition: common.hpp:355