Files
sqlgen/tests/postgres/test_update_dry.cpp
Dr. Patrick Urbanke 9d6cac0502 Added update
2025-05-11 05:15:04 +02:00

28 lines
651 B
C++

#include <gtest/gtest.h>
#include <sqlgen.hpp>
#include <sqlgen/postgres.hpp>
namespace test_update_dry {
struct TestTable {
std::string field1;
int32_t field2;
sqlgen::PrimaryKey<uint32_t> id;
std::optional<std::string> nullable;
};
TEST(postgres, test_update_dry) {
using namespace sqlgen;
const auto query =
update<TestTable>("field1"_c.set("Hello"), "nullable"_c.set("field1"_c)) |
where("field2"_c > 0);
const auto expected =
R"(UPDATE "TestTable" SET "field1" = 'Hello', "nullable" = "field1" WHERE "field2" > 0;)";
EXPECT_EQ(sqlgen::postgres::to_sql(query), expected);
}
} // namespace test_update_dry