Orbit Framework 2.0.0
A high-performance asynchronous C++20 HTTP server framework.
Loading...
Searching...
No Matches
orbit::database Namespace Reference

Namespaces

namespace  detail
 

Classes

struct  ConnectAwaiter
 A coroutine awaiter for connecting a PostgresClient asynchronously. More...
 
class  ConnectionPool
 A thread-safe connection pool for managing reusable database client connections. More...
 
class  MongoClient
 An asynchronous MongoDB client using coroutines. More...
 
class  MysqlClient
 An asynchronous MySQL client using coroutines and a network Proactor. More...
 
struct  PoolOptions
 Health checking and reconnecting for a ConnectionPool. More...
 
class  PostgresClient
 An asynchronous PostgreSQL client using libpq and a network Proactor. More...
 
struct  QueryAwaiter
 A coroutine awaiter for executing a query on a PostgresClient asynchronously. More...
 
class  RedisClient
 A synchronous Redis client providing core operations. More...
 
struct  ResultAwaiter
 Awaits any PostgresClient operation that reports a ResultSet. More...
 
class  ResultSet
 Represents a generic, unified result set from a database query. More...
 
class  Row
 Represents a single row of a database result set. More...
 

Functions

ConnectAwaiter connect_async (std::shared_ptr< PostgresClient > client)
 Creates an awaiter for connecting a PostgresClient.
 
QueryAwaiter query_async (std::shared_ptr< PostgresClient > client, const std::string &sql)
 Creates an awaiter for executing a query on a PostgresClient.
 
QueryAwaiter query_async (std::shared_ptr< PostgresClient > client, const std::string &sql, std::vector< std::optional< std::string > > params)
 Runs a statement with $1, $2, ... placeholders bound to params.
 
ResultAwaiter execute_async (std::shared_ptr< PostgresClient > client, std::string sql, std::vector< std::optional< std::string > > params={})
 Runs a statement through the prepared-statement cache (PostgresClient::execute).
 
ResultAwaiter begin_async (std::shared_ptr< PostgresClient > client)
 Transaction control for coroutines.
 
ResultAwaiter commit_async (std::shared_ptr< PostgresClient > client)
 
ResultAwaiter rollback_async (std::shared_ptr< PostgresClient > client)
 

Function Documentation

◆ begin_async()

ResultAwaiter orbit::database::begin_async ( std::shared_ptr< PostgresClient >  client)
inline

Transaction control for coroutines.

if (!(co_await begin_async(db)).ok()) co_return;
auto debit = co_await execute_async(db, "UPDATE accounts SET balance = balance - $1 WHERE id = $2", {amount, from});
auto credit = co_await execute_async(db, "UPDATE accounts SET balance = balance + $1 WHERE id = $2", {amount, to});
if (debit.ok() && credit.ok()) co_await commit_async(db);
else co_await rollback_async(db);
ResultAwaiter execute_async(std::shared_ptr< PostgresClient > client, std::string sql, std::vector< std::optional< std::string > > params={})
Runs a statement through the prepared-statement cache (PostgresClient::execute).
Definition PostgresCoro.hpp:109
ResultAwaiter begin_async(std::shared_ptr< PostgresClient > client)
Transaction control for coroutines.
Definition PostgresCoro.hpp:127
ResultAwaiter commit_async(std::shared_ptr< PostgresClient > client)
Definition PostgresCoro.hpp:131
ResultAwaiter rollback_async(std::shared_ptr< PostgresClient > client)
Definition PostgresCoro.hpp:135

◆ commit_async()

ResultAwaiter orbit::database::commit_async ( std::shared_ptr< PostgresClient >  client)
inline

◆ connect_async()

ConnectAwaiter orbit::database::connect_async ( std::shared_ptr< PostgresClient >  client)
inline

Creates an awaiter for connecting a PostgresClient.

Parameters
clientA shared pointer to the PostgresClient.
Returns
A ConnectAwaiter that can be co_awaited.

◆ execute_async()

ResultAwaiter orbit::database::execute_async ( std::shared_ptr< PostgresClient >  client,
std::string  sql,
std::vector< std::optional< std::string > >  params = {} 
)
inline

Runs a statement through the prepared-statement cache (PostgresClient::execute).

◆ query_async() [1/2]

QueryAwaiter orbit::database::query_async ( std::shared_ptr< PostgresClient >  client,
const std::string &  sql 
)
inline

Creates an awaiter for executing a query on a PostgresClient.

Parameters
clientA shared pointer to the PostgresClient.
sqlThe SQL query string to execute.
Returns
A QueryAwaiter that can be co_awaited for the result.
auto result = co_await query_async(client, "SELECT * FROM items");
QueryAwaiter query_async(std::shared_ptr< PostgresClient > client, const std::string &sql)
Creates an awaiter for executing a query on a PostgresClient.
Definition PostgresCoro.hpp:75

◆ query_async() [2/2]

QueryAwaiter orbit::database::query_async ( std::shared_ptr< PostgresClient >  client,
const std::string &  sql,
std::vector< std::optional< std::string > >  params 
)
inline

Runs a statement with $1, $2, ... placeholders bound to params.

co_await query_async(db, "SELECT * FROM users WHERE name = $1", {name});

◆ rollback_async()

ResultAwaiter orbit::database::rollback_async ( std::shared_ptr< PostgresClient >  client)
inline