collection_resolver progress
This commit is contained in:
parent
f9333158e2
commit
621c3703fd
|
|
@ -188,10 +188,6 @@ int main() {
|
||||||
.where( query::is_null("lastSuccessfulLogin") && LOGIN_HISTORY.login_time < "ll.lastSuccessfulLogin" )
|
.where( query::is_null("lastSuccessfulLogin") && LOGIN_HISTORY.login_time < "ll.lastSuccessfulLogin" )
|
||||||
.str( conn->dialect() );
|
.str( conn->dialect() );
|
||||||
|
|
||||||
std::cout << stmt1 << std::endl;
|
|
||||||
std::cout << stmt2 << std::endl;
|
|
||||||
std::cout << stmt3 << std::endl;
|
|
||||||
|
|
||||||
// const QString subQuery = QString( "SELECT MAX(%1) AS lastSuccessfulLogin, %3 FROM %2 "
|
// const QString subQuery = QString( "SELECT MAX(%1) AS lastSuccessfulLogin, %3 FROM %2 "
|
||||||
// "WHERE(%4 = ? OR %4 = ? OR %4 = ?) AND %3 = ? GROUP BY %3 " );
|
// "WHERE(%4 = ? OR %4 = ? OR %4 = ?) AND %3 = ? GROUP BY %3 " );
|
||||||
//
|
//
|
||||||
|
|
@ -316,6 +312,13 @@ int main() {
|
||||||
.where(JOB.id > _ && JOB.name == _)
|
.where(JOB.id > _ && JOB.name == _)
|
||||||
.str(conn->dialect());
|
.str(conn->dialect());
|
||||||
|
|
||||||
|
std::cout << stmt1 << std::endl;
|
||||||
|
std::cout << stmt2 << std::endl;
|
||||||
|
std::cout << stmt3 << std::endl;
|
||||||
|
std::cout << stmt4 << std::endl;
|
||||||
|
std::cout << stmt5 << std::endl;
|
||||||
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,9 +6,6 @@
|
||||||
|
|
||||||
#include "matador/object/object_resolver.hpp"
|
#include "matador/object/object_resolver.hpp"
|
||||||
|
|
||||||
#include "matador/query/table.hpp"
|
|
||||||
#include "matador/query/select_query_builder.hpp"
|
|
||||||
|
|
||||||
namespace matador::sql {
|
namespace matador::sql {
|
||||||
class executor;
|
class executor;
|
||||||
}
|
}
|
||||||
|
|
@ -17,41 +14,20 @@ namespace matador::query {
|
||||||
template<typename Type>
|
template<typename Type>
|
||||||
class query_object_resolver : public object::object_resolver<Type> {
|
class query_object_resolver : public object::object_resolver<Type> {
|
||||||
public:
|
public:
|
||||||
explicit query_object_resolver(const basic_schema &repo, sql::executor& exec, const table &tab, std::string pk_name)
|
explicit query_object_resolver(sql::statement &&stmt)
|
||||||
: executor_(exec)
|
: stmt_(std::move(stmt)) {}
|
||||||
, schema_(repo)
|
|
||||||
, table_(tab)
|
|
||||||
, pk_name_(std::move(pk_name)) {}
|
|
||||||
|
|
||||||
std::shared_ptr<Type> resolve(const utils::identifier &id) override;
|
std::shared_ptr<Type> resolve(const utils::identifier &id) override;
|
||||||
protected:
|
protected:
|
||||||
sql::executor& executor_;
|
sql::statement stmt_;
|
||||||
const basic_schema &schema_;
|
|
||||||
const table &table_;
|
|
||||||
std::string pk_name_;
|
|
||||||
std::type_index index{typeid(Type)};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
utils::result<sql::statement, utils::error> prepare_statement(sql::executor& exec, entity_query_data &&data);
|
|
||||||
|
|
||||||
template<typename Type>
|
template<typename Type>
|
||||||
std::shared_ptr<Type> query_object_resolver<Type>::resolve(const utils::identifier &id) {
|
std::shared_ptr<Type> query_object_resolver<Type>::resolve(const utils::identifier &id) {
|
||||||
select_query_builder qb(schema_, executor_);
|
sql::identifier_statement_binder binder(stmt_);
|
||||||
const auto *pk_column = table_[pk_name_];
|
|
||||||
auto builder_result = qb.build<Type>(*pk_column == utils::_);
|
|
||||||
|
|
||||||
if (!builder_result) {
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
auto stmt = prepare_statement(executor_, builder_result.release());
|
|
||||||
if (!stmt) {
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
sql::identifier_statement_binder binder(*stmt);
|
|
||||||
binder.bind(id);
|
binder.bind(id);
|
||||||
|
|
||||||
auto result = stmt->template fetch_one_raw<Type>();
|
auto result = stmt_.template fetch_one_raw<Type>();
|
||||||
if (!result) {
|
if (!result) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@
|
||||||
|
|
||||||
#include "matador/query/query_collection_resolver.hpp"
|
#include "matador/query/query_collection_resolver.hpp"
|
||||||
#include "matador/query/query_object_resolver.hpp"
|
#include "matador/query/query_object_resolver.hpp"
|
||||||
|
#include "matador/query/select_query_builder.hpp"
|
||||||
#include "matador/query/basic_schema.hpp"
|
#include "matador/query/basic_schema.hpp"
|
||||||
|
|
||||||
namespace matador::sql {
|
namespace matador::sql {
|
||||||
|
|
@ -119,7 +120,28 @@ public:
|
||||||
Type obj;
|
Type obj;
|
||||||
access::process(pc, obj);
|
access::process(pc, obj);
|
||||||
|
|
||||||
return std::make_shared<query_object_resolver<Type>>(repo_, exec, table_, std::move(pk_name_));
|
select_query_builder qb(repo_, exec);
|
||||||
|
const auto *pk_column = table_[pk_name_];
|
||||||
|
auto builder_result = qb.build<Type>(*pk_column == utils::_);
|
||||||
|
|
||||||
|
if (!builder_result) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto data = builder_result.release();
|
||||||
|
auto stmt = query::query::select(data.columns)
|
||||||
|
.from(*data.root_table)
|
||||||
|
.join_left(data.joins)
|
||||||
|
.where(std::move(data.where_clause))
|
||||||
|
.order_by({data.root_table, data.pk_column_name})
|
||||||
|
.asc()
|
||||||
|
.prepare(exec);
|
||||||
|
|
||||||
|
if (!stmt) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
return std::make_shared<query_object_resolver<Type>>(stmt.release());
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
||||||
|
|
@ -5,12 +5,12 @@
|
||||||
|
|
||||||
#include "matador/query/criteria.hpp"
|
#include "matador/query/criteria.hpp"
|
||||||
#include "matador/query/query.hpp"
|
#include "matador/query/query.hpp"
|
||||||
|
#include "matador/query/criteria/criteria_visitor.hpp"
|
||||||
|
|
||||||
#include "matador/sql/statement.hpp"
|
#include "matador/sql/statement.hpp"
|
||||||
|
|
||||||
#include "matador/object/join_columns_collector.hpp"
|
#include "matador/object/join_columns_collector.hpp"
|
||||||
#include "matador/object/repository.hpp"
|
#include "matador/object/repository.hpp"
|
||||||
#include "matador/query/criteria/criteria_visitor.hpp"
|
|
||||||
|
|
||||||
#include "matador/utils/primary_key_attribute.hpp"
|
#include "matador/utils/primary_key_attribute.hpp"
|
||||||
#include "matador/utils/result.hpp"
|
#include "matador/utils/result.hpp"
|
||||||
|
|
|
||||||
|
|
@ -151,7 +151,6 @@ add_library(matador-orm STATIC
|
||||||
query/query_builder.cpp
|
query/query_builder.cpp
|
||||||
query/query_builder_exception.cpp
|
query/query_builder_exception.cpp
|
||||||
query/query_collection_resolver.cpp
|
query/query_collection_resolver.cpp
|
||||||
query/query_object_resolver.cpp
|
|
||||||
query/query_part.cpp
|
query/query_part.cpp
|
||||||
query/query_utils.cpp
|
query/query_utils.cpp
|
||||||
query/schema.cpp
|
query/schema.cpp
|
||||||
|
|
|
||||||
|
|
@ -1,16 +0,0 @@
|
||||||
#include "matador/query/query_object_resolver.hpp"
|
|
||||||
|
|
||||||
#include "matador/query/criteria.hpp"
|
|
||||||
#include "matador/query/query.hpp"
|
|
||||||
|
|
||||||
namespace matador::query {
|
|
||||||
utils::result<sql::statement, utils::error> prepare_statement(sql::executor &exec, entity_query_data &&data) {
|
|
||||||
return query::query::select(data.columns)
|
|
||||||
.from(*data.root_table)
|
|
||||||
.join_left(data.joins)
|
|
||||||
.where(std::move(data.where_clause))
|
|
||||||
.order_by({data.root_table, data.pk_column_name})
|
|
||||||
.asc()
|
|
||||||
.prepare(exec);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -24,7 +24,8 @@ using namespace matador::query::meta;
|
||||||
class StatementTestFixture : public QueryFixture {
|
class StatementTestFixture : public QueryFixture {
|
||||||
public:
|
public:
|
||||||
StatementTestFixture() {
|
StatementTestFixture() {
|
||||||
REQUIRE(repo.attach<airplane>("airplanes"));
|
REQUIRE(repo.attach<airplane>("airplanes")
|
||||||
|
.and_then([this] {return repo.create(db); }));
|
||||||
repo.initialize_executor(db);
|
repo.initialize_executor(db);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -38,7 +39,6 @@ protected:
|
||||||
|
|
||||||
TEST_CASE_METHOD(StatementTestFixture, "Create prepared statement", "[statement]") {
|
TEST_CASE_METHOD(StatementTestFixture, "Create prepared statement", "[statement]") {
|
||||||
using namespace matador::utils;
|
using namespace matador::utils;
|
||||||
REQUIRE(repo.create(db));
|
|
||||||
SECTION("Insert with prepared statement and placeholder") {
|
SECTION("Insert with prepared statement and placeholder") {
|
||||||
auto stmt = query::insert()
|
auto stmt = query::insert()
|
||||||
.into(AIRPLANE, {AIRPLANE.id, AIRPLANE.brand, AIRPLANE.model})
|
.into(AIRPLANE, {AIRPLANE.id, AIRPLANE.brand, AIRPLANE.model})
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue