19 namespace sph = oral::sph;
21 void OralTest_SimpleRecord::testSimpleRecordInsertSelect ()
23 auto adapted = PrepareRecords<SimpleRecord> (
MakeDatabase ());
24 const auto& list = adapted->Select ();
28 void OralTest_SimpleRecord::testSimpleRecordInsertReplaceSelect ()
32 auto adapted = Util::oral::AdaptPtr<SimpleRecord, OralFactory> (db);
33 for (
int i = 0; i < 3; ++i)
34 adapted->Insert ({ 0, QString::number (i) }, lco::InsertAction::Replace::PKey<SimpleRecord>);
36 const auto& list = adapted->Select ();
40 void OralTest_SimpleRecord::testSimpleRecordInsertIgnoreSelect ()
44 auto adapted = Util::oral::AdaptPtr<SimpleRecord, OralFactory> (db);
45 for (
int i = 0; i < 3; ++i)
48 const auto& list = adapted->Select ();
52 void OralTest_SimpleRecord::testSimpleRecordInsertSelectByPos ()
54 auto adapted = PrepareRecords<SimpleRecord> (
MakeDatabase ());
55 const auto& list = adapted->Select (sph::f<&SimpleRecord::ID_> == 1);
59 void OralTest_SimpleRecord::testSimpleRecordInsertSelectByPos2 ()
61 auto adapted = PrepareRecords<SimpleRecord> (
MakeDatabase ());
62 const auto& list = adapted->Select (sph::f<&SimpleRecord::ID_> < 2);
66 void OralTest_SimpleRecord::testSimpleRecordInsertSelectByPos3 ()
68 auto adapted = PrepareRecords<SimpleRecord> (
MakeDatabase ());
69 const auto& list = adapted->Select (sph::f<&SimpleRecord::ID_> < 2 && sph::f<&SimpleRecord::Value_> == QString {
"1" });
73 void OralTest_SimpleRecord::testSimpleRecordInsertSelectOneByPos ()
75 auto adapted = PrepareRecords<SimpleRecord> (
MakeDatabase ());
76 const auto& single = adapted->SelectOne (sph::f<&SimpleRecord::ID_> == 1);
77 QCOMPARE (single, (std::optional<SimpleRecord> { { 1,
"1" } }));
80 void OralTest_SimpleRecord::testSimpleRecordInsertSelectByFields ()
82 auto adapted = PrepareRecords<SimpleRecord> (
MakeDatabase ());
83 const auto& list = adapted->Select (sph::f<&SimpleRecord::ID_> == 1);
87 void OralTest_SimpleRecord::testSimpleRecordInsertSelectByFields2 ()
89 auto adapted = PrepareRecords<SimpleRecord> (
MakeDatabase ());
90 const auto& list = adapted->Select (sph::f<&SimpleRecord::ID_> < 2);
94 void OralTest_SimpleRecord::testSimpleRecordInsertSelectByFields3 ()
96 auto adapted = PrepareRecords<SimpleRecord> (
MakeDatabase ());
97 const auto& list = adapted->Select (sph::f<&SimpleRecord::ID_> < 2 && sph::f<&SimpleRecord::Value_> == QString {
"1" });
101 void OralTest_SimpleRecord::testSimpleRecordInsertSelectOneByFields ()
103 auto adapted = PrepareRecords<SimpleRecord> (
MakeDatabase ());
104 const auto& single = adapted->SelectOne (sph::f<&SimpleRecord::ID_> == 1);
105 QCOMPARE (single, (std::optional<SimpleRecord> { { 1,
"1" } }));
108 void OralTest_SimpleRecord::testSimpleRecordInsertSelectSingleFieldByFields ()
110 auto adapted = PrepareRecords<SimpleRecord> (
MakeDatabase ());
111 const auto& list = adapted->Select (sph::fields<&SimpleRecord::Value_>, sph::f<&SimpleRecord::ID_> < 2);
115 void OralTest_SimpleRecord::testSimpleRecordInsertSelectFieldsByFields ()
117 auto adapted = PrepareRecords<SimpleRecord> (
MakeDatabase ());
118 const auto& list = adapted->Select (sph::fields<&SimpleRecord::ID_, &SimpleRecord::Value_>, sph::f<&SimpleRecord::ID_> < 2);
119 QCOMPARE (list, (
QList<std::tuple<int, QString>> { { 0,
"0" }, { 1,
"1" } }));
122 void OralTest_SimpleRecord::testSimpleRecordInsertSelectFieldsByFieldsOrderAsc ()
124 auto adapted = PrepareRecords<SimpleRecord> (
MakeDatabase ());
125 const auto& list = adapted->Select (sph::fields<&SimpleRecord::ID_, &SimpleRecord::Value_>,
126 sph::f<&SimpleRecord::ID_> < 2,
128 QCOMPARE (list, (
QList<std::tuple<int, QString>> { { 0,
"0" }, { 1,
"1" } }));
131 void OralTest_SimpleRecord::testSimpleRecordInsertSelectFieldsByFieldsOrderDesc ()
133 auto adapted = PrepareRecords<SimpleRecord> (
MakeDatabase ());
134 const auto& list = adapted->Select (sph::fields<&SimpleRecord::ID_, &SimpleRecord::Value_>,
135 sph::f<&SimpleRecord::ID_> < 2,
137 QCOMPARE (list, (
QList<std::tuple<int, QString>> { { 1,
"1" }, { 0,
"0" } }));
140 void OralTest_SimpleRecord::testSimpleRecordInsertSelectFieldsByFieldsOrderManyAsc ()
142 auto adapted = PrepareRecords<SimpleRecord> (
MakeDatabase ());
143 const auto& list = adapted->Select (sph::fields<&SimpleRecord::ID_, &SimpleRecord::Value_>,
144 sph::f<&SimpleRecord::ID_> < 2,
145 oral::OrderBy<sph::asc<&SimpleRecord::Value_>, sph::desc<&SimpleRecord::ID_>>);
146 QCOMPARE (list, (
QList<std::tuple<int, QString>> { { 0,
"0" }, { 1,
"1" } }));
149 void OralTest_SimpleRecord::testSimpleRecordInsertSelectFieldsByFieldsOrderManyDesc ()
151 auto adapted = PrepareRecords<SimpleRecord> (
MakeDatabase ());
152 const auto& list = adapted->Select (sph::fields<&SimpleRecord::ID_, &SimpleRecord::Value_>,
153 sph::f<&SimpleRecord::ID_> < 2,
154 oral::OrderBy<sph::desc<&SimpleRecord::Value_>, sph::asc<&SimpleRecord::ID_>>);
155 QCOMPARE (list, (
QList<std::tuple<int, QString>> { { 1,
"1" }, { 0,
"0" } }));
158 void OralTest_SimpleRecord::testSimpleRecordInsertSelectNoOffsetLimit ()
160 auto adapted = PrepareRecords<SimpleRecord> (
MakeDatabase (), 10);
161 const auto& list = adapted->Select.Build ().Limit ({ 2 }) ();
165 void OralTest_SimpleRecord::testSimpleRecordInsertSelectOffsetNoLimit ()
167 auto adapted = PrepareRecords<SimpleRecord> (
MakeDatabase (), 10);
168 const auto& list = adapted->Select.Build ().Offset ({ 8 }) ();
172 void OralTest_SimpleRecord::testSimpleRecordInsertSelectOffsetLimit ()
174 auto adapted = PrepareRecords<SimpleRecord> (
MakeDatabase (), 10);
175 const auto& list = adapted->Select.Build ().Offset ({ 5 }).Limit ({ 2 }) ();
179 void OralTest_SimpleRecord::testSimpleRecordInsertSelectCount ()
181 auto adapted = PrepareRecords<SimpleRecord> (
MakeDatabase ());
182 const auto count = adapted->Select (sph::count<>);
186 void OralTest_SimpleRecord::testSimpleRecordInsertSelectCountByFields ()
188 auto adapted = PrepareRecords<SimpleRecord> (
MakeDatabase ());
189 const auto count = adapted->Select (sph::count<>, sph::f<&SimpleRecord::ID_> < 2);
193 void OralTest_SimpleRecord::testSimpleRecordInsertSelectMin ()
195 auto adapted = PrepareRecords<SimpleRecord> (
MakeDatabase ());
196 const auto min = adapted->Select (sph::min<&SimpleRecord::ID_>);
200 void OralTest_SimpleRecord::testSimpleRecordInsertSelectMax ()
202 auto adapted = PrepareRecords<SimpleRecord> (
MakeDatabase ());
203 const auto max = adapted->Select (sph::max<&SimpleRecord::ID_>);
207 void OralTest_SimpleRecord::testSimpleRecordInsertSelectMinPlusMax ()
209 auto adapted = PrepareRecords<SimpleRecord> (
MakeDatabase ());
210 const auto minMax = adapted->Select (sph::min<&SimpleRecord::ID_> + sph::max<&SimpleRecord::ID_>);
211 QCOMPARE (minMax, (std::tuple { 0, 2 }));
214 void OralTest_SimpleRecord::testSimpleRecordInsertSelectValuePlusMinPlusMax ()
216 auto adapted = oral::AdaptPtr<SimpleRecord, OralFactory> (
MakeDatabase ());
217 for (
int i = 0; i < 3; ++i)
218 adapted->Insert ({ i,
"0" });
219 for (
int i = 3; i < 6; ++i)
220 adapted->Insert ({ i,
"1" });
222 const auto allMinMax = adapted->Select.Build ()
223 .Select (sph::fields<&SimpleRecord::Value_> + sph::min<&SimpleRecord::ID_> + sph::max<&SimpleRecord::ID_>)
224 .Group (oral::GroupBy<&SimpleRecord::Value_>)
226 QCOMPARE (allMinMax, (
QList<std::tuple<QString, int, int>> { { {
"0" }, 0, 2 }, { {
"1" }, 3, 5 } }));
229 void OralTest_SimpleRecord::testSimpleRecordInsertSelectAllPlusMinPlusMax ()
231 auto adapted = PrepareRecords<SimpleRecord> (
MakeDatabase (), 2);
232 const auto allMinMax = adapted->Select.Build ()
233 .Select (
sph::all + sph::min<&SimpleRecord::ID_> + sph::max<&SimpleRecord::ID_>)
236 QCOMPARE (allMinMax, (
QList<std::tuple<SimpleRecord, int, int>> { { { 0,
"0" }, 0, 0 }, { { 1,
"1" }, 1, 1 } }));
239 void OralTest_SimpleRecord::testSimpleRecordInsertSelectLike ()
241 using namespace oral::infix;
243 auto adapted = Util::oral::AdaptPtr<SimpleRecord, OralFactory> (
MakeDatabase ());
244 adapted->Insert ({ 0,
"foo" });
245 adapted->Insert ({ 1,
"bar" });
246 adapted->Insert ({ 2,
"foobar" });
247 const auto& list = adapted->Select (sph::f<&SimpleRecord::Value_> |
like| QString {
"%oo%" });
251 void OralTest_SimpleRecord::testSimpleRecordUpdate ()
253 auto adapted = PrepareRecords<SimpleRecord> (
MakeDatabase ());
254 adapted->Update ({ 0,
"meh" });
255 const auto updated = adapted->Select (sph::f<&SimpleRecord::ID_> == 0);
259 void OralTest_SimpleRecord::testSimpleRecordUpdateExprTree ()
261 auto adapted = PrepareRecords<SimpleRecord> (
MakeDatabase ());
262 adapted->Update (sph::f<&SimpleRecord::Value_> = QString {
"meh" }, sph::f<&SimpleRecord::ID_> == 0);
263 const auto updated = adapted->Select (sph::f<&SimpleRecord::ID_> == 0);
267 void OralTest_SimpleRecord::testSimpleRecordUpdateMultiExprTree ()
269 auto adapted = PrepareRecords<SimpleRecord> (
MakeDatabase ());
270 adapted->Update ((sph::f<&SimpleRecord::Value_> = QString {
"meh" }, sph::f<&SimpleRecord::ID_> = 10),
271 sph::f<&SimpleRecord::ID_> == 0);
272 const auto updated = adapted->Select (sph::f<&SimpleRecord::ID_> == 10);