mirror of
https://github.com/getml/sqlgen.git
synced 2025-12-31 06:30:18 -06:00
Added the test infrastructure for postgres
This commit is contained in:
@@ -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<Ref<sqlgen::Connection>> make(
|
||||
const Credentials& _credentials) noexcept;
|
||||
|
||||
@@ -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()
|
||||
|
||||
19
tests/postgres/CMakeLists.txt
Normal file
19
tests/postgres/CMakeLists.txt
Normal file
@@ -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"]] <iostream> <string> <functional> <gtest/gtest.h>)
|
||||
|
||||
|
||||
target_link_libraries(
|
||||
sqlgen-postgres-tests
|
||||
PRIVATE
|
||||
"${SQLGEN_GTEST_LIB}"
|
||||
)
|
||||
|
||||
find_package(GTest)
|
||||
gtest_discover_tests(sqlgen-postgres-tests)
|
||||
25
tests/postgres/test_to_select_from.cpp
Normal file
25
tests/postgres/test_to_select_from.cpp
Normal file
@@ -0,0 +1,25 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <sqlgen.hpp>
|
||||
#include <sqlgen/postgres.hpp>
|
||||
#include <sqlgen/transpilation/to_select_from.hpp>
|
||||
|
||||
namespace test_to_select_from {
|
||||
|
||||
struct TestTable {
|
||||
std::string field1;
|
||||
int32_t field2;
|
||||
sqlgen::PrimaryKey<uint32_t> id;
|
||||
std::optional<std::string> nullable;
|
||||
};
|
||||
|
||||
TEST(postgres, test_to_select_from) {
|
||||
/*const auto select_from_stmt =
|
||||
sqlgen::transpilation::to_select_from<TestTable>();
|
||||
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
|
||||
Reference in New Issue
Block a user