59 lines
1.6 KiB
C++
59 lines
1.6 KiB
C++
#include <catch2/catch_test_macros.hpp>
|
|
#include <catch2/catch_template_test_macros.hpp>
|
|
|
|
#include "matador/sql/connection_pool.hpp"
|
|
#include "matador/sql/session.hpp"
|
|
|
|
#include "Databases.hpp"
|
|
|
|
#include "models/location.hpp"
|
|
|
|
using namespace matador::sql;
|
|
using namespace matador::test;
|
|
|
|
using namespace matador::sql;
|
|
using namespace matador::test;
|
|
|
|
template<class Type>
|
|
class TypeTraitsTestFixture
|
|
{
|
|
public:
|
|
TypeTraitsTestFixture()
|
|
: pool_(Type::dns, 4), session_(pool_)
|
|
{
|
|
auto res = session_.create()
|
|
.table<location>("location")
|
|
.execute();
|
|
REQUIRE(res.first == 0);
|
|
REQUIRE(res.second == R"(CREATE TABLE "location" ("id" BIGINT, "name" VARCHAR(255), "coordinate_x" INTEGER, "coordinate_y" INTEGER, "coordinate_z" INTEGER, "color" INTEGER, CONSTRAINT PK_location PRIMARY KEY (id)))");
|
|
}
|
|
|
|
~TypeTraitsTestFixture()
|
|
{
|
|
session_.drop().table("location").execute();
|
|
}
|
|
|
|
matador::sql::session &session()
|
|
{ return session_; }
|
|
|
|
private:
|
|
matador::sql::connection_pool<matador::sql::connection> pool_;
|
|
matador::sql::session session_;
|
|
};
|
|
|
|
TEMPLATE_TEST_CASE_METHOD(TypeTraitsTestFixture, "Special handling of attributes with type traits", "[typetraits]", Sqlite, Postgres)
|
|
{
|
|
auto &s = TypeTraitsTestFixture<TestType>::session();
|
|
|
|
location loc{1, "center", {1, 2, 3}, Color::Black};
|
|
|
|
auto res = s.insert().template into<location>("location").values(loc).execute();
|
|
REQUIRE(res.first == 1);
|
|
|
|
auto result = s.template select<location>().from("location").template fetch_all<location>();
|
|
|
|
for (const auto &l : result) {
|
|
REQUIRE(l.name == "center");
|
|
}
|
|
|
|
} |