17struct sqlite3_context;
24 std::function<void(sqlite3_context*,
int, sqlite3_value**)>;
28SQLITE_HELPERS_API
void FromSQLiteValue(sqlite3_value& value,
bool& result);
29SQLITE_HELPERS_API
void FromSQLiteValue(sqlite3_value& value,
int& result);
30SQLITE_HELPERS_API
void FromSQLiteValue(sqlite3_value& value,
unsigned int& result);
31SQLITE_HELPERS_API
void FromSQLiteValue(sqlite3_value& value,
long& result);
32SQLITE_HELPERS_API
void FromSQLiteValue(sqlite3_value& value,
unsigned long& result);
33SQLITE_HELPERS_API
void FromSQLiteValue(sqlite3_value& value,
long long& result);
34SQLITE_HELPERS_API
void FromSQLiteValue(sqlite3_value& value,
unsigned long long& result);
35SQLITE_HELPERS_API
void FromSQLiteValue(sqlite3_value& value,
double& result);
36SQLITE_HELPERS_API
void FromSQLiteValue(sqlite3_value& value,
float& result);
37SQLITE_HELPERS_API
void FromSQLiteValue(sqlite3_value& value, std::string& result);
38SQLITE_HELPERS_API
void FromSQLiteValue(sqlite3_value& value, std::string_view& result);
52SQLITE_HELPERS_API
void
58 std::decay_t<T> result;
63template<
typename... Args, std::size_t...
Is>
66 return std::make_tuple(FromSQLiteValue<Args>(*
values[
Is])...);
69template <
typename CallbackType>
72template<
typename R,
typename... Args>
75 static constexpr std::size_t Arity =
sizeof...(Args);
79 return [function = std::move(callback)](
80 sqlite3_context* context,
int argc, sqlite3_value**
argv)
82 if (
argc !=
sizeof...(Args))
88 if constexpr (std::is_same_v<R, void>)
91 function, SQLiteValuesToTuple<Args...>(
92 argv, std::make_index_sequence<
sizeof...(Args)>()));
100 SQLiteValuesToTuple<Args...>(
101 argv, std::make_index_sequence<
sizeof...(Args)>())));
111 return [function = std::move(callback)](sqlite3_context* context)
113 if constexpr (std::is_same_v<R, void>)
121template<
typename CallbackType>
124 using FunctionType =
decltype(std::function { callback });
126 std::move(callback));
129template<
typename CallbackType>
132 using FunctionType =
decltype(std::function { std::declval<CallbackType>() });
136template <
typename CallbackType>
139 using FunctionType =
decltype(std::function { callback });
141 std::move(callback));
149 template<
typename ScalarFunctionType>
151 sqlite3* connection, std::string
name, ScalarFunctionType function)
152 : mConnection { connection }
156 Register(details::GetFunctionArity<ScalarFunctionType>());
169 void Register(
std::
size_t arity);
171 static
void CallFunction(sqlite3_context* context,
int argc, sqlite3_value**
argv);
173 sqlite3* mConnection {
nullptr };
182 template<
typename StepFunctionType,
typename FinalFunctionType>
184 sqlite3* connection, std::string
name, StepFunctionType stepFunction,
185 FinalFunctionType finalFunction)
186 : mConnection { connection }
189 std::move(stepFunction)) }
192 Register(details::GetFunctionArity<StepFunctionType>());
206 void Register(
std::
size_t arity);
208 static
void CallStepFunction (
209 sqlite3_context* context,
int argc, sqlite3_value**
argv);
211 static
void CallFinalFunction(sqlite3_context* context);
213 sqlite3* mConnection {
nullptr };
A class representing an aggregate function in a SQLite database.
details::SQLiteFunctor mFinalFunctor
details::SQLiteFunctorWithArgs mStepFunctor
AggregateFunction(const AggregateFunction &)=delete
AggregateFunction(sqlite3 *connection, std::string name, StepFunctionType stepFunction, FinalFunctionType finalFunction)
AggregateFunction()=default
A class representing a connection to a SQLite database.
A class representing a scalar function in a SQLite database.
details::SQLiteFunctorWithArgs mFunctor
ScalarFunction(sqlite3 *connection, std::string name, ScalarFunctionType function)
ScalarFunction(const ScalarFunction &)=delete
UTILITY_API const char *const * argv
A copy of argv; responsibility of application startup to assign it.
UTILITY_API int argc
A copy of argc; responsibility of application startup to assign it.
Call< Predicate, T > Is
Apply a metapredicate to a type.
void FromSQLiteValue(sqlite3_value &value, bool &result)
auto MakeSQLiteFunctor(CallbackType callback)
std::function< void(sqlite3_context *)> SQLiteFunctor
void SetSQLiteFunctionError(sqlite3_context *context, const std::string_view &error)
constexpr std::size_t GetFunctionArity()
std::function< void(sqlite3_context *, int, sqlite3_value **)> SQLiteFunctorWithArgs
auto MakeSQLiteFunctorWithArgs(CallbackType callback)
void SetSQLiteFunctionResult(sqlite3_context *context, bool value)
auto SQLiteValuesToTuple(sqlite3_value **values, std::index_sequence< Is... >)
static SQLiteFunctor ToSQLiteFunctor(std::function< R()> callback)
static SQLiteFunctorWithArgs ToSQLiteFunctorWithArgs(std::function< R(Args...)> callback)