forked from fnc12/sqlite_orm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimple_query.cpp
More file actions
51 lines (48 loc) · 1.46 KB
/
simple_query.cpp
File metadata and controls
51 lines (48 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <sqlite_orm/sqlite_orm.h>
#include <catch2/catch.hpp>
using namespace sqlite_orm;
TEST_CASE("Simple query") {
auto storage = make_storage("");
{
// SELECT 1
auto one = storage.select(1);
REQUIRE(one.size() == 1);
REQUIRE(one.front() == 1);
}
{
// SELECT 'ototo'
auto ototo = storage.select("ototo");
REQUIRE(ototo.size() == 1);
REQUIRE(ototo.front() == "ototo");
}
{
// SELECT 1 + 1
auto two = storage.select(c(1) + 1);
REQUIRE(two.size() == 1);
REQUIRE(two.front() == 2);
auto twoAgain = storage.select(add(1, 1));
REQUIRE(two == twoAgain);
}
{
// SELECT 10 / 5, 2 * 4
auto math = storage.select(columns(sqlite_orm::div(10, 5), mul(2, 4)));
REQUIRE(math.size() == 1);
REQUIRE(math.front() == std::make_tuple(2, 8));
}
{
// SELECT 1, 2
auto twoRows = storage.select(columns(1, 2));
REQUIRE(twoRows.size() == 1);
REQUIRE(std::get<0>(twoRows.front()) == 1);
REQUIRE(std::get<1>(twoRows.front()) == 2);
}
{
// SELECT 1, 2
// UNION ALL
// SELECT 3, 4;
auto twoRowsUnion = storage.select(union_all(select(columns(1, 2)), select(columns(3, 4))));
REQUIRE(twoRowsUnion.size() == 2);
REQUIRE(twoRowsUnion[0] == std::make_tuple(1, 2));
REQUIRE(twoRowsUnion[1] == std::make_tuple(3, 4));
}
}