Database requests related functions.
Functions | |
template<typename Connection , typename Executor = boost::asio::system_executor> | |
cancel_handle< Executor > | ozo::get_cancel_handle (const Connection &connection, Executor &&executor=Executor{}) |
Get cancel handle for the cancel operation. More... | |
template<typename Executor , typename TimeConstraint , typename CancelCompletionToken > | |
auto | ozo::cancel (cancel_handle< Executor > &&handle, io_context &io, TimeConstraint time_constraint, CancelCompletionToken &&token) |
Cancel execution of current request on a database backend. More... | |
template<typename Executor , typename CancelCompletionToken > | |
auto | ozo::cancel (cancel_handle< Executor > &&handle, CancelCompletionToken &&token) |
Cancel execution of current request on a database backend. More... | |
template<typename ConnectionProvider , typename BinaryQueryConvertible , typename TimeConstraint , typename CompletionToken > | |
decltype(auto) | ozo::execute (ConnectionProvider &&provider, BinaryQueryConvertible &&query, TimeConstraint time_constraint, CompletionToken &&token) |
Executes query with no result data expected. More... | |
template<typename ConnectionProvider , typename BinaryQueryConvertible , typename CompletionToken > | |
decltype(auto) | ozo::execute (ConnectionProvider &&provider, BinaryQueryConvertible &&query, CompletionToken &&token) |
Executes query with no result data expected. More... | |
template<typename ConnectionProvider , typename BinaryQueryConvertible , typename TimeConstraint , typename Out , typename CompletionToken > | |
decltype(auto) | ozo::request (ConnectionProvider &&provider, BinaryQueryConvertible &&query, TimeConstraint time_constraint, Out out, CompletionToken &&token) |
Executes query and retrives a result from a database with time constraint. More... | |
template<typename ConnectionProvider , typename BinaryQueryConvertible , typename Out , typename CompletionToken > | |
decltype(auto) | ozo::request (ConnectionProvider &&provider, BinaryQueryConvertible &&query, Out out, CompletionToken &&token) |
Executes query and retrives a result from a database. More... | |
template<typename T > | |
constexpr auto | ozo::into (T &v) |
Shortcut for create result container back inserter. More... | |
template<typename T > | |
constexpr auto | ozo::into (basic_result< T > &v) noexcept |
Shortcut for create reference wrapper for ozo::basic_result . More... | |
auto ozo::cancel | ( | cancel_handle< Executor > && | handle, |
CancelCompletionToken && | token | ||
) |
Cancel execution of current request on a database backend.
This version executes cancel operation without a time constraint.
handle | — handle for the cancel operation, should be obtained via ozo::get_cancel_handle . |
token | — valid CancelCompletionToken (see time constraint version of ozo::cancel() for details). |
CancelCompletionToken
.cancel()
operation. The only option is to stop wait. auto ozo::cancel | ( | cancel_handle< Executor > && | handle, |
io_context & | io, | ||
TimeConstraint | time_constraint, | ||
CancelCompletionToken && | token | ||
) |
Cancel execution of current request on a database backend.
Sometimes you need to cancel request to a database due to operation time constraint. In case of closing connection, PostgreSQL backend will continue to execute request anyway. So to prevent such waste of database resources it is best practice to cancel the execution of the request by sending special command.
handle | — handle for the cancel operation, should be obtained via ozo::get_cancel_handle . |
io | — io_context on which the operation timer will run. |
time_constraint | — time constraint to wait for the operation complete. |
token | — valid CancelCompletionToken which is described below. |
CancelCompletionToken
.It determines how to continue with an asynchronous cancel operation result when the operation is complete.
Valid CancelCompletionToken
is one of:
void(ozo::error_code ec, std::string error_message)
. In this case ozo::cancel()
returns void
. First argument provides error code, second - error message from the undelying libpq
library.boost::asio::use_future
— to get a future on the asynchronous operation result. In this case ozo::cancel()
will return std::future<void>
. Additional error message from the undelying libpq
library will be lost. For this reason the completion token is not recommended for use in production code. In case of synchronization is needed it is better to use a callback with promise and future are used directely.boost::asio::yield_context
— to use async operation with Boost.Coroutine. Asynchronous function in this case will return std::string
. libpq
library error code binding should be used to avoid exception in case of error.boost::asio::async_result
.decltype(auto) ozo::execute | ( | ConnectionProvider && | provider, |
BinaryQueryConvertible && | query, | ||
CompletionToken && | token | ||
) |
Executes query with no result data expected.
This function is time constrain free shortcut to ozo::execute()
function. Its call is equal to ozo::execute(provider, query, ozo::none, token)
call.
provider | — connection provider object |
query | — query object to execute |
token | — operation CompletionToken. |
References ozo::get_operation_initiator(), and ozo::none.
decltype(auto) ozo::execute | ( | ConnectionProvider && | provider, |
BinaryQueryConvertible && | query, | ||
TimeConstraint | time_constraint, | ||
CompletionToken && | token | ||
) |
Executes query with no result data expected.
This function is same as ozo::request()
function except it does not provide any result data. It suitable to use with UPDATE
INSERT
statements, or invoking procedures without result.
provider | — connection provider object |
query | — query object to execute |
time_constraint | — request #TimeConstraint; this time constrain includes time for getting connection from provider. |
token | — operation CompletionToken. |
cancel_handle< Executor > ozo::get_cancel_handle | ( | const Connection & | connection, |
Executor && | executor = Executor{} |
||
) |
Get cancel handle for the cancel operation.
connection | — Connection with active operation to cancel. |
executor | — Executor on which the operation will be executed. Default executor is boost::asio::system_executor . |
Since libpq's cancel operation implementation is synchronous only it would block a thread where executed. That's why it needs a dedicated Executor. User should specify an executor to implement a proper execution strategy, e.g. the operations' queue which would be handled in a dedicated thread and so on.
References ozo::get_native_handle().
|
constexprnoexcept |
Shortcut for create reference wrapper for ozo::basic_result
.
This shortcut creates reference wrapper for ozo::basic_result
to obtain raw result into it.
v | — ozo::basic_result object for rows. |
|
constexpr |
Shortcut for create result container back inserter.
This shortcut defines insert iterator for row container.
v | — container for rows |
decltype(auto) ozo::request | ( | ConnectionProvider && | provider, |
BinaryQueryConvertible && | query, | ||
Out | out, | ||
CompletionToken && | token | ||
) |
Executes query and retrives a result from a database.
This function is time constrain free shortcut to ozo::request()
function. Its call is equal to ozo::request(provider, query, ozo::none, out, token)
call.
provider | — connection provider to get connection from. |
query | — query object to request from a database. |
out | — output object like Iterator, InsertIterator or ozo::result . |
token | — operation CompletionToken. |
References ozo::get_operation_initiator(), and ozo::none.
decltype(auto) ozo::request | ( | ConnectionProvider && | provider, |
BinaryQueryConvertible && | query, | ||
TimeConstraint | time_constraint, | ||
Out | out, | ||
CompletionToken && | token | ||
) |
Executes query and retrives a result from a database with time constraint.
The function sends request to a database and provides result via out parameter. The function can be called as any of Boost.Asio asynchronous function with CompletionToken. The request would be cancelled if time constrain is reached while performing.
provider | — connection provider object to get connection from. |
query | — query object to request from a database. |
time_constraint | — request #TimeConstraint; this time constrain includes time for getting connection from provider. |
out | — output object like Iterator, InsertIterator or ozo::result . |
token | — operation CompletionToken. |