VSQLite++ 0.3
Loading...
Searching...
No Matches
sqlite::v2::json Namespace Reference

Classes

class  path_builder
 Helper for composing JSON path expressions compatible with SQLite's JSON1 dialect. More...

Functions

path_builder path ()
 Convenience shortcut for starting a new JSON path builder rooted at $.
std::string extract_expression (std::string_view json_expr, path_builder const &path)
 Produces a SQL expression that extracts a JSON value at the given path.
std::string contains_expression (std::string_view json_expr, path_builder const &path, std::string_view value_expr)
 Produces a SQL expression that compares a JSON value at path with value_expr.
bool available (connection &con)
 Detects whether the connected SQLite build exposes the JSON1 extension.
void register_contains_function (connection &con, std::string_view function_name="json_contains_value")
 Registers a deterministic SQL scalar function that checks for JSON containment.

Function Documentation

◆ available()

bool sqlite::v2::json::available ( connection & con)

Detects whether the connected SQLite build exposes the JSON1 extension.

Returns
true when JSON functions (e.g. json_extract) can be executed, false otherwise.

◆ contains_expression()

std::string sqlite::v2::json::contains_expression ( std::string_view json_expr,
path_builder const & path,
std::string_view value_expr )

Produces a SQL expression that compares a JSON value at path with value_expr.

This expands to json_extract(json_expr, path) = value_expr so it can be embedded inside WHERE clauses or CHECK constraints.

References path().

Here is the call graph for this function:

◆ extract_expression()

std::string sqlite::v2::json::extract_expression ( std::string_view json_expr,
path_builder const & path )

Produces a SQL expression that extracts a JSON value at the given path.

Parameters
json_exprSQL expression that yields JSON text.
pathJSON path built with path_builder.
Returns
SQL snippet invoking json_extract(json_expr, path).

References path().

Here is the call graph for this function:

◆ path()

path_builder sqlite::v2::json::path ( )
inline

Convenience shortcut for starting a new JSON path builder rooted at $.

Definition at line 91 of file json_fts.hpp.

Referenced by contains_expression(), and extract_expression().

◆ register_contains_function()

void sqlite::v2::json::register_contains_function ( connection & con,
std::string_view function_name = "json_contains_value" )

Registers a deterministic SQL scalar function that checks for JSON containment.

Parameters
conOpen connection that already enabled JSON1.
function_nameOptional SQL symbol name (defaults to json_contains_value).
Exceptions
database_exceptionwhen JSON1 is unavailable or the function cannot be created.