mirror of
https://github.com/getml/sqlgen.git
synced 2026-01-02 07:30:17 -06:00
31 lines
750 B
C++
31 lines
750 B
C++
#include <gtest/gtest.h>
|
|
|
|
#include <sqlgen.hpp>
|
|
#include <sqlgen/mysql.hpp>
|
|
#include <vector>
|
|
|
|
namespace test_where_dry {
|
|
|
|
struct Person {
|
|
sqlgen::PrimaryKey<uint32_t> id;
|
|
std::string first_name;
|
|
std::string last_name;
|
|
int age;
|
|
};
|
|
|
|
TEST(mysql, test_where_dry) {
|
|
using namespace sqlgen;
|
|
using namespace sqlgen::literals;
|
|
|
|
const auto query = sqlgen::read<std::vector<Person>> |
|
|
where("age"_c < 18 and "first_name"_c != "Hugo") |
|
|
order_by("age"_c);
|
|
|
|
const auto expected =
|
|
R"(SELECT `id`, `first_name`, `last_name`, `age` FROM `Person` WHERE (`age` < 18) AND (`first_name` != 'Hugo') ORDER BY `age`)";
|
|
|
|
EXPECT_EQ(sqlgen::mysql::to_sql(query), expected);
|
|
}
|
|
|
|
} // namespace test_where_dry
|