Skip to content

Commit c8695ec

Browse files
Added tests for postgres and MySQL
1 parent aedf02f commit c8695ec

2 files changed

Lines changed: 26 additions & 4 deletions

File tree

tests/mysql/test_dynamic_type.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,17 @@ struct Parser<boost::uuids::uuid> {
3838

3939
} // namespace sqlgen::parsing
4040

41+
namespace sqlgen::transpilation {
42+
43+
template <>
44+
struct ToValue<boost::uuids::uuid> {
45+
dynamic::Value operator()(const boost::uuids::uuid& _u) const {
46+
return dynamic::Value{dynamic::String{.val = boost::uuids::to_string(_u)}};
47+
}
48+
};
49+
50+
} // namespace sqlgen::transpilation
51+
4152
/// For the JSON serialization - not needed for
4253
/// the actual DB operations.
4354
namespace rfl {
@@ -87,10 +98,10 @@ TEST(mysql, test_dynamic_type) {
8798

8899
const auto people2 = sqlgen::write(conn, people1)
89100
.and_then(sqlgen::read<std::vector<Person>> |
90-
order_by("age"_c.desc()))
101+
where("id"_c == people1.front().id()))
91102
.value();
92103

93-
const auto json1 = rfl::json::write(people1);
104+
const auto json1 = rfl::json::write(std::vector<Person>({people1.front()}));
94105
const auto json2 = rfl::json::write(people2);
95106

96107
EXPECT_EQ(json1, json2);

tests/postgres/test_dynamic_type.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,17 @@ struct Parser<boost::uuids::uuid> {
3838

3939
} // namespace sqlgen::parsing
4040

41+
namespace sqlgen::transpilation {
42+
43+
template <>
44+
struct ToValue<boost::uuids::uuid> {
45+
dynamic::Value operator()(const boost::uuids::uuid& _u) const {
46+
return dynamic::Value{dynamic::String{.val = boost::uuids::to_string(_u)}};
47+
}
48+
};
49+
50+
} // namespace sqlgen::transpilation
51+
4152
/// For the JSON serialization - not needed for
4253
/// the actual DB operations.
4354
namespace rfl {
@@ -87,10 +98,10 @@ TEST(postgres, test_dynamic_type) {
8798

8899
const auto people2 = sqlgen::write(conn, people1)
89100
.and_then(sqlgen::read<std::vector<Person>> |
90-
order_by("age"_c.desc()))
101+
where("id"_c == people1.front().id()))
91102
.value();
92103

93-
const auto json1 = rfl::json::write(people1);
104+
const auto json1 = rfl::json::write(std::vector<Person>({people1.front()}));
94105
const auto json2 = rfl::json::write(people2);
95106

96107
EXPECT_EQ(json1, json2);

0 commit comments

Comments
 (0)