Support for CREATE TABLE in sqlite

This commit is contained in:
Dr. Patrick Urbanke
2025-04-02 08:18:09 +02:00
parent 9b40b301fc
commit 081a0414c7
13 changed files with 257 additions and 15 deletions

View File

@@ -0,0 +1,24 @@
#include <gtest/gtest.h>
#include <sqlgen.hpp>
#include <sqlgen/parsing/to_create_table.hpp>
#include <sqlgen/sqlite.hpp>
namespace test_to_create_table {
struct TestTable {
std::string field1;
int32_t field2;
sqlgen::PrimaryKey<uint32_t> id;
std::optional<std::string> nullable;
};
TEST(sqlite, test_to_create_table) {
const auto create_table_stmt = sqlgen::parsing::to_create_table<TestTable>();
const auto conn = sqlgen::sqlite::connect().value();
const auto expected =
R"(CREATE TABLE "TestTable" IF NOT EXISTS ("field1" TEXT NOT NULL, "field2" INTEGER NOT NULL, "id" INTEGER PRIMARY KEY NOT NULL, "nullable" TEXT);)";
EXPECT_EQ(conn->to_sql(create_table_stmt), expected);
}
} // namespace test_to_create_table