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

Functions

bool 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 & checked_identifier (const std::string &s)
 
bool is_reserved_word (std::string_view s)
 
std::string ident (const std::string &name)
 Validates an identifier (name or table.name) and marks the parts that are reserved words for quoting.
 
std::string render_identifiers (std::string sql, bool mysql)
 Replaces quote marks with " (PostgreSQL, standard SQL) or a backtick (MySQL).
 
const std::string & checked_operator (const std::string &op)
 
template<typename T >
std::optional< std::string > to_param (const T &val)
 
std::optional< std::string > json_to_param (const nlohmann::json &v)
 
std::string number_placeholders (const std::string &sql)
 Rewrites ? placeholders as PostgreSQL's $1, $2, ...
 
template<typename Escape >
std::string inline_literals (const std::string &sql, const Params &params, Escape &&escape)
 Replaces ? placeholders with escaped, quoted literals (for clients without parameter binding).
 
void throw_if_failed (const database::ResultSet &rs)
 
bool is_unset_key (const nlohmann::json &v)
 A key that the database should generate: null, 0, or an empty string.
 
nlohmann::json 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 > 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 kQuoteMark = '\x01'
 

Function Documentation

◆ checked_identifier()

const std::string & orbit::orm::detail::checked_identifier ( const std::string &  s)
inline

◆ checked_operator()

const std::string & orbit::orm::detail::checked_operator ( const std::string &  op)
inline

◆ ident()

std::string orbit::orm::detail::ident ( const std::string &  name)
inline

Validates an identifier (name or table.name) and marks the parts that are reserved words for quoting.

Exceptions
std::invalid_argumentif it is not a plain identifier.

◆ inline_literals()

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).

◆ is_identifier()

bool orbit::orm::detail::is_identifier ( std::string_view  s)
inline

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.

◆ is_reserved_word()

bool orbit::orm::detail::is_reserved_word ( std::string_view  s)
inline

SQL reserved words likely to be used as table or column names. These are quoted; other identifiers stay unquoted, so PostgreSQL still folds them to lower case exactly as when the table was created without quotes.

◆ is_unset_key()

bool orbit::orm::detail::is_unset_key ( const nlohmann::json &  v)
inline

A key that the database should generate: null, 0, or an empty string.

◆ json_to_param()

std::optional< std::string > orbit::orm::detail::json_to_param ( const nlohmann::json &  v)
inline

◆ number_placeholders()

std::string orbit::orm::detail::number_placeholders ( const std::string &  sql)
inline

Rewrites ? placeholders as PostgreSQL's $1, $2, ...

◆ render_identifiers()

std::string orbit::orm::detail::render_identifiers ( std::string  sql,
bool  mysql 
)
inline

Replaces quote marks with " (PostgreSQL, standard SQL) or a backtick (MySQL).

◆ rows_to_models()

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.

Every column arrives as text. Guessing turned a string column holding "42" or "007" into a number, which a std::string field then failed to read. Columns the model does not declare are ignored; fields with no column keep the value of a default-constructed model.

Exceptions
DatabaseErrorif a row cannot be read into ModelType (e.g. NULL in a non-optional field).

◆ throw_if_failed()

void orbit::orm::detail::throw_if_failed ( const database::ResultSet &  rs)
inline

◆ to_param()

template<typename T >
std::optional< std::string > orbit::orm::detail::to_param ( const T &  val)

◆ typed_value()

nlohmann::json orbit::orm::detail::typed_value ( const std::string &  text,
const nlohmann::json &  proto 
)
inline

Converts a column's text to the JSON type of the model field proto.

Variable Documentation

◆ kQuoteMark

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

Marks a reserved word in generated SQL; replaced by the dialect's quote when the statement is sent (render_identifiers). Values are always bound separately, so this character never comes from user data.