Orbit Framework 2.0.0
A high-performance asynchronous C++20 HTTP server framework.
Loading...
Searching...
No Matches
QueryBuilder.hpp File Reference
#include <orbit/legacy_namespaces.hpp>
#include <string>
#include <string_view>
#include <vector>
#include <memory>
#include <optional>
#include <coroutine>
#include <sstream>
#include <stdexcept>
#include <type_traits>
#include <limits>
#include <charconv>
#include <cstdlib>
#include <orbit/http/json.hpp>
#include <orbit/database/ResultSet.hpp>
Include dependency graph for QueryBuilder.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  orbit::orm::Expr
 A SQL condition with ? placeholders and the values bound to them. More...
 
class  orbit::orm::Col
 A database column, allowing C++ operators to build parameterized SQL conditions. More...
 
struct  orbit::orm::Statement
 A statement with ? placeholders and the values bound to them. More...
 
class  orbit::orm::DatabaseError
 A query run by the ORM failed, or its rows did not fit the model. More...
 
struct  orbit::orm::QueryGetAwaiter< DBClient, ModelType >
 
struct  orbit::orm::QueryInsertAwaiter< DBClient, ModelType >
 
struct  orbit::orm::QueryCountAwaiter< DBClient >
 
struct  orbit::orm::QueryCreateAwaiter< DBClient, ModelType >
 Resumes with the row an INSERT ... RETURNING * stored. More...
 
class  orbit::orm::QueryBuilder< DBClient, ModelType >
 A lightweight, JSON-backed ORM Query Builder with bound parameters. More...
 

Namespaces

namespace  orbit
 
namespace  orbit::orm
 
namespace  orbit::orm::detail
 

Typedefs

using orbit::orm::Params = std::vector< std::optional< std::string > >
 Values bound to the ? placeholders of an expression, in order. std::nullopt binds SQL NULL.
 

Enumerations

enum class  orbit::orm::Order { orbit::orm::Asc , orbit::orm::Desc }
 Sort direction for QueryBuilder::order_by(). More...
 

Functions

bool orbit::orm::detail::is_identifier (std::string_view s)
 True for a plain SQL identifier (name) or a qualified one (table.name): ASCII letters, digits and underscores, not starting with a digit. Identifiers cannot be bound as parameters, so anything else is rejected rather than spliced into SQL.
 
const std::string & orbit::orm::detail::checked_identifier (const std::string &s)
 
bool orbit::orm::detail::is_reserved_word (std::string_view s)
 
std::string orbit::orm::detail::ident (const std::string &name)
 Validates an identifier (name or table.name) and marks the parts that are reserved words for quoting.
 
std::string orbit::orm::detail::render_identifiers (std::string sql, bool mysql)
 Replaces quote marks with " (PostgreSQL, standard SQL) or a backtick (MySQL).
 
const std::string & orbit::orm::detail::checked_operator (const std::string &op)
 
template<typename T >
std::optional< std::string > orbit::orm::detail::to_param (const T &val)
 
std::optional< std::string > orbit::orm::detail::json_to_param (const nlohmann::json &v)
 
std::string orbit::orm::detail::number_placeholders (const std::string &sql)
 Rewrites ? placeholders as PostgreSQL's $1, $2, ...
 
template<typename Escape >
std::string orbit::orm::detail::inline_literals (const std::string &sql, const Params &params, Escape &&escape)
 Replaces ? placeholders with escaped, quoted literals (for clients without parameter binding).
 
template<typename DBClient >
constexpr bool orbit::orm::is_mysql_client ()
 Runs sql (with ? placeholders) on either client type.
 
template<typename DBClient >
auto orbit::orm::do_query_async (std::shared_ptr< DBClient > client, const std::string &sql, const Params &params)
 
void orbit::orm::detail::throw_if_failed (const database::ResultSet &rs)
 
bool orbit::orm::detail::is_unset_key (const nlohmann::json &v)
 A key that the database should generate: null, 0, or an empty string.
 
nlohmann::json orbit::orm::detail::typed_value (const std::string &text, const nlohmann::json &proto)
 Converts a column's text to the JSON type of the model field proto.
 
template<typename ModelType >
std::vector< ModelType > orbit::orm::detail::rows_to_models (const database::ResultSet &rs)
 Maps result rows to models, converting each column by the type of the model's field rather than by guessing from its text.
 

Variables

constexpr char orbit::orm::detail::kQuoteMark = '\x01'