Files
sqlgen/tests/mysql/test_is_null_dry.cpp
2025-07-27 12:25:12 +02:00

33 lines
767 B
C++

#include <gtest/gtest.h>
#include <rfl.hpp>
#include <rfl/json.hpp>
#include <sqlgen.hpp>
#include <sqlgen/mysql.hpp>
#include <vector>
namespace test_is_null_dry {
struct Person {
sqlgen::PrimaryKey<uint32_t> id;
std::string first_name;
std::string last_name;
std::optional<int> age;
};
TEST(mysql, test_is_null_dry) {
using namespace sqlgen;
using namespace sqlgen::literals;
const auto sql =
mysql::to_sql(sqlgen::read<std::vector<Person>> |
where("age"_c.is_null()) | order_by("first_name"_c.desc()));
const std::string expected =
R"(SELECT `id`, `first_name`, `last_name`, `age` FROM `Person` WHERE `age` IS NULL ORDER BY `first_name` DESC)";
EXPECT_EQ(sql, expected);
}
} // namespace test_is_null_dry