15#include <boost/preprocessor/stringize.hpp>
16#include <boost/preprocessor/tuple.hpp>
33#ifndef ORAL_ADAPT_STRUCT
35#define ORAL_STRING_FIELD_IMPL(index, sname, field) \
37 constexpr auto MemberNameByIdx<sname, index> = CtString { BOOST_PP_STRINGIZE(field) }; \
39 constexpr auto MemberNameByPtr<&sname::field> = CtString { BOOST_PP_STRINGIZE(field) };
41#define ORAL_STRING_FIELD(_, index, args) \
42 ORAL_STRING_FIELD_IMPL(index, BOOST_PP_TUPLE_ELEM(0, args), BOOST_PP_TUPLE_ELEM(index, BOOST_PP_TUPLE_ELEM(1, args)))
44#define ORAL_ADAPT_STRUCT(sname, ...) \
45namespace LC::Util::oral \
48 constexpr auto BeenAdapted<sname> = true; \
51 constexpr auto SeqSize<sname> = BOOST_PP_TUPLE_SIZE((__VA_ARGS__)); \
53 static_assert (SeqSize<sname> == detail::FullSize<sname>); \
55 BOOST_PP_REPEAT(BOOST_PP_TUPLE_SIZE((__VA_ARGS__)), ORAL_STRING_FIELD, (sname, (__VA_ARGS__))) \
66 using std::runtime_error::runtime_error;
82 template<
typename,
int>
90 template<
size_t Idx,
typename Seq>
91 constexpr decltype (
auto)
Get (
const Seq& seq)
93 const auto& [...fields] = seq;
94 return (fields... [Idx]);
97 template<
size_t Idx,
typename Seq>
98 constexpr decltype (
auto)
Get (Seq& seq)
100 auto& [...fields] = seq;
101 return (fields... [Idx]);
104 template<
typename Seq>
107 const auto& [...fields] = seq;
108 return std::integral_constant<size_t,
sizeof... (fields)> {};
111 template<
typename Seq>
114 template<
typename T, CtString str>
117 if constexpr (
requires { T::template FieldNameMorpher<str> (); })
118 return T::template FieldNameMorpher<str> ();
119 else if constexpr (str.EndsWith (
'_'))
120 return str.template Chop<1> ();
125 template<
typename Seq,
int Idx>
133 constexpr auto SeqIndices = std::make_index_sequence<SeqSize<S>> {};
136 constexpr auto FieldNames = []<
size_t... Ix> (std::index_sequence<Ix...>)
constexpr
142 constexpr auto BoundFieldNames = []<
size_t... Ix> (std::index_sequence<Ix...>)
constexpr
166 template<
typename ImplFactory,
typename T>
169 constexpr auto operator() () const noexcept
177 else if constexpr (std::is_same_v<T, double>)
179 else if constexpr (std::is_same_v<T, QString> || std::is_same_v<T, QDateTime> || std::is_same_v<T, QUrl>)
181 else if constexpr (std::is_same_v<T, QByteArray>)
182 return ImplFactory::TypeLits::Binary;
184 static_assert (std::is_same_v<T, struct Dummy>,
"Unsupported type");
188 template<
typename ImplFactory,
typename T>
194 template<
typename ImplFactory,
typename T>
200 template<
typename ImplFactory,
typename T,
typename...
Tags>
206 template<
typename ImplFactory,
typename...
Tags>
209 constexpr auto operator() () const noexcept {
return ImplFactory::TypeLits::IntAutoincrement; }
212 template<
typename ImplFactory,
typename T>
218 template<
typename ImplFactory, auto Ptr>
221 constexpr auto operator() () const noexcept
230 requires (!std::same_as<T, QVariant>)
237 requires (!std::same_as<T, QVariant>)
240 static QVariant operator() (
const T& t)
noexcept
243 return t.ToVariant ();
246 else if constexpr (std::is_same_v<T, QDateTime>)
247 return t.toString (Qt::ISODateWithMs);
248 else if constexpr (std::is_enum_v<T>)
249 return static_cast<qint64
> (t);
256 static T operator() (
const QVariant& var)
noexcept
259 return T::FromVariant (var);
262 else if constexpr (std::is_same_v<T, QDateTime>)
263 return QDateTime::fromString (var.toString (), Qt::ISODateWithMs);
264 else if constexpr (std::is_enum_v<T>)
265 return static_cast<T
> (var.value<qint64> ());
269 return var.value<T> ();
276 static QVariant operator() (
const std::optional<T>& t)
noexcept
281 static std::optional<T> operator() (
const QVariant& var)
noexcept
283 return var.isNull () ? std::nullopt : std::optional {
Convert<T> (var) };
289 template<
typename Seq,
int Idx>
290 using ValueAtC_t = std::decay_t<decltype (Get<Idx> (std::declval<Seq> ()))>;
295 template<
typename U,
typename...
Tags>
304 template<
size_t Ix,
typename Seq>
305 void BindAtIndex (
const Seq& seq, QSqlQuery& query,
bool bindPrimaryKey)
311 template<
typename Seq>
312 auto DoInsert (
const Seq& seq, QSqlQuery& insertQuery,
bool bindPrimaryKey)
314 [&]<
size_t... Ix> (std::index_sequence<Ix...>)
319 if (!insertQuery.exec ())
321 qCritical () <<
"insert query execution failed";
327 template<
typename Seq>
330 auto run = []<
size_t... Idxes> (std::index_sequence<Idxes...>)
339 template<
typename Seq>
343 static_assert (idx >= 0);
347 template<
typename Seq>
350 template<
typename Seq>
353 template<
typename Seq>
362 template<
typename Seq>
367 return []<
size_t... Idxs> (std::index_sequence<Idxs...>)
369 const auto [...namesPack] = allNames;
370 return std::tuple { namesPack... [Idxs >=
PKeyIndex_v<Seq> ? Idxs + 1 : Idxs]... };
371 } (std::make_index_sequence<SeqSize<Seq> - 1> ());
376 template<
typename Seq,
auto... Ptrs>
382 template<
typename Seq>
385 const QSqlDatabase DB_;
393 template<
typename Action = InsertAction::DefaultTag>
394 auto operator() (Seq& t, Action action = {})
const
396 return Run<SQLite::ImplFactory> (t, action);
399 template<
typename ImplFactory>
400 auto operator() (ImplFactory, Seq& t,
auto action)
const
402 return Run<ImplFactory> (t, action);
405 template<
typename Action = InsertAction::DefaultTag>
406 auto operator() (
const Seq& t, Action action = {})
const
408 return Run<SQLite::ImplFactory> (t, action);
411 template<
typename ImplFactory>
412 auto operator() (ImplFactory,
const Seq& t,
auto action)
const
414 return Run<ImplFactory> (t, action);
417 template<
typename ImplFactory,
typename Action>
418 constexpr static auto MakeInsertSuffix (Action action)
420 if constexpr (HasAutogen_)
423 if constexpr (std::is_same_v<Action, InsertAction::DefaultTag> || std::is_same_v<Action, InsertAction::IgnoreTag>)
427 ExtractReplaceFields<Seq> (action),
428 GetFieldName<Seq, pkIdx> ());
432 if constexpr (std::is_same_v<Action, InsertAction::DefaultTag> || std::is_same_v<Action, InsertAction::IgnoreTag>)
433 return ImplFactory::GetInsertSuffix (action);
435 return ImplFactory::GetInsertSuffix (InsertAction::Replace {},
436 ExtractReplaceFields<Seq> (action));
440 template<
typename ImplFactory>
441 constexpr static auto MakeQueryForAction (
auto action)
443 return ImplFactory::GetInsertPrefix (action) +
444 " INTO " + Seq::ClassName +
445 " (" +
JoinTup (FieldNames<Seq>,
", ") +
") " +
446 "VALUES (" +
JoinTup (BoundFieldNames<Seq>,
", ") +
") " +
447 MakeInsertSuffix<ImplFactory> (action);
450 template<
typename ImplFactory,
typename T,
typename Action>
451 auto Run (T& t, Action action)
const
453 QSqlQuery query { DB_ };
454 constexpr auto queryText = MakeQueryForAction<ImplFactory> (action);
455 query.prepare (ToString<queryText> ());
459 if constexpr (HasAutogen_)
461 constexpr auto pkIndex = PKeyIndex_v<Seq>;
462 constexpr auto mightBeMissing = std::same_as<Action, InsertAction::IgnoreTag>;
467 if constexpr (mightBeMissing)
468 return std::optional<FieldType_t> {};
469 throw QueryException {
"unable to fetch last inserted rowid" };
472 const auto& lastId = Convert<FieldType_t> (query.value (0));
474 if constexpr (!std::is_const_v<T>)
475 Get<pkIndex> (t) = lastId;
477 if constexpr (mightBeMissing)
478 return std::optional { lastId };
485 template<
typename Seq>
496 constexpr auto del =
"DELETE FROM " + Seq::ClassName +
511 template<
typename T,
size_t...
Indices>
545 template<ExprType Type>
567 static_assert (std::is_same_v<struct D1, ExprType>,
"Invalid expression type");
582 template<ExprType Type>
586 return "lower(" + subexpr +
")";
600 WrapDirect<T>>::value_type;
602 template<ExprType Type,
typename Seq,
typename L,
typename R>
609 return requires (LReal l, RReal r) { l == r; };
615 template<ExprType Type,
typename L =
void,
typename R =
void>
621 template<ExprType Type,
typename L,
typename R>
624 template<
typename L,
typename R>
636 template<
typename Seq, CtString S>
637 constexpr static auto ToSql () noexcept
640 return L::GetFieldName () +
" = " + R::template
ToSql<Seq, S +
"r"> ();
645 template<
typename Seq, CtString S>
648 Left_.template
BindValues<Seq, S +
"l"> (query);
649 Right_.template
BindValues<Seq, S +
"r"> (query);
652 template<
typename OL,
typename OR>
659 template<ExprType Type,
typename L,
typename R>
665 constexpr ExprTree (
const L& l,
const R& r) noexcept
671 template<
typename Seq, CtString S>
672 constexpr static auto ToSql () noexcept
675 "Incompatible types passed to a relational operator.");
682 template<
typename Seq, CtString S>
685 Left_.template
BindValues<Seq, S +
"l"> (query);
686 Right_.template
BindValues<Seq, S +
"r"> (query);
715 template<
typename, CtString S>
716 constexpr static auto ToSql () noexcept
718 return ":bound_" + S;
721 template<
typename Seq, CtString S>
731 return std::tuple {};
741 template<
typename... Ts>
744 const std::tuple<Ts...>& Data_;
746 template<
size_t Idx, CtString S>
752 constexpr ExprTree (
const std::tuple<Ts...>& t) noexcept
757 template<
typename, CtString S>
758 constexpr static auto ToSql () noexcept
762 return "(" +
Join (
", "_ct, BoundVarName<Indices, S>...) +
")";
763 } (std::index_sequence_for<Ts...> {});
766 template<
typename Seq, CtString S>
771 (query.bindValue (
ToString<BoundVarName<Indices, S>> (),
ToVariantF (std::get<Indices> (Data_))), ...);
772 } (std::index_sequence_for<Ts...> {});
778 return std::tuple {};
797 template<
auto... Ptr>
808 template<
typename Seq, CtString S>
809 constexpr static auto ToSql () noexcept
814 template<
typename Seq, CtString S>
828 if constexpr (std::is_same_v<Seq, T>)
829 return std::tuple {};
831 return std::tuple { Seq::ClassName };
837 return !std::is_same_v<MemberPtrStruct_t<Ptr>, T>;
840 constexpr auto operator= (
const ExpectedType_t& r)
const noexcept
846 template<
auto... Ptrs>
847 requires (
sizeof... (Ptrs) > 1)
850 using ExpectedType_t = std::tuple<MemberPtrType_t<Ptrs>...>;
855 template<
typename Seq, CtString S>
856 constexpr static auto ToSql () noexcept
861 template<
typename Seq, CtString S>
869 return std::tuple_cat ([]
872 if constexpr (std::is_same_v<Seq, T>)
873 return std::tuple {};
875 return std::tuple { Seq::ClassName };
882 return !(std::is_same_v<MemberPtrStruct_t<Ptrs>, T> || ...);
890 template<
typename, CtString>
891 constexpr static auto ToSql () noexcept
896 template<
typename, CtString>
910 template<ExprType Type,
typename L,
typename R>
918 template<
typename L,
typename R>
921 template<
typename L,
typename R>
928 template<
typename L,
typename R>
929 requires EitherIsExprTree<L, R>
930 auto operator< (
const L& left,
const R& right)
noexcept
935 template<
typename L,
typename R>
936 requires EitherIsExprTree<L, R>
937 auto operator<= (
const L& left,
const R& right)
noexcept
942 template<
typename L,
typename R>
943 requires EitherIsExprTree<L, R>
944 auto operator> (
const L& left,
const R& right)
noexcept
949 template<
typename L,
typename R>
950 requires EitherIsExprTree<L, R>
951 auto operator>= (
const L& left,
const R& right)
noexcept
956 template<
typename L,
typename R>
957 requires EitherIsExprTree<L, R>
958 auto operator!= (
const L& left,
const R& right)
noexcept
963 template<ExprType Op>
975 template<
typename L, ExprType Op>
981 template<
typename L, ExprType Op>
987 template<
typename L, ExprType Op,
typename R>
993 template<
typename L,
typename R>
994 requires EitherIsExprTree<L, R>
995 auto operator&& (
const L& left,
const R& right)
noexcept
1000 template<
typename L,
typename R>
1001 requires EitherIsExprTree<L, R>
1002 auto operator|| (
const L& left,
const R& right)
noexcept
1007 template<CtString BindPrefix,
typename Seq,
typename Tree>
1010 return Tree::template ToSql<Seq, BindPrefix> ();
1013 template<CtString BindPrefix,
typename Seq,
typename Tree>
1016 tree.template BindValues<Seq, BindPrefix> (query);
1026 template<AggregateFunction, auto Ptr>
1029 template<
typename FunRetType, CtString Fun, auto Ptr>
1034 template<
typename... MemberDirectionList>
1037 template<
auto... Ptrs>
1042 template<
typename L,
typename R>
1045 template<
typename T>
1051 template<
typename T>
1057 template<AggregateFunction Fun, auto Ptr>
1060 template<
typename FunRetType, CtString Fun, auto Ptr>
1063 template<
auto... Ptrs>
1066 template<
typename L,
typename R>
1069 template<
typename T>
1072 template<
typename L,
typename R>
1085 template<
auto... Ptrs>
1088 template<
auto... Ptrs>
1093 template<
typename T>
1096 template<
auto... Ptrs>
1099 template<
auto... Ptrs>
1103 template<
auto Ptr = std::true_type {}>
1112 template<
typename FunRetType, CtString Fun, auto Ptr>
1116 template<
typename... Orders>
1119 template<
auto... Ptrs>
1146 template<
auto... Ptrs>
1149 if constexpr (
sizeof... (Ptrs) == 1)
1152 return [&]<
size_t... Ix> (std::index_sequence<Ix...>)
1155 } (std::make_index_sequence<
sizeof... (Ptrs)> {});
1165 template<
size_t RepIdx,
size_t TupIdx,
typename Tuple,
typename NewType>
1168 if constexpr (RepIdx == TupIdx)
1169 return std::forward<NewType> (arg);
1171 return std::get<TupIdx> (tuple);
1174 template<
size_t RepIdx,
typename NewType,
typename Tuple,
size_t... TupIdxs>
1183 template<
size_t RepIdx,
typename NewType,
typename... TupleArgs>
1187 std::forward<NewType> (arg),
1188 std::index_sequence_for<TupleArgs...> {});
1191 template<
typename Seq,
typename T>
1197 template<
typename Seq,
typename... Args>
1203 template<
typename Seq>
1209 template<
typename... LArgs,
typename... RArgs>
1210 auto Combine (std::tuple<LArgs...>&& left, std::tuple<RArgs...>&& right)
noexcept
1212 return std::tuple_cat (std::move (left), std::move (right));
1215 template<
typename... LArgs,
typename R>
1216 auto Combine (std::tuple<LArgs...>&& left,
const R& right)
noexcept
1218 return std::tuple_cat (std::move (left), std::tuple { right });
1221 template<
typename L,
typename... RArgs>
1222 auto Combine (
const L& left, std::tuple<RArgs...>&& right)
noexcept
1224 return std::tuple_cat (std::tuple { left }, std::move (right));
1227 template<
typename L,
typename R>
1228 auto Combine (
const L& left,
const R& right)
noexcept
1230 return std::tuple { left, right };
1239 template<ResultBehaviour ResultBehaviour,
typename ResList>
1243 return std::forward<ResList> (list);
1245 return list.value (0);
1250 const QSqlDatabase DB_;
1258 auto&& binder)
const
1260 QSqlQuery query { DB_ };
1261 query.prepare (queryStr);
1266 qCritical () <<
"select query execution failed";
1275 template<
typename L,
typename O>
1278 if constexpr (std::is_same_v<L, LimitNone>)
1280 static_assert (std::is_same_v<O, OffsetNone>,
"LIMIT-less queries currently cannot have OFFSET");
1284 return " LIMIT :limit "_ct +
1287 if constexpr (std::is_same_v<O, OffsetNone>)
1290 return " OFFSET :offset"_ct;
1294 template<
typename L,
typename O>
1297 if constexpr (!std::is_same_v<std::decay_t<L>,
LimitNone>)
1298 query.bindValue (
":limit", qulonglong { limit.Count });
1299 if constexpr (!std::is_same_v<std::decay_t<O>,
OffsetNone>)
1300 query.bindValue (
":offset", qulonglong { offset.Count });
1303 template<
typename T,
typename Selector>
1309 template<
typename T>
1320 template<
typename T,
typename U>
1326 template<
typename T,
auto... Ptrs>
1337 template<
typename T,
typename FunRetType, CtString Fun, auto Ptr>
1348 template<
typename T>
1351 constexpr static auto Fields =
"count(1)"_ct;
1355 return q.value (startIdx).toLongLong ();
1359 template<
typename T, auto Ptr>
1366 return q.value (startIdx).toLongLong ();
1370 template<CtString Aggregate,
typename T, auto Ptr>
1377 const auto& var = q.value (startIdx);
1378 return var.isNull () ?
1384 template<
typename T, auto Ptr>
1387 template<
typename T, auto Ptr>
1397 template<
typename T,
typename L,
typename R>
1405 constexpr static auto Fields = HL::Fields +
", " + HR::Fields;
1409 constexpr auto shift =
DetectShift<T,
decltype (HL::Initializer (q, 0))>::Value;
1410 return Combine (HL::Initializer (q, startIdx), HR::Initializer (q, startIdx + shift));
1414 template<
typename T, SelectBehaviour SelectBehaviour>
1417 template<
typename ParamsTuple>
1421 ParamsTuple Params_;
1423 template<
typename NewTuple>
1424 constexpr auto RepTuple (NewTuple&& tuple)
noexcept
1426 return Builder<NewTuple> { W_, tuple };
1429 template<
typename U>
1430 constexpr auto Select (U&& selector) &&
noexcept
1435 template<
typename U>
1436 constexpr auto Where (U&& tree) &&
noexcept
1441 template<
typename U>
1442 constexpr auto AndWhere (U&& tree) &&
noexcept
1444 return std::move (*this).Where (std::get<1> (Params_) && std::forward<U> (tree));
1447 template<
typename U>
1448 constexpr auto Order (U&& order) &&
noexcept
1453 template<
typename U>
1454 constexpr auto Group (U&& group) &&
noexcept
1459 constexpr auto Limit (
Limit limit) &&
noexcept
1464 constexpr auto Limit (uint64_t limit) &&
noexcept
1466 return std::move (*this).Limit (
oral::Limit { limit });
1474 constexpr auto Offset (uint64_t offset) &&
noexcept
1476 return std::move (*this).Offset (
oral::Offset { offset });
1479 auto operator() () &&
1481 return std::apply (W_, Params_);
1484 template<
auto... Ptrs>
1485 constexpr auto Group () &&
noexcept
1495 std::tuple defParams
1504 return Builder<
decltype (defParams)> { *
this, defParams };
1507 auto operator() ()
const
1512 template<
typename Single>
1513 auto operator() (Single&& single)
const
1516 return (*
this) (
SelectWhole {}, std::forward<Single> (single));
1523 ExprType Type,
typename L,
typename R,
1529 auto operator() (Selector,
1533 Limit limit = LimitNone {},
1534 Offset offset = OffsetNone {})
const
1536 using TreeType_t = ExprTree<Type, L, R>;
1538 constexpr auto where = ExprTreeToSql<
"", T, TreeType_t> ();
1539 constexpr auto wherePrefix = [where]
1541 if constexpr (where.IsEmpty ())
1544 return " WHERE "_ct;
1546 constexpr auto from = BuildFromClause<TreeType_t> ();
1547 const auto binder = [&] (QSqlQuery& query)
1549 BindExprTree<
"", T> (tree, query);
1550 BindLimitOffset (query, limit, offset);
1552 using HS = HandleSelector<T, Selector>;
1554 constexpr auto query =
"SELECT " + HS::Fields +
1556 wherePrefix + where +
1557 HandleOrder (std::forward<Order> (order)) +
1558 HandleGroup (std::forward<Group> (group)) +
1559 LimitOffsetToString<Limit, Offset> ();
1560 auto selectResult = Select<HS> (ToString<query> (), binder);
1561 return HandleResultBehaviour<HS::ResultBehaviour_v> (std::move (selectResult));
1564 template<
typename HS,
typename Binder>
1565 auto Select (
const QString& queryStr,
1566 Binder&& binder)
const
1568 auto query =
RunQuery (queryStr, binder);
1572 QList<
decltype (HS::Initializer (query, 0))> result;
1573 while (query.next ())
1574 result << HS::Initializer (query, 0);
1579 using RetType_t = std::optional<
decltype (HS::Initializer (query, 0))>;
1580 return query.next () ?
1581 RetType_t { HS::Initializer (query, 0) } :
1586 template<
typename Tree>
1587 consteval static auto BuildFromClause () noexcept
1589 if constexpr (Tree::template HasAdditionalTables<T> ())
1590 return T::ClassName +
", " + JoinTup (Nub<Tree::template AdditionalTables<T>> (),
", ");
1592 return T::ClassName;
1595 constexpr static auto HandleOrder (OrderNone)
noexcept
1600 template<
auto... Ptrs>
1601 constexpr static auto HandleSuborder (sph::asc<Ptrs...>)
noexcept
1603 return std::tuple { (QualifiedFieldNameByPtr<Ptrs> +
" ASC")... };
1606 template<
auto... Ptrs>
1607 constexpr static auto HandleSuborder (sph::desc<Ptrs...>)
noexcept
1609 return std::tuple { (QualifiedFieldNameByPtr<Ptrs> +
" DESC")... };
1612 template<
typename... Suborders>
1613 constexpr static auto HandleOrder (OrderBy<Suborders...>)
noexcept
1615 return " ORDER BY " +
JoinTup (std::tuple_cat (HandleSuborder (Suborders {})...),
", ");
1618 constexpr static auto HandleGroup (GroupNone)
noexcept
1623 template<
auto... Ptrs>
1624 constexpr static auto HandleGroup (GroupBy<Ptrs...>)
noexcept
1626 return " GROUP BY " +
Join (
", ", QualifiedFieldNameByPtr<Ptrs>...);
1630 template<
typename T>
1633 const QSqlDatabase DB_;
1640 template<ExprType Type,
typename L,
typename R>
1645 constexpr auto selectAll =
"DELETE FROM " + T::ClassName +
" WHERE " + where;
1647 QSqlQuery query { DB_ };
1654 template<
typename T>
1657 const QSqlDatabase DB_;
1660 QSqlQuery UpdateByPKey_ { DB_ };
1669 constexpr auto update =
"UPDATE " + T::ClassName +
1670 " SET " +
JoinTup (statements,
", ") +
1671 " WHERE " + std::get<pkeyIdx> (statements);
1678 DoInsert (seq, UpdateByPKey_,
true);
1681 template<
typename SL,
typename SR, ExprType WType,
typename WL,
typename WR>
1685 "joins in update statements are not supported by SQL");
1690 constexpr auto update =
"UPDATE " + T::ClassName +
1691 " SET " + setClause +
1692 " WHERE " + whereClause;
1694 QSqlQuery query { DB_ };
1700 qCritical () <<
"update query execution failed";
1705 return query.numRowsAffected ();
1710 template<
typename...>
typename Tgt = std::tuple,
1711 template<
typename...>
typename Src,
1714 constexpr auto MapTy (Src<Vals...>,
auto f)
1716 return Tgt { f (Vals {})... };
1719 template<
typename Seq,
auto... Ptrs>
1722 constexpr auto query =
"CREATE INDEX IF NOT EXISTS "_ct +
1729 template<
typename Seq>
1732 if constexpr (
requires {
typename Seq::Indices; })
1736 template<
auto... Ptrs>
1742 template<
auto... Ptrs>
1748 template<
typename T>
1751 if constexpr (
requires {
typename T::Constraints; })
1754 return std::tuple {};
1757 template<
typename ImplFactory,
typename T,
size_t...
Indices>
1758 constexpr auto GetTypes (std::index_sequence<Indices...>)
noexcept
1763 template<auto Name,
typename ImplFactory,
typename T>
1769 constexpr auto constraintsStr = [&]
1771 if constexpr (!std::tuple_size_v<
decltype (constraints)>)
1774 return ", " +
JoinTup (constraints,
", ");
1778 return "CREATE TABLE " +
1786 template<
typename ImplFactory,
typename T>
1793 template<
typename T>
1807 template<
typename T,
typename ImplFactory = detail::SQLite::ImplFactory>
1832 template<
typename T>
1835 template<
typename T,
typename ImplFactory = SQLiteImplFactory>
static UTIL_DB_API void DumpError(const QSqlError &error)
Dumps the error to the qWarning() stream.
A somewhat "strong" typedef.
~QueryException() noexcept=default
AdaptInsert(const QSqlDatabase &db) noexcept
AdaptUpdate(const QSqlDatabase &db) noexcept
constexpr AssignList(const L &l, const R &r) noexcept
void BindValues(QSqlQuery &query) const noexcept
static constexpr auto ToSql() noexcept
DeleteByFieldsWrapper(const QSqlDatabase &db) noexcept
static constexpr bool HasAdditionalTables() noexcept
void BindValues(QSqlQuery &) const noexcept
static constexpr auto ToSql() noexcept
static constexpr auto ToSql() noexcept
static constexpr auto AdditionalTables() noexcept
void BindValues(QSqlQuery &query) const noexcept
static constexpr bool HasAdditionalTables() noexcept
constexpr ExprTree(const T &t) noexcept
static constexpr auto AdditionalTables() noexcept
constexpr ExprTree(const std::tuple< Ts... > &t) noexcept
static constexpr bool HasAdditionalTables() noexcept
static constexpr auto ToSql() noexcept
std::tuple< Ts... > ValueType_t
void BindValues(QSqlQuery &query) const noexcept
ExpectedType_t ValueType_t
static constexpr bool HasAdditionalTables() noexcept
static constexpr auto GetFieldName() noexcept
static constexpr auto ToSql() noexcept
void BindValues(QSqlQuery &) const noexcept
static constexpr auto AdditionalTables() noexcept
void BindValues(QSqlQuery &) const noexcept
static constexpr auto AdditionalTables() noexcept
ExpectedType_t ValueType_t
static constexpr auto ToSql() noexcept
static constexpr bool HasAdditionalTables() noexcept
constexpr ExprTree(const L &l, const R &r) noexcept
static constexpr bool HasAdditionalTables() noexcept
void BindValues(QSqlQuery &query) const noexcept
static constexpr auto ToSql() noexcept
static constexpr auto AdditionalTables() noexcept
auto RunQuery(const QString &queryStr, auto &&binder) const
SelectWrapperCommon(const QSqlDatabase &db) noexcept
SelectWrapperCommon(const QSqlDatabase &db) noexcept
auto Build() const noexcept
auto operator==(const T &left, const T &right)
QSqlQuery RunTextQuery(const QSqlDatabase &db, const QString &text)
Runs the given query text on the given db.
void RunQuery(const QSqlDatabase &db, const QString &pluginName, const QString &filename)
Loads the query from the given resource file and runs it.
decltype(GetFieldAt< I >(std::declval< T >())) FieldType_t
constexpr auto GetTypes(std::index_sequence< Indices... >) noexcept
constexpr auto AdaptCreateTableNamed() noexcept
auto MakeIndexedQueryHandler(const QSqlQuery &q, int startIdx=0) noexcept
consteval int PKeyIndex()
constexpr auto ExprTreeToSql() noexcept
constexpr auto MapTy(Src< Vals... >, auto f)
constexpr auto AsLeafData(const T &node) noexcept
constexpr auto LimitOffsetToString() noexcept
T InitializeFromQuery(const QSqlQuery &q, std::index_sequence< Indices... >, int startIdx) noexcept
void BindLimitOffset(QSqlQuery &query, L limit, O offset) noexcept
auto Combine(std::tuple< LArgs... > &&left, std::tuple< RArgs... > &&right) noexcept
constexpr auto GetConstraintsStrings() noexcept
consteval int PKeyIndexUnsafe()
decltype(auto) HandleResultBehaviour(ResList &&list) noexcept
constexpr auto ConstTrueTree_v
constexpr auto ExtractConstraintFields(UniqueSubset< Ptrs... >)
void AdaptCreateIndices(const QSqlDatabase &db)
auto DoInsert(const Seq &seq, QSqlQuery &insertQuery, bool bindPrimaryKey)
constexpr decltype(auto) Get(const Seq &seq)
QVariant ToVariantF(const T &t) noexcept
constexpr bool IsRelational(ExprType type) noexcept
constexpr auto AdaptCreateTable() noexcept
constexpr bool IsExprTree
auto MemberFromVariant(const QVariant &var) noexcept
constexpr auto FieldNames
consteval auto GetFieldName()
constexpr auto TypeToSql() noexcept
constexpr auto CreateIndex(const QSqlDatabase &db, Index< Ptrs... >)
constexpr decltype(auto) GetReplaceTupleElem(Tuple &&tuple, NewType &&arg) noexcept
constexpr auto FieldNameByPtr
constexpr auto BoundFieldNames
constexpr auto QualifiedFieldNameByPtr
typename std::conditional_t< IsIndirect< T > {}, T, WrapDirect< T > >::value_type UnwrapIndirect_t
constexpr auto ReplaceTupleElem(std::tuple< TupleArgs... > &&tuple, NewType &&arg) noexcept
constexpr auto WrapSubexpr(auto subexpr)
constexpr auto CombineBehaviour(ResultBehaviour l, ResultBehaviour r) noexcept
auto MakeExprTree(const L &left, const R &right) noexcept
void BindAtIndex(const Seq &seq, QSqlQuery &query, bool bindPrimaryKey)
constexpr auto QualifiedFieldNames
std::decay_t< decltype(Get< Idx >(std::declval< Seq >()))> ValueAtC_t
constexpr auto ReplaceTupleElemImpl(Tuple &&tuple, NewType &&arg, std::index_sequence< TupIdxs... >) noexcept
constexpr bool Typecheck()
constexpr bool IsSelector
void BindExprTree(const Tree &tree, QSqlQuery &query)
constexpr int PKeyIndex_v
constexpr auto GetFullSize(const Seq &seq)
consteval auto MorphFieldName()
constexpr auto SeqIndices
constexpr auto HasAutogenPKey() noexcept
constexpr auto ExtractReplaceFields(InsertAction::Replace::WholeType)
constexpr detail::InfixBinary< detail::ExprType::ILike > ilike
constexpr detail::InfixBinary< detail::ExprType::Like > like
constexpr detail::ExprTree< detail::ExprType::LeafStaticPlaceholder, detail::MemberPtrs< Ptr > > f
constexpr detail::ExprTree< detail::ExprType::LeafStaticPlaceholder, detail::MemberPtrs< Ptrs... > > tuple
constexpr detail::SelectWhole all
constexpr detail::CustomFunctionType< FunRetType, Fun, Ptr > fun
constexpr detail::AggregateType< detail::AggregateFunction::Count, Ptr > count
constexpr detail::AggregateType< detail::AggregateFunction::Min, Ptr > min
detail::SelectDistinct< T > distinct
constexpr detail::MemberPtrs< Ptrs... > fields
constexpr detail::AggregateType< detail::AggregateFunction::Max, Ptr > max
void AdaptPtrs(const QSqlDatabase &db, ObjectInfo_ptr< Ts > &... objects)
ObjectInfo_ptr< T > AdaptPtr(const QSqlDatabase &db)
detail::SQLite::ImplFactory SQLiteImplFactory
constexpr detail::OrderBy< Orders... > OrderBy
Typelist< Args... > Indices
constexpr bool BeenAdapted
constexpr detail::GroupBy< Ptrs... > GroupBy
constexpr auto MemberNameByPtr
constexpr auto MemberNameByIdx
ObjectInfo< T > Adapt(const QSqlDatabase &db)
std::unique_ptr< ObjectInfo< T > > ObjectInfo_ptr
std::shared_ptr< QSqlQuery > QSqlQuery_ptr
typename AsTypelist< T >::Result_t AsTypelist_t
QString ToString() noexcept
std::tuple_element_t< 0, detail::CallTypeGetter_t< F > > RetType_t
constexpr auto JoinTup(auto &&stringsTuple, auto &&sep) noexcept
constexpr bool HasType(List< Args... >)
constexpr auto ReplaceAll(CtString< N2, Char > replacement) noexcept
constexpr auto IntegralToString()
constexpr auto ZipWith(Tup1 &&tup1, auto &&sep, Tup2 &&tup2) noexcept
MemberTypeType_t< decltype(Ptr)> MemberPtrType_t
constexpr auto Join(auto &&) noexcept
MemberTypeStruct_t< decltype(Ptr)> MemberPtrStruct_t
A proper void type, akin to unit (or ()) type in functional languages.
detail::AdaptUpdate< T > Update
detail::SelectWrapper< T, detail::SelectBehaviour::Some > Select
detail::AdaptDelete< T > Delete
detail::AdaptInsert< T > Insert
detail::DeleteByFieldsWrapper< T > DeleteBy
detail::SelectWrapper< T, detail::SelectBehaviour::One > SelectOne
AdaptDelete(const QSqlDatabase &db) noexcept
static constexpr int Value
static constexpr int Value
static constexpr int Value
static constexpr auto ResultBehaviour_v
static constexpr auto ResultBehaviour_v
static auto Initializer(const QSqlQuery &q, int startIdx) noexcept
static constexpr auto Fields
static constexpr auto Fields
static auto Initializer(const QSqlQuery &q, int startIdx)
static auto Initializer(const QSqlQuery &q, int startIdx)
static constexpr auto Fields
static constexpr auto Fields
static auto Initializer(const QSqlQuery &q, int startIdx)
static constexpr auto Fields
static auto Initializer(const QSqlQuery &q, int startIdx) noexcept
static constexpr auto Fields
static auto Initializer(const QSqlQuery &q, int startIdx)
static constexpr auto Fields
static constexpr auto Fields
static constexpr auto ResultBehaviour_v
HandleSelector< T, L > HL
static auto Initializer(const QSqlQuery &q, int startIdx) noexcept
HandleSelector< T, R > HR
SelectDistinct(T) noexcept