FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
sqlite_orm/tests/iterate.cpp at master · fnc12/sqlite_orm · GitHub
fnc12
/
sqlite_orm
Public
Uh oh!
There was an error while loading.
Please reload this page
.
Notifications
You must be signed in to change notification settings
Fork
343
Star
2.7k
Code
Issues
13
Pull requests
3
Discussions
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Discussions
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
sqlite_orm
/
tests
/
iterate.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
114 lines (94 loc) · 3.27 KB
Breadcrumbs
sqlite_orm
/
tests
/
iterate.cpp
Copy path
File metadata and controls
114 lines (94 loc) · 3.27 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#
include
<
sqlite_orm/sqlite_orm.h
>
#
include
<
catch2/catch_all.hpp
>
#
include
<
numeric
>
//
std::iota
using
namespace
sqlite_orm
;
TEST_CASE
(
"
Iterate mapped
"
) {
struct
Test
{
int64_t
id;
std::vector<
char
> key;
bool
operator
==(
const
Test& rhs)
const
{
return
this
->
id
== rhs.
id
&&
this
->
key
== rhs.
key
;
}
};
auto
db =
make_storage
(
"
"
,
make_table
(
"
Test
"
,
make_column
(
"
id
"
, &Test::id,
primary_key
()),
make_column
(
"
key
"
, &Test::key)));
db.
sync_schema
(
true
);
std::vector<
char
>
key
(
255
);
iota
(key.
begin
(), key.
end
(),
'
\0
'
);
Test expected{
5
, key};
std::vector<Test> expected_vec{expected};
db.
replace
(expected);
SECTION
(
"
range-based for
"
) {
for
(Test& obj: db.
iterate
<Test>()) {
REQUIRE
(obj == expected);
}
}
SECTION
(
"
from iterator range
"
) {
auto
view = db.
iterate
<Test>();
REQUIRE
(std::vector<Test>{view.
begin
(), view.
end
()} == expected_vec);
}
#
ifdef
SQLITE_ORM_STRUCTURED_BINDINGS_SUPPORTED
SECTION
(
"
borrowed iterator
"
) {
auto
[begin, end] = [](
auto
view) {
return
std::make_pair
(view.
begin
(), view.
end
());
}(db.
iterate
<Test>());
REQUIRE
(*begin == expected);
REQUIRE
(++begin == end);
}
#
endif
#
if
__cpp_lib_containers_ranges >= 202202L
SECTION
(
"
from range
"
) {
auto
view = db.
iterate
<Test>();
REQUIRE
(std::vector<Test>{std::from_range, view} == expected_vec);
}
#
endif
SECTION
(
"
with conditions
"
) {
auto
view = db.
iterate
<Test>(
where
(
c
(&Test::id) ==
5
),
order_by
(&Test::id));
REQUIRE
(std::vector<Test>{view.
begin
(), view.
end
()} == expected_vec);
}
}
#
if
defined(SQLITE_ORM_SENTINEL_BASED_FOR_SUPPORTED) && defined(SQLITE_ORM_DEFAULT_COMPARISONS_SUPPORTED)
TEST_CASE
(
"
Iterate select statement
"
) {
struct
Test
{
int64_t
id;
std::vector<
char
> key;
bool
operator
==(
const
Test&)
const
=
default
;
};
auto
db =
make_storage
(
"
"
,
make_table
(
"
Test
"
,
make_column
(
"
id
"
, &Test::id,
primary_key
()),
make_column
(
"
key
"
, &Test::key)));
db.
sync_schema
(
true
);
std::vector<
char
>
key
(
255
);
iota
(key.
begin
(), key.
end
(),
'
\0
'
);
Test expected{
5
, key};
db.
replace
(expected);
std::vector<Test> expected_vec{expected};
SECTION
(
"
range-based for
"
) {
for
(Test&& obj: db.iterate(
select
(object<Test>()))) {
REQUIRE
(obj == expected);
}
}
#
ifdef
SQLITE_ORM_STL_HAS_DEFAULT_SENTINEL
SECTION
(
"
borrowed iterator
"
) {
std::input_iterator
auto
begin = db.iterate(
select
(object<Test>())).
begin
();
REQUIRE
(*begin == expected);
REQUIRE
(++begin == std::default_sentinel);
}
#
endif
#
if
__cpp_lib_containers_ranges >= 202202L
SECTION
(
"
from range
"
) {
std::ranges::view
auto
view = db.iterate(
select
(object<Test>()));
REQUIRE
(std::vector<Test>{std::from_range, view} == expected_vec);
}
#
endif
#
if
(SQLITE_VERSION_NUMBER >= 3008003) && defined(SQLITE_ORM_WITH_CTE)
#
ifdef
SQLITE_ORM_WITH_CPP20_ALIASES
constexpr
auto
x =
"
x
"
_cte;
std::input_iterator
auto
begin =
db.iterate(
with
(
x
().
as
(
select
(asterisk<Test>())),
select
(struct_<Test>(asterisk<x>())))).
begin
();
REQUIRE
(*begin == expected);
#
endif
#
endif
}
#
endif
Back
|
FazBrowse Home
|
New Git URL