Skip to content

Commit b7c336a

Browse files
committed
More fixes to read
1 parent 0d3c878 commit b7c336a

4 files changed

Lines changed: 14 additions & 7 deletions

File tree

include/sqlgen/read.hpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,17 @@ struct Read {
102102
friend auto operator|(const Read& _r, const Limit& _limit) {
103103
static_assert(std::is_same_v<LimitType, Nothing>,
104104
"You cannot call limit(...) twice.");
105-
return Read<Type, WhereType, OrderByType, Limit, Offset>{.where_ = _r.where_,
106-
.limit_ = _limit};
105+
return Read<Type, WhereType, OrderByType, Limit, OffsetType>{.where_ = _r.where_,
106+
.limit_ = _limit,
107+
.offset_ = _r.offset_};
107108
}
108109

109110
friend auto operator|(const Read& _r, const Offset& _offset) {
110111
static_assert(std::is_same_v<OffsetType, Nothing>,
111112
"You cannot call offset(...) twice.");
112-
return Read<Type, WhereType, OrderByType, Limit, Offset>{.where_ = _r.where_,
113-
.offset_ = _offset};
113+
return Read<Type, WhereType, OrderByType, LimitType, Offset>{.where_ = _r.where_,
114+
.limit_ = _r.limit_,
115+
.offset_ = _offset};
114116
}
115117

116118
WhereType where_;

include/sqlgen/select_from.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,8 @@ struct SelectFrom {
300300
.from_ = _s.from_,
301301
.joins_ = _s.joins_,
302302
.where_ = _s.where_,
303-
.limit_ = _s.limit_};
303+
.limit_ = _s.limit_,
304+
.offset_ = _s.offset_};
304305
}
305306

306307
FieldsType fields_;

include/sqlgen/transpilation/read_to_select_from.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ dynamic::SelectFrom read_to_select_from(const WhereType& _where = WhereType{},
5050
.fields = fields,
5151
.where = to_condition<std::remove_cvref_t<T>>(_where),
5252
.order_by = to_order_by<OrderByType>(),
53-
.limit = to_limit(_limit)};
53+
.limit = to_limit(_limit),
54+
.offset = to_offset(_offset)};
5455
}
5556

5657
} // namespace sqlgen::transpilation

tests/sqlite/test_offset.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ TEST(sqlite, test_offset) {
3434
using namespace sqlgen::literals;
3535

3636
const auto query =
37-
sqlgen::read<std::vector<Person>> | order_by("id"_c) | offset(3);
37+
sqlgen::read<std::vector<Person>> | order_by("id"_c) | offset(3);
38+
39+
const auto sql = sqlite::to_sql(query);
40+
std::cout << "SQL: " << sql << std::endl;
3841

3942
const auto people2 = query(conn).value();
4043

0 commit comments

Comments
 (0)