6#ifndef ATLASGAMEMANAGER_BINDER_HPP
7#define ATLASGAMEMANAGER_BINDER_HPP
19template <
typename T >
23 } -> std::same_as< typename T::value_type& >;
26template <
typename T >
30 } -> std::same_as< bool >;
33template <
typename T >
42template <
typename T >
47 sqlite3_stmt*
stmt {
nullptr };
52 Q_DISABLE_COPY_MOVE(
Binder )
58 Binder(
const std::string_view sql );
60 template <
typename T >
68 "param_counter > param_count = {} > {} for query \"{}\"",
70 sqlite3_bind_parameter_count(
stmt ),
71 std::string( sqlite3_sql(
stmt ) ) ) );
81 "Failed to bind to \"{}\": Reason: \"{}\"",
90 template <
typename T >
92 void operator>>( T& t )
94 std::optional< std::tuple< T > > tpl;
98 if ( tpl.has_value() ) t = std::move( std::get< 0, T >( tpl.value() ) );
101 template <
typename T >
103 void operator>>( std::optional< T >& t )
105 std::optional< std::tuple< T > > tpl;
109 if ( tpl.has_value() )
110 t = std::move( std::get< 0, T >( tpl.value() ) );
115 template <
typename Function >
117 void operator>>( Function&& func )
120 using Tpl = FuncArgs::ArgTuple;
122 std::optional< Tpl > opt_tpl { std::nullopt };
125 while ( opt_tpl.has_value() )
127 std::apply( func, std::move( opt_tpl.value() ) );
132 template <
typename... Ts >
134 void operator>>( std::tuple< Ts... >& tpl )
138 std::optional< std::tuple< Ts... > > opt_tpl { std::nullopt };
141 if ( opt_tpl.has_value() )
143 tpl = std::move( opt_tpl.value() );
150 template <
typename... Ts >
156 "Not enough parameters given for query! Given {}, Expected {}. param_counter != max_param_count = {} != {} for query \"{}\"",
161 std::string( sqlite3_sql(
stmt ) ) ) );
169 const auto step_ret { sqlite3_step(
stmt ) };
176 if constexpr (
sizeof...( Ts ) > 0 )
178 std::tuple< Ts... > tpl;
180 tpl_opt = std::move( tpl );
185 tpl_opt = std::nullopt;
192 tpl_opt = std::nullopt;
204 "DB: Query error: \"{}\", Query: \"{}\"",
206 sqlite3_expanded_sql(
stmt ) ) );
int bindParameter(sqlite3_stmt *, const T, const int) noexcept=delete
Definition binders.hpp:20
sqlite3_stmt * stmt
Definition Binder.hpp:47
bool ran
Definition Binder.hpp:50
void executeQuery(std::optional< std::tuple< Ts... > > &tpl_opt)
Definition Binder.hpp:152
~Binder() noexcept(false)
Definition Binder.cpp:24
Binder & operator<<(T t)
Definition Binder.hpp:63
int max_param_count
Definition Binder.hpp:49
int param_counter
Definition Binder.hpp:48
static sqlite3 & ref()
Returns a ref to the sqlite DB.
Definition Database.cpp:22
debug(format_ns::format_string< Ts... >, Ts &&...) -> debug< Ts... >
Definition FunctionDecomp.hpp:19
Definition exceptions.hpp:17
Definition exceptions.hpp:63