added InsertQueryBuilderTest.cpp
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include "matador/object/object_ptr.hpp"
|
||||
|
||||
#include "matador/sql/backend_provider.hpp"
|
||||
#include "matador/sql/connection.hpp"
|
||||
#include "matador/sql/interface/connection_impl.hpp"
|
||||
|
||||
#include "matador/query/schema.hpp"
|
||||
|
||||
#include "matador/query/insert_query_builder.hpp"
|
||||
|
||||
#include "../backend/test_backend_service.hpp"
|
||||
|
||||
#include "../../models/airplane.hpp"
|
||||
#include "../../models/flight.hpp"
|
||||
|
||||
using namespace matador::object;
|
||||
using namespace matador::sql;
|
||||
using namespace matador::query;
|
||||
using namespace matador::utils;
|
||||
|
||||
TEST_CASE("insert query builder test", "[query][insert_query_builder]") {
|
||||
using namespace matador::test;
|
||||
backend_provider::instance().register_backend("noop", std::make_unique<orm::test_backend_service>());
|
||||
connection db("noop://noop.db");
|
||||
|
||||
schema scm;
|
||||
auto result = scm.attach<airplane>("airplanes")
|
||||
.and_then( [&scm] { return scm.attach<flight>("flights"); } );
|
||||
REQUIRE(result);
|
||||
|
||||
insert_query_builder iqb(scm);
|
||||
|
||||
const auto a380 = object_ptr(std::make_shared<airplane>(1, "Boeing", "A380" ));
|
||||
auto build_result = iqb.build<airplane>(a380);
|
||||
REQUIRE(build_result.is_ok());
|
||||
|
||||
const auto& stmts = *build_result;
|
||||
REQUIRE(stmts.size() == 1);
|
||||
|
||||
const auto sql = stmts.front().str(db);
|
||||
REQUIRE(sql == R"(INSERT INTO "airplanes" ("id", "brand", "model") VALUES (1, 'Boeing', 'A380'))");
|
||||
}
|
||||
Reference in New Issue
Block a user