kDB: Knowledge DataBase
Loading...
Searching...
No Matches
Sql_h.h
1/% QString guard = _database->namespaces().join("_").toUpper() + "_SQL_H_";
2%/ #ifndef _/%= guard %/
3#define _/%= guard %/
4
5#include <QVariant>
6
7namespace /%= _database->namespaces().join("::") %/::Sql
8{
9 enum class Sort
10 {
11 ASC,
12 DESC
13 };
14 enum class Operand
15 {
16 EQ, GT, LT, LTE, GTE, NEQ, LIKE
17 };
18 namespace details
19 {
20 template<typename _T_, class Enable = void>
21 struct value_conversion_helper;
22
23 template<typename _T_>
24 struct value_conversion_helper<_T_, typename std::enable_if<not std::is_enum<_T_>::value>::type>
25 {
26 static knowCore::Value toValue(const _T_& _t)
27 {
29 }
30 static _T_ fromValue(const knowCore::Value& _variant)
31 {
32 if(_variant.isEmpty())
33 {
34 return _T_();
35 } else {
36 return _variant.value<_T_>(knowCore::TypeCheckingMode::Force).expectSuccess();
37 }
38 }
39 };
40 template<typename _T_>
41 struct value_conversion_helper<_T_, typename std::enable_if<std::is_enum<_T_>::value>::type>
42 {
43 static knowCore::Value toValue(const _T_& _t)
44 {
45 return knowCore::Value::fromValue(int(_t));
46 }
47 static _T_ fromValue(const knowCore::Value& _variant)
48 {
49 if(_variant.isEmpty())
50 {
51 return _T_();
52 } else {
53 return _T_(_variant.value<int>().expectSuccess());
54 }
55 }
56 };
57 }
58
59 template<typename _T_>
60 knowCore::Value toVariant(const _T_& _t)
61 {
62 return details::value_conversion_helper<_T_>::toValue(_t);
63 }
64 template<typename _T_>
65 _T_ fromVariant(const knowCore::Value& _variant)
66 {
67 return details::value_conversion_helper<_T_>::fromValue(_variant);
68 }
69
70}
71
72#endif
Definition Value.h:21
bool isEmpty() const
Definition Value.cpp:234
static Value fromValue(const _T_ &_value)
Definition Value.h:241
cres_qresult< _T_ > value(TypeCheckingMode _conversion=TypeCheckingMode::Safe) const
Definition Value.h:353