From 39d78d7cb560abf59ea91bec77c104123866dd6d Mon Sep 17 00:00:00 2001 From: "Dr. Patrick Urbanke" Date: Sat, 19 Apr 2025 10:56:38 +0200 Subject: [PATCH] Added the test infrastructure for postgres --- include/sqlgen/postgres/Connection.hpp | 2 +- tests/CMakeLists.txt | 4 ++++ tests/postgres/CMakeLists.txt | 19 +++++++++++++++++++ tests/postgres/test_to_select_from.cpp | 25 +++++++++++++++++++++++++ 4 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 tests/postgres/CMakeLists.txt create mode 100644 tests/postgres/test_to_select_from.cpp diff --git a/include/sqlgen/postgres/Connection.hpp b/include/sqlgen/postgres/Connection.hpp index e3ac3ad..75e6101 100644 --- a/include/sqlgen/postgres/Connection.hpp +++ b/include/sqlgen/postgres/Connection.hpp @@ -23,7 +23,7 @@ class Connection : public sqlgen::Connection { public: Connection(const Credentials& _credentials) - : credentials_(_credentials), conn_(make_conn(_credentials.to_str())) {} + : conn_(make_conn(_credentials.to_str())), credentials_(_credentials) {} static rfl::Result> make( const Credentials& _credentials) noexcept; diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 5192523..c4dbef8 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -23,6 +23,10 @@ target_link_libraries( find_package(GTest) gtest_discover_tests(sqlgen-tests) +if(SQLGEN_POSTGRES) + add_subdirectory(postgres) +endif() + if(SQLGEN_SQLITE3) add_subdirectory(sqlite) endif() diff --git a/tests/postgres/CMakeLists.txt b/tests/postgres/CMakeLists.txt new file mode 100644 index 0000000..18f8296 --- /dev/null +++ b/tests/postgres/CMakeLists.txt @@ -0,0 +1,19 @@ +project(sqlgen-postgres-tests) + +file(GLOB_RECURSE SOURCES CONFIGURE_DEPENDS "*.cpp") + +add_executable( + sqlgen-postgres-tests + ${SOURCES} +) +target_precompile_headers(sqlgen-postgres-tests PRIVATE [["sqlgen.hpp"]] ) + + +target_link_libraries( + sqlgen-postgres-tests + PRIVATE + "${SQLGEN_GTEST_LIB}" +) + +find_package(GTest) +gtest_discover_tests(sqlgen-postgres-tests) diff --git a/tests/postgres/test_to_select_from.cpp b/tests/postgres/test_to_select_from.cpp new file mode 100644 index 0000000..b8d45db --- /dev/null +++ b/tests/postgres/test_to_select_from.cpp @@ -0,0 +1,25 @@ +#include + +#include +#include +#include + +namespace test_to_select_from { + +struct TestTable { + std::string field1; + int32_t field2; + sqlgen::PrimaryKey id; + std::optional nullable; +}; + +TEST(postgres, test_to_select_from) { + /*const auto select_from_stmt = + sqlgen::transpilation::to_select_from(); + const auto conn = sqlgen::postgres::connect().value(); + const auto expected = + R"(SELECT "field1", "field2", "id", "nullable" FROM "TestTable";)"; + + EXPECT_EQ(conn->to_sql(select_from_stmt), expected);*/ +} +} // namespace test_to_select_from