Represents a single row of a database result set.
More...
#include <ResultSet.hpp>
|
| | Row ()=default |
| |
| | Row (std::vector< std::string > values, std::shared_ptr< std::unordered_map< std::string, size_t > > col_map) |
| |
| | Row (std::vector< std::optional< std::string > > values, std::shared_ptr< std::unordered_map< std::string, size_t > > col_map) |
| | Values may be std::nullopt for SQL NULL.
|
| |
| std::optional< std::string > | get (size_t index) const |
| | Gets a column value by index.
|
| |
| std::optional< std::string > | get (const std::string &col_name) const |
| | Gets a column value by column name.
|
| |
| template<typename T > |
| std::optional< T > | get_as (size_t index) const |
| | Gets a column converted to T (bool, an integer type, a floating point type or std::string).
|
| |
| template<typename T > |
| std::optional< T > | get_as (const std::string &col_name) const |
| |
| template<typename T > |
| T | value_or (const std::string &col_name, T fallback) const |
| | get_as<T>(), or fallback when that is std::nullopt.
|
| |
| bool | is_null (const std::string &col_name) const |
| | True if the column exists and is SQL NULL.
|
| |
| int | as_int (const std::string &col_name, int default_val=0) const |
| | Helper to get a column value as an integer.
|
| |
| nlohmann::json | to_json () const |
| | Serializes the row to a JSON object automatically. Tries to parse numbers and booleans from strings if possible (Task 52).
|
| |
|
| std::vector< std::optional< std::string > > | values_ |
| |
| std::shared_ptr< std::unordered_map< std::string, size_t > > | col_map_ |
| |
Represents a single row of a database result set.
◆ Row() [1/3]
| orbit::database::Row::Row |
( |
| ) |
|
|
default |
◆ Row() [2/3]
| orbit::database::Row::Row |
( |
std::vector< std::string > |
values, |
|
|
std::shared_ptr< std::unordered_map< std::string, size_t > > |
col_map |
|
) |
| |
|
inline |
◆ Row() [3/3]
| orbit::database::Row::Row |
( |
std::vector< std::optional< std::string > > |
values, |
|
|
std::shared_ptr< std::unordered_map< std::string, size_t > > |
col_map |
|
) |
| |
|
inline |
Values may be std::nullopt for SQL NULL.
◆ as_int()
| int orbit::database::Row::as_int |
( |
const std::string & |
col_name, |
|
|
int |
default_val = 0 |
|
) |
| const |
|
inline |
Helper to get a column value as an integer.
◆ get() [1/2]
| std::optional< std::string > orbit::database::Row::get |
( |
const std::string & |
col_name | ) |
const |
|
inline |
Gets a column value by column name.
- Parameters
-
| col_name | The name of the column. |
- Returns
- An optional containing the string value, or std::nullopt if not found or NULL.
◆ get() [2/2]
| std::optional< std::string > orbit::database::Row::get |
( |
size_t |
index | ) |
const |
|
inline |
Gets a column value by index.
- Parameters
-
| index | The zero-based column index. |
- Returns
- An optional containing the string value, or std::nullopt if index is out of bounds or value is NULL.
◆ get_as() [1/2]
template<typename T >
| std::optional< T > orbit::database::Row::get_as |
( |
const std::string & |
col_name | ) |
const |
|
inline |
◆ get_as() [2/2]
template<typename T >
| std::optional< T > orbit::database::Row::get_as |
( |
size_t |
index | ) |
const |
|
inline |
Gets a column converted to T (bool, an integer type, a floating point type or std::string).
- Returns
- std::nullopt if the column is missing, NULL, or does not convert exactly (out of range, trailing characters).
◆ is_null()
| bool orbit::database::Row::is_null |
( |
const std::string & |
col_name | ) |
const |
|
inline |
True if the column exists and is SQL NULL.
◆ to_json()
Serializes the row to a JSON object automatically. Tries to parse numbers and booleans from strings if possible (Task 52).
◆ value_or()
template<typename T >
| T orbit::database::Row::value_or |
( |
const std::string & |
col_name, |
|
|
T |
fallback |
|
) |
| const |
|
inline |
◆ col_map_
| std::shared_ptr<std::unordered_map<std::string, size_t> > orbit::database::Row::col_map_ |
|
private |
◆ values_
| std::vector<std::optional<std::string> > orbit::database::Row::values_ |
|
private |
The documentation for this class was generated from the following file: