mirror of
https://github.com/getml/sqlgen.git
synced 2026-01-06 01:19:58 -06:00
Support for CREATE TABLE in sqlite
This commit is contained in:
@@ -22,3 +22,7 @@ target_link_libraries(
|
||||
|
||||
find_package(GTest)
|
||||
gtest_discover_tests(sqlgen-tests)
|
||||
|
||||
if(SQLGEN_SQLITE3)
|
||||
add_subdirectory(sqlite)
|
||||
endif()
|
||||
|
||||
19
tests/sqlite/CMakeLists.txt
Normal file
19
tests/sqlite/CMakeLists.txt
Normal file
@@ -0,0 +1,19 @@
|
||||
project(sqlgen-sqlite-tests)
|
||||
|
||||
file(GLOB_RECURSE SOURCES CONFIGURE_DEPENDS "*.cpp")
|
||||
|
||||
add_executable(
|
||||
sqlgen-sqlite-tests
|
||||
${SOURCES}
|
||||
)
|
||||
target_precompile_headers(sqlgen-sqlite-tests PRIVATE [["sqlgen.hpp"]] <iostream> <string> <functional> <gtest/gtest.h>)
|
||||
|
||||
|
||||
target_link_libraries(
|
||||
sqlgen-sqlite-tests
|
||||
PRIVATE
|
||||
"${SQLGEN_GTEST_LIB}"
|
||||
)
|
||||
|
||||
find_package(GTest)
|
||||
gtest_discover_tests(sqlgen-sqlite-tests)
|
||||
24
tests/sqlite/test_to_create_table.cpp
Normal file
24
tests/sqlite/test_to_create_table.cpp
Normal 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
|
||||
Reference in New Issue
Block a user