14 using LC::operator
""_ct;
21 constexpr
static auto ClassName =
"AutogenPKeyRecord"_ct;
40 constexpr
static auto ClassName =
"NoPKeyRecord"_ct;
44 return std::tie (ID_,
Value_);
54 struct NonInPlaceConstructibleRecord
59 NonInPlaceConstructibleRecord () =
default;
61 NonInPlaceConstructibleRecord (
int id,
const QString& value,
double someExtraArgument)
65 Q_UNUSED (someExtraArgument)
68 constexpr
static auto ClassName =
"NonInPlaceConstructibleRecord"_ct;
72 return std::tie (ID_,
Value_);
80 TOSTRING (NonInPlaceConstructibleRecord)
82 struct ComplexConstraintsRecord
89 constexpr
static auto ClassName =
"ComplexConstraintsRecord"_ct;
93 return std::tie (ID_,
Value_, Age_, Weight_);
110 template<
typename... Args>
111 QDebug
operator<< (QDebug dbg,
const std::tuple<Args...>&
tup)
113 return std::apply ([&] (
auto&&... args) {
return ((dbg.nospace () << args <<
' '), ...); },
tup);
120 namespace sph = oral::sph;
122 void OralTest::testAutoPKeyRecordInsertSelect ()
124 qDebug () << oral::detail::FieldNames<AutogenPKeyRecord>;
125 auto adapted = PrepareRecords<AutogenPKeyRecord> (
MakeDatabase ());
126 const auto& list = adapted->Select ();
130 void OralTest::testAutoPKeyRecordInsertRvalueReturnsPKey ()
132 auto adapted = Util::oral::AdaptPtr<AutogenPKeyRecord, OralFactory> (
MakeDatabase ());
135 for (
int i = 0; i < 3; ++i)
136 ids << adapted->Insert ({ 0, QString::number (i) });
141 void OralTest::testAutoPKeyRecordInsertConstLvalueReturnsPKey ()
143 auto adapted = Util::oral::AdaptPtr<AutogenPKeyRecord, OralFactory> (
MakeDatabase ());
146 for (
int i = 0; i < 3; ++i)
147 records.push_back ({ 0, QString::number (i) });
150 for (
const auto& record : records)
151 ids << adapted->Insert (record);
156 void OralTest::testAutoPKeyRecordInsertSetsPKey ()
158 auto adapted = Util::oral::AdaptPtr<AutogenPKeyRecord, OralFactory> (
MakeDatabase ());
161 for (
int i = 0; i < 3; ++i)
162 records.push_back ({ 0, QString::number (i) });
164 for (
auto& record : records)
165 adapted->Insert (record);
170 void OralTest::testNoPKeyRecordInsertSelect ()
172 auto adapted = PrepareRecords<NoPKeyRecord> (
MakeDatabase ());
173 const auto& list = adapted->Select ();
177 void OralTest::testNonInPlaceConstructibleRecordInsertSelect ()
179 auto adapted = Util::oral::AdaptPtr<NonInPlaceConstructibleRecord, OralFactory> (
MakeDatabase ());
180 for (
int i = 0; i < 3; ++i)
181 adapted->Insert ({ i, QString::number (i), 0 });
183 const auto& list = adapted->Select ();
189 template<
typename Ex,
typename F>
190 void ShallThrow (F&&
f)
202 QCOMPARE (failed,
true);
206 void OralTest::testComplexConstraintsRecordInsertSelectDefault ()
208 auto adapted = Util::oral::AdaptPtr<ComplexConstraintsRecord, OralFactory> (
MakeDatabase ());
210 adapted->Insert ({ 0,
"first", 1, 2 });
211 ShallThrow<oral::QueryException> ([&] { adapted->Insert ({ 0,
"second", 1, 2 }); });
212 ShallThrow<oral::QueryException> ([&] { adapted->Insert ({ 0,
"first", 1, 3 }); });
213 adapted->Insert ({ 0,
"second", 1, 3 });
214 ShallThrow<oral::QueryException> ([&] { adapted->Insert ({ 0,
"first", 1, 3 }); });
216 const auto& list = adapted->Select ();
220 void OralTest::testComplexConstraintsRecordInsertSelectIgnore ()
222 auto adapted = Util::oral::AdaptPtr<ComplexConstraintsRecord, OralFactory> (
MakeDatabase ());
230 const auto& list = adapted->Select ();
234 void OralTest::testComplexConstraintsRecordInsertSelectReplace ()
236 auto adapted = Util::oral::AdaptPtr<ComplexConstraintsRecord, OralFactory> (
MakeDatabase ());
238 const auto idValueFields = lco::InsertAction::Replace::Fields<
239 &ComplexConstraintsRecord::ID_,
242 const auto weightAgeFields = lco::InsertAction::Replace::Fields<
243 &ComplexConstraintsRecord::Weight_,
244 &ComplexConstraintsRecord::Age_
246 adapted->Insert ({ 0,
"first", 1, 2 }, idValueFields);
247 adapted->Insert ({ 0,
"second", 1, 2 }, weightAgeFields);
248 adapted->Insert ({ 0,
"first", 1, 3 }, idValueFields);
249 adapted->Insert ({ 0,
"third", 1, 3 }, weightAgeFields);
250 adapted->Insert ({ 0,
"first", 1, 3 }, weightAgeFields);
252 const auto& list = adapted->Select ();
static constexpr struct LC::Util::oral::InsertAction::IgnoreTag Ignore
const std::tuple< Args... > & tup
QSqlDatabase MakeDatabase(const QString &name=":memory:")
ORAL_ADAPT_STRUCT(AutogenPKeyRecord, ID_, Value_) struct NoPKeyRecord
constexpr detail::ExprTree< detail::ExprType::LeafStaticPlaceholder, detail::MemberPtrs< Ptr > > f
static constexpr auto ClassName
QDBusArgument & operator<<(QDBusArgument &out, const IconFrame &frame)
Typelist< Args... > Constraints