diff --git a/CMakeLists.txt b/CMakeLists.txt index 6771387..ab3cb4f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,6 +8,8 @@ option(SQLGEN_SQLITE3 "Enable SQLite3 support" ON) # enabled by default option(SQLGEN_BUILD_TESTS "Build tests" OFF) +option(SQLGEN_BUILD_DRY_TESTS_ONLY "Build 'dry' tests only (those that do not require a database connection)" OFF) + set(CMAKE_CXX_STANDARD_REQUIRED ON) if (NOT DEFINED CMAKE_CXX_STANDARD) set(CMAKE_CXX_STANDARD 20) diff --git a/src/sqlgen/postgres/to_sql.cpp b/src/sqlgen/postgres/to_sql.cpp index bf6a74b..cbd20b7 100644 --- a/src/sqlgen/postgres/to_sql.cpp +++ b/src/sqlgen/postgres/to_sql.cpp @@ -225,7 +225,7 @@ std::string insert_to_sql(const dynamic::Insert& _stmt) noexcept { ", ", internal::collect::vector(_stmt.columns | transform(wrap_in_quotes))); return "COPY " + schema + "." + table + "(" + colnames + - ") FROM STDIN WITH DELIMITER '\t' NULL '\e' QUOTE '\a';"; + ") FROM STDIN WITH DELIMITER '\t' NULL '\e' CSV QUOTE '\a';"; } std::string select_from_to_sql(const dynamic::SelectFrom& _stmt) noexcept { diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index c4dbef8..38466d5 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,27 +1,12 @@ -project(sqlgen-tests) - -file(GLOB_RECURSE SOURCES CONFIGURE_DEPENDS "*.cpp") - -add_executable( - sqlgen-tests - ${SOURCES} -) -target_precompile_headers(sqlgen-tests PRIVATE [["sqlgen.hpp"]] ) - if (MSVC) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std:c++20") else() set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -Wall -Werror -ggdb -fconcepts-diagnostics-depth=5") endif() -target_link_libraries( - sqlgen-tests - PRIVATE - "${SQLGEN_GTEST_LIB}" -) - -find_package(GTest) -gtest_discover_tests(sqlgen-tests) +if (SQLGEN_BUILD_DRY_TESTS_ONLY) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DSQLGEN_BUILD_DRY_TESTS_ONLY") +endif() if(SQLGEN_POSTGRES) add_subdirectory(postgres) diff --git a/tests/postgres/test_delete_from.cpp b/tests/postgres/test_delete_from.cpp new file mode 100644 index 0000000..5b2b543 --- /dev/null +++ b/tests/postgres/test_delete_from.cpp @@ -0,0 +1,59 @@ +#ifndef SQLGEN_BUILD_DRY_TESTS_ONLY + +#include + +#include +#include +#include +#include +#include + +namespace test_delete_from { + +struct Person { + sqlgen::PrimaryKey id; + std::string first_name; + std::string last_name; + int age; +}; + +TEST(postgres, test_delete_from) { + const auto people1 = std::vector( + {Person{ + .id = 0, .first_name = "Homer", .last_name = "Simpson", .age = 45}, + Person{.id = 1, .first_name = "Bart", .last_name = "Simpson", .age = 10}, + Person{.id = 2, .first_name = "Lisa", .last_name = "Simpson", .age = 8}, + Person{ + .id = 3, .first_name = "Maggie", .last_name = "Simpson", .age = 0}, + Person{ + .id = 4, .first_name = "Hugo", .last_name = "Simpson", .age = 10}}); + + const auto credentials = sqlgen::postgres::Credentials{.user = "postgres", + .password = "password", + .host = "localhost", + .dbname = "postgres"}; + + using namespace sqlgen; + + const auto conn = + sqlgen::postgres::connect(credentials).and_then(drop | if_exists); + + sqlgen::write(conn, people1).value(); + + const auto delete_hugo = + delete_from | where("first_name"_c == "Hugo"); + + const auto people2 = + conn.and_then(delete_hugo) + .and_then(sqlgen::read> | order_by("id"_c)) + .value(); + + const std::string expected = + R"([{"id":0,"first_name":"Homer","last_name":"Simpson","age":45},{"id":1,"first_name":"Bart","last_name":"Simpson","age":10},{"id":2,"first_name":"Lisa","last_name":"Simpson","age":8},{"id":3,"first_name":"Maggie","last_name":"Simpson","age":0}])"; + + EXPECT_EQ(rfl::json::write(people2), expected); +} + +} // namespace test_delete_from + +#endif diff --git a/tests/postgres/test_insert_dry.cpp b/tests/postgres/test_insert_dry.cpp index 4ee7335..7ed216a 100644 --- a/tests/postgres/test_insert_dry.cpp +++ b/tests/postgres/test_insert_dry.cpp @@ -17,7 +17,7 @@ TEST(postgres, test_insert_dry) { const auto expected = "COPY \"public\".\"TestTable\"(\"field1\", \"field2\", \"id\", " - "\"nullable\") FROM STDIN WITH DELIMITER '\t' NULL '\e' QUOTE '\a';"; + "\"nullable\") FROM STDIN WITH DELIMITER '\t' NULL '\e' CSV QUOTE '\a';"; EXPECT_EQ(sqlgen::postgres::to_sql(query), expected); } diff --git a/tests/postgres/test_limit.cpp b/tests/postgres/test_limit.cpp new file mode 100644 index 0000000..fac7a79 --- /dev/null +++ b/tests/postgres/test_limit.cpp @@ -0,0 +1,56 @@ +#ifndef SQLGEN_BUILD_DRY_TESTS_ONLY + +#include + +#include +#include +#include +#include +#include + +namespace test_limit { + +struct Person { + sqlgen::PrimaryKey id; + std::string first_name; + std::string last_name; + int age; +}; + +TEST(postgres, test_limit) { + const auto people1 = std::vector( + {Person{ + .id = 0, .first_name = "Homer", .last_name = "Simpson", .age = 45}, + Person{.id = 1, .first_name = "Bart", .last_name = "Simpson", .age = 10}, + Person{.id = 2, .first_name = "Lisa", .last_name = "Simpson", .age = 8}, + Person{ + .id = 3, .first_name = "Maggie", .last_name = "Simpson", .age = 0}, + Person{ + .id = 4, .first_name = "Hugo", .last_name = "Simpson", .age = 10}}); + + const auto credentials = sqlgen::postgres::Credentials{.user = "postgres", + .password = "password", + .host = "localhost", + .dbname = "postgres"}; + + using namespace sqlgen; + + const auto conn = + sqlgen::postgres::connect(credentials).and_then(drop | if_exists); + + sqlgen::write(conn, people1).value(); + + const auto query = + sqlgen::read> | order_by("age"_c) | limit(2); + + const auto people2 = query(conn).value(); + + const std::string expected = + R"([{"id":3,"first_name":"Maggie","last_name":"Simpson","age":0},{"id":2,"first_name":"Lisa","last_name":"Simpson","age":8}])"; + + EXPECT_EQ(rfl::json::write(people2), expected); +} + +} // namespace test_limit + +#endif diff --git a/tests/postgres/test_range.cpp b/tests/postgres/test_range.cpp new file mode 100644 index 0000000..92ea408 --- /dev/null +++ b/tests/postgres/test_range.cpp @@ -0,0 +1,63 @@ +#ifndef SQLGEN_BUILD_DRY_TESTS_ONLY + +#include + +#include +#include +#include +#include +#include +#include + +namespace test_range { + +struct Person { + sqlgen::PrimaryKey id; + std::string first_name; + std::string last_name; + int age; +}; + +TEST(postgres, test_range) { + static_assert(std::ranges::input_range>, + "Must be an input range."); + + const auto people1 = std::vector( + {Person{ + .id = 0, .first_name = "Homer", .last_name = "Simpson", .age = 45}, + Person{.id = 1, .first_name = "Bart", .last_name = "Simpson", .age = 10}, + Person{.id = 2, .first_name = "Lisa", .last_name = "Simpson", .age = 8}, + Person{ + .id = 3, .first_name = "Maggie", .last_name = "Simpson", .age = 0}}); + + const auto credentials = sqlgen::postgres::Credentials{.user = "postgres", + .password = "password", + .host = "localhost", + .dbname = "postgres"}; + + using namespace sqlgen; + + const auto conn = + sqlgen::postgres::connect(credentials).and_then(drop | if_exists); + + const auto people2 = + sqlgen::write(conn, people1) + .and_then(sqlgen::read> | order_by("id"_c)) + .value(); + + using namespace std::ranges::views; + + const auto first_names = + internal::collect::vector(people2 | transform([](const auto& _r) { + return _r.value().first_name; + })); + + EXPECT_EQ(first_names.at(0), "Homer"); + EXPECT_EQ(first_names.at(1), "Bart"); + EXPECT_EQ(first_names.at(2), "Lisa"); + EXPECT_EQ(first_names.at(3), "Maggie"); +} + +} // namespace test_range + +#endif diff --git a/tests/postgres/test_timestamp.cpp b/tests/postgres/test_timestamp.cpp new file mode 100644 index 0000000..e7912d2 --- /dev/null +++ b/tests/postgres/test_timestamp.cpp @@ -0,0 +1,47 @@ +#ifndef SQLGEN_BUILD_DRY_TESTS_ONLY + +#include + +#include +#include +#include + +namespace test_timestamp { + +struct Person { + sqlgen::PrimaryKey id; + std::string first_name; + std::string last_name; + sqlgen::Timestamp<"%Y-%m-%d %H:%M:%S"> ts; +}; + +TEST(postgres, test_timestamp) { + const auto people1 = + std::vector({Person{.id = 0, + .first_name = "Homer", + .last_name = "Simpson", + .ts = "2000-01-01 01:00:00"}}); + + using namespace sqlgen; + + const auto credentials = sqlgen::postgres::Credentials{.user = "postgres", + .password = "password", + .host = "localhost", + .dbname = "postgres"}; + + const auto conn = + sqlgen::postgres::connect(credentials).and_then(drop | if_exists); + + const auto people2 = sqlgen::write(conn, people1) + .and_then(sqlgen::read>) + .value(); + + const auto json1 = rfl::json::write(people1); + const auto json2 = rfl::json::write(people2); + + EXPECT_EQ(json1, json2); +} + +} // namespace test_timestamp + +#endif diff --git a/tests/postgres/test_timestamp_with_tz.cpp b/tests/postgres/test_timestamp_with_tz.cpp new file mode 100644 index 0000000..b251dfd --- /dev/null +++ b/tests/postgres/test_timestamp_with_tz.cpp @@ -0,0 +1,47 @@ +#ifndef SQLGEN_BUILD_DRY_TESTS_ONLY + +#include + +#include +#include +#include + +namespace test_timestamp_with_tz { + +struct Person { + sqlgen::PrimaryKey id; + std::string first_name; + std::string last_name; + sqlgen::Timestamp<"%Y-%m-%d %H:%M:%S%z"> ts; +}; + +TEST(postgres, test_timestamp_with_tz) { + const auto people1 = + std::vector({Person{.id = 0, + .first_name = "Homer", + .last_name = "Simpson", + .ts = "2000-01-01 01:00:00+0100"}}); + + using namespace sqlgen; + + const auto credentials = postgres::Credentials{.user = "postgres", + .password = "password", + .host = "localhost", + .dbname = "postgres"}; + + const auto conn = + postgres::connect(credentials).and_then(drop | if_exists); + + const auto people2 = sqlgen::write(conn, people1) + .and_then(sqlgen::read>) + .value(); + + const auto json1 = rfl::json::write(people1); + const auto json2 = rfl::json::write(people2); + + EXPECT_EQ(json1, json2); +} + +} // namespace test_timestamp_with_tz + +#endif diff --git a/tests/postgres/test_transaction.cpp b/tests/postgres/test_transaction.cpp new file mode 100644 index 0000000..8e76cc0 --- /dev/null +++ b/tests/postgres/test_transaction.cpp @@ -0,0 +1,62 @@ +#include + +#include +#include +#include +#include +#include + +namespace test_update { + +struct Person { + sqlgen::PrimaryKey id; + std::string first_name; + std::string last_name; + int age; +}; + +TEST(postgres, test_transaction) { + const auto people1 = std::vector( + {Person{ + .id = 0, .first_name = "Homer", .last_name = "Simpson", .age = 45}, + Person{.id = 1, .first_name = "Bart", .last_name = "Simpson", .age = 10}, + Person{.id = 2, .first_name = "Lisa", .last_name = "Simpson", .age = 8}, + Person{ + .id = 3, .first_name = "Maggie", .last_name = "Simpson", .age = 0}, + Person{ + .id = 4, .first_name = "Hugo", .last_name = "Simpson", .age = 10}}); + + const auto credentials = sqlgen::postgres::Credentials{.user = "postgres", + .password = "password", + .host = "localhost", + .dbname = "postgres"}; + + using namespace sqlgen; + + const auto conn = + postgres::connect(credentials).and_then(drop | if_exists); + + sqlgen::write(conn, people1).value(); + + const auto delete_hugo = + delete_from | where("first_name"_c == "Hugo"); + + const auto update_homers_age = + update("age"_c.set(46)) | where("first_name"_c == "Homer"); + + const auto get_data = sqlgen::read> | order_by("id"_c); + + const auto people2 = begin_transaction(conn) + .and_then(delete_hugo) + .and_then(update_homers_age) + .and_then(commit) + .and_then(get_data) + .value(); + + const std::string expected = + R"([{"id":0,"first_name":"Homer","last_name":"Simpson","age":46},{"id":1,"first_name":"Bart","last_name":"Simpson","age":10},{"id":2,"first_name":"Lisa","last_name":"Simpson","age":8},{"id":3,"first_name":"Maggie","last_name":"Simpson","age":0}])"; + + EXPECT_EQ(rfl::json::write(people2), expected); +} + +} // namespace test_update diff --git a/tests/postgres/test_update.cpp b/tests/postgres/test_update.cpp new file mode 100644 index 0000000..2d8ed9e --- /dev/null +++ b/tests/postgres/test_update.cpp @@ -0,0 +1,60 @@ +#ifndef SQLGEN_BUILD_DRY_TESTS_ONLY + +#include + +#include +#include +#include +#include +#include + +namespace test_update { + +struct Person { + sqlgen::PrimaryKey id; + std::string first_name; + std::string last_name; + int age; +}; + +TEST(postgres, test_update) { + const auto people1 = std::vector( + {Person{ + .id = 0, .first_name = "Homer", .last_name = "Simpson", .age = 45}, + Person{.id = 1, .first_name = "Bart", .last_name = "Simpson", .age = 10}, + Person{.id = 2, .first_name = "Lisa", .last_name = "Simpson", .age = 8}, + Person{ + .id = 3, .first_name = "Maggie", .last_name = "Simpson", .age = 0}, + Person{ + .id = 4, .first_name = "Hugo", .last_name = "Simpson", .age = 10}}); + + const auto credentials = sqlgen::postgres::Credentials{.user = "postgres", + .password = "password", + .host = "localhost", + .dbname = "postgres"}; + + using namespace sqlgen; + + const auto conn = + sqlgen::postgres::connect(credentials).and_then(drop | if_exists); + + sqlgen::write(conn, people1).value(); + + const auto update_hugos_age = + update("first_name"_c.set("last_name"_c), "age"_c.set(100)) | + where("first_name"_c == "Hugo"); + + const auto people2 = + conn.and_then(update_hugos_age) + .and_then(sqlgen::read> | order_by("id"_c)) + .value(); + + const std::string expected = + R"([{"id":0,"first_name":"Homer","last_name":"Simpson","age":45},{"id":1,"first_name":"Bart","last_name":"Simpson","age":10},{"id":2,"first_name":"Lisa","last_name":"Simpson","age":8},{"id":3,"first_name":"Maggie","last_name":"Simpson","age":0},{"id":4,"first_name":"Simpson","last_name":"Simpson","age":100}])"; + + EXPECT_EQ(rfl::json::write(people2), expected); +} + +} // namespace test_update + +#endif diff --git a/tests/postgres/test_varchar.cpp b/tests/postgres/test_varchar.cpp new file mode 100644 index 0000000..1e5c283 --- /dev/null +++ b/tests/postgres/test_varchar.cpp @@ -0,0 +1,52 @@ + +#ifndef SQLGEN_BUILD_DRY_TESTS_ONLY + +#include + +#include +#include +#include +#include +#include + +namespace test_varchar { + +struct Person { + sqlgen::PrimaryKey id; + sqlgen::Varchar<6> first_name; + sqlgen::Varchar<7> last_name; + int age; +}; + +TEST(postgres, test_varchar) { + const auto people1 = std::vector( + {Person{ + .id = 0, .first_name = "Homer", .last_name = "Simpson", .age = 45}, + Person{.id = 1, .first_name = "Bart", .last_name = "Simpson", .age = 10}, + Person{.id = 2, .first_name = "Lisa", .last_name = "Simpson", .age = 8}, + Person{ + .id = 3, .first_name = "Maggie", .last_name = "Simpson", .age = 0}}); + + const auto credentials = sqlgen::postgres::Credentials{.user = "postgres", + .password = "password", + .host = "localhost", + .dbname = "postgres"}; + + using namespace sqlgen; + + const auto conn = + sqlgen::postgres::connect(credentials).and_then(drop | if_exists); + + sqlgen::write(conn, people1).value(); + + const auto people2 = sqlgen::read>(conn).value(); + + const auto json1 = rfl::json::write(people1); + const auto json2 = rfl::json::write(people2); + + EXPECT_EQ(json1, json2); +} + +} // namespace test_varchar + +#endif diff --git a/tests/postgres/test_where.cpp b/tests/postgres/test_where.cpp new file mode 100644 index 0000000..ddaed0a --- /dev/null +++ b/tests/postgres/test_where.cpp @@ -0,0 +1,57 @@ +#ifndef SQLGEN_BUILD_DRY_TESTS_ONLY + +#include + +#include +#include +#include +#include +#include + +namespace test_where { + +struct Person { + sqlgen::PrimaryKey id; + std::string first_name; + std::string last_name; + int age; +}; + +TEST(postgres, test_where) { + const auto people1 = std::vector( + {Person{ + .id = 0, .first_name = "Homer", .last_name = "Simpson", .age = 45}, + Person{.id = 1, .first_name = "Bart", .last_name = "Simpson", .age = 10}, + Person{.id = 2, .first_name = "Lisa", .last_name = "Simpson", .age = 8}, + Person{ + .id = 3, .first_name = "Maggie", .last_name = "Simpson", .age = 0}, + Person{ + .id = 4, .first_name = "Hugo", .last_name = "Simpson", .age = 10}}); + + const auto credentials = sqlgen::postgres::Credentials{.user = "postgres", + .password = "password", + .host = "localhost", + .dbname = "postgres"}; + + using namespace sqlgen; + + const auto conn = + sqlgen::postgres::connect(credentials).and_then(drop | if_exists); + + sqlgen::write(conn, people1).value(); + + const auto query = sqlgen::read> | + where("age"_c < 18 and "first_name"_c != "Hugo") | + order_by("age"_c); + + const auto people2 = query(conn).value(); + + const std::string expected = + R"([{"id":3,"first_name":"Maggie","last_name":"Simpson","age":0},{"id":2,"first_name":"Lisa","last_name":"Simpson","age":8},{"id":1,"first_name":"Bart","last_name":"Simpson","age":10}])"; + + EXPECT_EQ(rfl::json::write(people2), expected); +} + +} // namespace test_where + +#endif diff --git a/tests/postgres/test_write_and_read.cpp b/tests/postgres/test_write_and_read.cpp new file mode 100644 index 0000000..d45d980 --- /dev/null +++ b/tests/postgres/test_write_and_read.cpp @@ -0,0 +1,51 @@ +#ifndef SQLGEN_BUILD_DRY_TESTS_ONLY + +#include + +#include +#include +#include +#include +#include + +namespace test_write_and_read { + +struct Person { + sqlgen::PrimaryKey id; + std::string first_name; + std::string last_name; + int age; +}; + +TEST(postgres, test_write_and_read) { + const auto people1 = std::vector( + {Person{ + .id = 0, .first_name = "Homer", .last_name = "Simpson", .age = 45}, + Person{.id = 1, .first_name = "Bart", .last_name = "Simpson", .age = 10}, + Person{.id = 2, .first_name = "Lisa", .last_name = "Simpson", .age = 8}, + Person{ + .id = 3, .first_name = "Maggie", .last_name = "Simpson", .age = 0}}); + + const auto credentials = sqlgen::postgres::Credentials{.user = "postgres", + .password = "password", + .host = "localhost", + .dbname = "postgres"}; + + using namespace sqlgen; + + const auto conn = + postgres::connect(credentials).and_then(drop | if_exists); + + const auto people2 = sqlgen::write(conn, people1) + .and_then(sqlgen::read>) + .value(); + + const auto json1 = rfl::json::write(people1); + const auto json2 = rfl::json::write(people2); + + EXPECT_EQ(json1, json2); +} + +} // namespace test_write_and_read + +#endif diff --git a/tests/sqlite/test_timestamp.cpp b/tests/sqlite/test_timestamp.cpp index d23216c..5c56c4c 100644 --- a/tests/sqlite/test_timestamp.cpp +++ b/tests/sqlite/test_timestamp.cpp @@ -15,7 +15,7 @@ struct Person { sqlgen::Timestamp<"%Y-%m-%d %H:%M:%S"> birthdate; }; -TEST(sqlite, test_birthdate) { +TEST(sqlite, test_timestamp) { const auto people1 = std::vector({Person{.id = 0, .first_name = "Homer", diff --git a/tests/test_schema.cpp b/tests/test_schema.cpp deleted file mode 100644 index 74095a0..0000000 --- a/tests/test_schema.cpp +++ /dev/null @@ -1,23 +0,0 @@ -#include - -#include -#include - -namespace test_schema { - -struct TestTable { - static constexpr const char* schema = "test"; - - std::string field1; - int32_t field2; - sqlgen::PrimaryKey id; - std::optional nullable; -}; - -TEST(general, test_schema) { - const auto create_table_stmt = - sqlgen::transpilation::to_create_table(); - - EXPECT_EQ(create_table_stmt.table.schema, "test"); -} -} // namespace test_schema diff --git a/tests/test_tablename.cpp b/tests/test_tablename.cpp deleted file mode 100644 index d653ecc..0000000 --- a/tests/test_tablename.cpp +++ /dev/null @@ -1,23 +0,0 @@ -#include - -#include -#include - -namespace test_tablename { - -struct TestTable { - static constexpr const char* tablename = "TEST_TABLE"; - - std::string field1; - int32_t field2; - sqlgen::PrimaryKey id; - std::optional nullable; -}; - -TEST(general, test_tablename) { - const auto create_table_stmt = - sqlgen::transpilation::to_create_table(); - - EXPECT_EQ(create_table_stmt.table.name, "TEST_TABLE"); -} -} // namespace test_tablename diff --git a/tests/test_to_create_table.cpp b/tests/test_to_create_table.cpp deleted file mode 100644 index c933e8d..0000000 --- a/tests/test_to_create_table.cpp +++ /dev/null @@ -1,27 +0,0 @@ -#include - -#include -#include -#include - -namespace test_to_create_table { - -struct TestTable { - std::string field1; - int32_t field2; - sqlgen::PrimaryKey id; - std::optional nullable; -}; - -TEST(general, test_to_create_table) { - const auto create_table_stmt = - sqlgen::transpilation::to_create_table(); - - const std::string expected = - R"({"table":{"name":"TestTable"},"columns":[{"name":"field1","type":{"type":"Text","properties":{"primary":false,"nullable":false}}},{"name":"field2","type":{"type":"Int32","properties":{"primary":false,"nullable":false}}},{"name":"id","type":{"type":"UInt32","properties":{"primary":true,"nullable":false}}},{"name":"nullable","type":{"type":"Text","properties":{"primary":false,"nullable":true}}}],"if_not_exists":true})"; - - const auto json_str = rfl::json::write(create_table_stmt); - - EXPECT_EQ(json_str, expected); -} -} // namespace test_to_create_table diff --git a/tests/test_to_insert.cpp b/tests/test_to_insert.cpp deleted file mode 100644 index 66ae407..0000000 --- a/tests/test_to_insert.cpp +++ /dev/null @@ -1,26 +0,0 @@ -#include - -#include -#include -#include - -namespace test_to_insert { - -struct TestTable { - std::string field1; - int32_t field2; - sqlgen::PrimaryKey id; - std::optional nullable; -}; - -TEST(general, test_to_insert) { - const auto insert_stmt = sqlgen::transpilation::to_insert(); - - const std::string expected = - R"({"table":{"name":"TestTable"},"columns":["field1","field2","id","nullable"]})"; - - const auto json_str = rfl::json::write(insert_stmt); - - EXPECT_EQ(json_str, expected); -} -} // namespace test_to_insert diff --git a/tests/test_to_select_from.cpp b/tests/test_to_select_from.cpp deleted file mode 100644 index 52df272..0000000 --- a/tests/test_to_select_from.cpp +++ /dev/null @@ -1,27 +0,0 @@ -#include - -#include -#include -#include - -namespace test_to_select_from { - -struct TestTable { - std::string field1; - int32_t field2; - sqlgen::PrimaryKey id; - std::optional nullable; -}; - -TEST(general, test_to_select_from) { - const auto select_from_stmt = - sqlgen::transpilation::to_select_from(); - - const std::string expected = - R"({"table":{"name":"TestTable"},"columns":[{"name":"field1","type":{"type":"Text","properties":{"primary":false,"nullable":false}}},{"name":"field2","type":{"type":"Int32","properties":{"primary":false,"nullable":false}}},{"name":"id","type":{"type":"UInt32","properties":{"primary":true,"nullable":false}}},{"name":"nullable","type":{"type":"Text","properties":{"primary":false,"nullable":true}}}]})"; - - const auto json_str = rfl::json::write(select_from_stmt); - - EXPECT_EQ(json_str, expected); -} -} // namespace test_to_select_from