criteria progress
This commit is contained in:
parent
ac514c3765
commit
328d164c05
|
|
@ -0,0 +1,2 @@
|
|||
# Generated by CLion for Google
|
||||
BasedOnStyle: Google
|
||||
|
|
@ -48,7 +48,7 @@ using namespace work::models;
|
|||
//
|
||||
// If all checks succeed, the requested is fetched from
|
||||
// the database.
|
||||
// schema.attach<jobs::Payload>("payloads", make_polymorph("type"));
|
||||
// schema.attach_as_base<jobs::Payload>("payloads", make_polymorph("type"));
|
||||
// schema.attach<jobs::Payload, jobs::IdPayload>("id_list_payloads", make_polymorph_type("IdPayload"));
|
||||
// schema.attach<jobs::Payload, jobs::IdListPayload>("id_payloads", make_polymorph_type("IdListPayload"));
|
||||
// object::object_ptr<jobs::Payload> payload;
|
||||
|
|
@ -66,7 +66,7 @@ int main() {
|
|||
logger::add_log_sink(logger::create_stdout_sink());
|
||||
|
||||
// sql::connection_pool<sql::connection> pool("postgres://news:news@127.0.0.1:15432/matador", 4);
|
||||
sql::connection_pool pool("postgres://test:test123!@127.0.0.1:5432/matador", 4);
|
||||
sql::connection_pool pool("postgres://test:test123!@127.0.0.1:15442/matador", 4);
|
||||
|
||||
utils::message_bus bus;
|
||||
// query::schema ses({bus, pool});
|
||||
|
|
@ -97,26 +97,72 @@ int main() {
|
|||
}
|
||||
|
||||
const auto conn = pool.acquire();
|
||||
result = admin_schema.create(*conn);
|
||||
if (!result) {
|
||||
std::cout << "error: " << result.err() << std::endl;
|
||||
return 0;
|
||||
}
|
||||
result = admin_schema.drop(*conn);
|
||||
if (!result) {
|
||||
std::cout << "error: " << result.err() << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// const std::string dns{"sqlite://demo.db"};
|
||||
// sql::connection c(dns);
|
||||
//
|
||||
// result = c.open();
|
||||
//
|
||||
// // orm::session s()
|
||||
// if (!result.is_ok()) {
|
||||
// result = admin_schema.create(*conn);
|
||||
// if (!result) {
|
||||
// std::cout << "error: " << result.err() << std::endl;
|
||||
// return 0;
|
||||
// }
|
||||
// result = admin_schema.drop(*conn);
|
||||
// if (!result) {
|
||||
// std::cout << "error: " << result.err() << std::endl;
|
||||
// return 0;
|
||||
// }
|
||||
|
||||
/*
|
||||
* const auto statement = QString( "SELECT %5.%6, %1.%2 FROM %3 %1, %4 %5 WHERE %1.%2=%5.%6 AND %7" )
|
||||
.arg( payloadTableAliasName,
|
||||
payloadSqlMetaInfo.columnName( Payload::Attributes::idAttributeId() ),
|
||||
Payload::staticSqlMetaInfo().tableName(),
|
||||
Task::staticSqlMetaInfo().tableName(),
|
||||
taskTableAliasName,
|
||||
taskSqlMetaInfo.columnName( Task::Attributes::payloadAttributeId() ),
|
||||
filter->idSelectStatement( taskTableAliasName ) );
|
||||
*/
|
||||
|
||||
using namespace matador::query::meta;
|
||||
using namespace matador::utils;
|
||||
const auto payloads = PAYLOAD.as( "payloads" );
|
||||
const auto tasks = TASK.as( "tasks" );
|
||||
const auto stmt1 = query:: query::select( { tasks.payload, payloads.id } )
|
||||
.from( tasks, payloads )
|
||||
.where ( payloads.id == tasks.payload )
|
||||
.str( conn->dialect() );
|
||||
|
||||
|
||||
/*
|
||||
const auto temporaryTable = status.addChildExc( fillTemporaryTable( idsInsidePayload ) );
|
||||
const auto lookUpTableName = temporaryTable->tableName();
|
||||
|
||||
const auto& jobSqlMetaInfo = Job::staticSqlMetaInfo();
|
||||
const auto& payloadSqlMetaInfo = Payload::staticSqlMetaInfo();
|
||||
const auto& idPayloadSqlMetaInfo = IdPayload::staticSqlMetaInfo();
|
||||
|
||||
const auto statement = QString( "SELECT iPT.%1 FROM %2 iPT INNER JOIN %3 pT ON iPT.%4 = pT.%5 WHERE pT.%5 IN (SELECT %6 FROM %7 WHERE %8=?) AND iPT.%1 IN (SELECT %9 FROM %10)" )
|
||||
.arg( idPayloadSqlMetaInfo.columnName( IdPayload::Attributes::payloadIdAttributeId() ) ) // %1
|
||||
.arg( idPayloadSqlMetaInfo.tableName() ) // %2
|
||||
.arg( payloadSqlMetaInfo.tableName() ) // %3
|
||||
.arg( idPayloadSqlMetaInfo.columnName( IdPayload::Attributes::idAttributeId() ) ) // %4
|
||||
.arg( payloadSqlMetaInfo.columnName( Payload::Attributes::idAttributeId() ) ) // %5
|
||||
.arg( jobSqlMetaInfo.columnName( Job::Attributes::payloadAttributeId() ) ) // %6
|
||||
.arg( jobSqlMetaInfo.tableName() ) // %7
|
||||
.arg( jobSqlMetaInfo.columnName( Job::Attributes::stateSqlAttributeId() ) ) // %8
|
||||
.arg( lookUpColName() ) // %9
|
||||
.arg( lookUpTableName ); // %10
|
||||
*/
|
||||
|
||||
query::table_column temp_id_col("ID");
|
||||
query::table temporary("TempTable", { temp_id_col } );
|
||||
|
||||
const auto iPT = ID_PAYLOAD.as("iPT");
|
||||
const auto pT = PAYLOAD.as("pT");
|
||||
|
||||
const auto stmt2 = query::query::select({ iPT.payload_id })
|
||||
.from( iPT )
|
||||
.join_left( pT ).on( iPT.id == pT.id )
|
||||
.where(
|
||||
in( pT.id, query::query::select({ JOB.payload }).from( JOB ).where( JOB.state == _) ) &&
|
||||
in( iPT.payload_id, query::query::select({ temp_id_col }).from( temporary ) )
|
||||
)
|
||||
.str( conn->dialect() );
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
namespace work::core {
|
||||
struct Model {
|
||||
uint64_t id{};
|
||||
int64_t id{};
|
||||
uint64_t version{};
|
||||
|
||||
template<typename Operator>
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@
|
|||
|
||||
#include "matador/object/collection.hpp"
|
||||
|
||||
#include "matador/query/meta_table_macro.hpp"
|
||||
|
||||
#include "matador/utils/foreign_attributes.hpp"
|
||||
|
||||
namespace work::models::jobs {
|
||||
|
|
@ -19,4 +21,6 @@ struct IdListPayload : Payload {
|
|||
};
|
||||
}
|
||||
|
||||
META_TABLE(id_list_payloads, ID_LIST_PAYLOAD, id, version, type, job)
|
||||
|
||||
#endif //ID_LIST_PAYLOAD_HPP
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@
|
|||
|
||||
#include "Payload.hpp"
|
||||
|
||||
#include "matador/query/meta_table_macro.hpp"
|
||||
|
||||
namespace work::models::jobs {
|
||||
struct IdPayload : Payload {
|
||||
uint64_t payload_id{};
|
||||
|
|
@ -15,4 +17,6 @@ struct IdPayload : Payload {
|
|||
};
|
||||
}
|
||||
|
||||
META_TABLE(id_payloads, ID_PAYLOAD, id, version, type, job, payload_id)
|
||||
|
||||
#endif //ID_PAYLOAD_HPP
|
||||
|
|
|
|||
|
|
@ -11,6 +11,8 @@
|
|||
|
||||
#include "matador/object/object_ptr.hpp"
|
||||
|
||||
#include "matador/query/meta_table_macro.hpp"
|
||||
|
||||
#include "matador/utils/base_class.hpp"
|
||||
#include "matador/utils/foreign_attributes.hpp"
|
||||
|
||||
|
|
@ -43,4 +45,6 @@ struct Job : core::Model {
|
|||
|
||||
}
|
||||
|
||||
META_TABLE(jobs, JOB, id, version, name, description, state, mode, created_at, payload, task, user_info)
|
||||
|
||||
#endif //JOB_HPP
|
||||
|
|
|
|||
|
|
@ -3,14 +3,16 @@
|
|||
|
||||
#include "../core/Model.hpp"
|
||||
|
||||
#include "matador/query/meta_table_macro.hpp"
|
||||
|
||||
#include "matador/utils/base_class.hpp"
|
||||
#include "matador/utils/foreign_attributes.hpp"
|
||||
|
||||
namespace work::models::jobs {
|
||||
struct Job;
|
||||
struct Payload : core::Model {
|
||||
std::string type;
|
||||
matador::object::object_ptr<Job> job;
|
||||
std::string type{};
|
||||
matador::object::object_ptr<Job> job{};
|
||||
|
||||
template<typename Operator>
|
||||
void process( Operator& op ) {
|
||||
|
|
@ -22,4 +24,6 @@ struct Payload : core::Model {
|
|||
};
|
||||
}
|
||||
|
||||
META_TABLE(payloads, PAYLOAD, id, version, type, job)
|
||||
|
||||
#endif //PAYLOAD_HPP
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@
|
|||
|
||||
#include "matador/object/object_ptr.hpp"
|
||||
|
||||
#include "matador/query/meta_table_macro.hpp"
|
||||
|
||||
#include "matador/utils/base_class.hpp"
|
||||
#include "matador/utils/foreign_attributes.hpp"
|
||||
|
||||
|
|
@ -39,4 +41,6 @@ struct Task : core::Model {
|
|||
};
|
||||
}
|
||||
|
||||
META_TABLE(tasks, TASK, id, version, name, description, job_name, state, payload, job_mode, start_delay, interval, user_session_id)
|
||||
|
||||
#endif //TASK_HPP
|
||||
|
|
|
|||
|
|
@ -40,12 +40,12 @@ public:
|
|||
return proxy_->items_.empty();
|
||||
}
|
||||
|
||||
void reset(std::shared_ptr<collection_proxy<typename Type::value_type>> proxy) {
|
||||
void reset(std::shared_ptr<collection_proxy<Type>> proxy) {
|
||||
proxy_ = std::move(proxy);
|
||||
}
|
||||
|
||||
private:
|
||||
std::shared_ptr<collection_proxy<typename Type::value_type>> proxy_;
|
||||
std::shared_ptr<collection_proxy<Type>> proxy_;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,22 +36,22 @@ public:
|
|||
template<typename Type>
|
||||
class collection_proxy final {
|
||||
public:
|
||||
collection_proxy(std::weak_ptr<object_resolver<Type>> resolver, utils::identifier owner_id)
|
||||
collection_proxy(std::weak_ptr<object_resolver<typename Type::value_type>> resolver, utils::identifier owner_id)
|
||||
: owner_id_(std::move(owner_id)), resolver_(std::move(resolver)) {}
|
||||
|
||||
collection_proxy(std::weak_ptr<object_resolver<Type>> resolver, std::vector<object_ptr<Type>> items)
|
||||
collection_proxy(std::weak_ptr<object_resolver<typename Type::value_type>> resolver, std::vector<Type> items)
|
||||
: items_(std::move(items)), resolver_(std::move(resolver)) {}
|
||||
|
||||
explicit collection_proxy(std::vector<object_ptr<Type>> items)
|
||||
explicit collection_proxy(std::vector<Type> items)
|
||||
: items_(std::move(items)) {}
|
||||
|
||||
[[nodiscard]] const utils::identifier& owner_id() const {
|
||||
return owner_id_;
|
||||
}
|
||||
const std::vector<object_ptr<Type>>& items() const {
|
||||
const std::vector<Type>& items() const {
|
||||
return items_;
|
||||
}
|
||||
std::vector<object_ptr<Type>>& items() {
|
||||
std::vector<Type>& items() {
|
||||
return items_;
|
||||
}
|
||||
private:
|
||||
|
|
@ -74,8 +74,8 @@ private:
|
|||
private:
|
||||
const utils::identifier owner_id_;
|
||||
std::atomic_bool loaded_{false};
|
||||
std::vector<object_ptr<Type>> items_;
|
||||
std::weak_ptr<object_resolver<Type>> resolver_{};
|
||||
std::vector<Type> items_;
|
||||
std::weak_ptr<object_resolver<typename Type::value_type>> resolver_{};
|
||||
mutable std::mutex mutex_{};
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,8 +3,8 @@
|
|||
|
||||
#include "matador/query/criteria/abstract_column_criteria.hpp"
|
||||
#include "matador/query/criteria/criteria_utils.hpp"
|
||||
|
||||
#include "matador/query/table_column.hpp"
|
||||
#include "matador/query/intermediates/fetchable_query.hpp"
|
||||
|
||||
namespace matador::query {
|
||||
enum class binary_operator {
|
||||
|
|
@ -34,7 +34,7 @@ private:
|
|||
class binary_column_criteria final : public abstract_criteria {
|
||||
public:
|
||||
binary_column_criteria() = delete;
|
||||
binary_column_criteria(const table_column& left_column, binary_operator operand, const table_column& right_column);
|
||||
binary_column_criteria(table_column left_column, binary_operator operand, table_column right_column);
|
||||
|
||||
void accept(criteria_visitor& visitor) const override;
|
||||
|
||||
|
|
|
|||
|
|
@ -3,8 +3,9 @@
|
|||
|
||||
#include "matador/query/criteria/abstract_column_criteria.hpp"
|
||||
#include "matador/query/criteria/criteria_utils.hpp"
|
||||
|
||||
#include "matador/query/intermediates/fetchable_query.hpp"
|
||||
#include "matador/query/table.hpp"
|
||||
|
||||
#include "matador/sql/query_context.hpp"
|
||||
|
||||
namespace matador::query {
|
||||
|
|
@ -54,16 +55,16 @@ private:
|
|||
class collection_query_criteria final : public abstract_column_criteria {
|
||||
public:
|
||||
collection_query_criteria() = delete;
|
||||
collection_query_criteria(const table_column& col, collection_operator operand_, sql::query_context ctx);
|
||||
collection_query_criteria(const table_column& col, collection_operator operand_, fetchable_query ctx);
|
||||
|
||||
void accept(criteria_visitor& visitor) const override;
|
||||
|
||||
[[nodiscard]] collection_operator operand() const;
|
||||
[[nodiscard]] const sql::query_context& context() const;
|
||||
[[nodiscard]] const fetchable_query& query() const;
|
||||
|
||||
private:
|
||||
collection_operator operand_;
|
||||
sql::query_context query_context_;
|
||||
fetchable_query query_context_;
|
||||
};
|
||||
}
|
||||
#endif //CRITERIA_COLLECTION_CRITERIA_NODE_HPP
|
||||
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include "matador/query/criteria/binary_criteria.hpp"
|
||||
#include "matador/query/criteria/collection_criteria.hpp"
|
||||
#include "matador/query/intermediates/fetchable_query.hpp"
|
||||
|
||||
#include "matador/utils/placeholder.hpp"
|
||||
#include "matador/utils/value.hpp"
|
||||
|
|
@ -17,12 +18,14 @@ namespace matador::query {
|
|||
class table_column;
|
||||
|
||||
template<class Type>
|
||||
criteria_ptr operator==(const table_column &col, Type val) {
|
||||
std::enable_if_t<!std::is_base_of_v<fetchable_query, std::decay_t<Type>>, criteria_ptr>
|
||||
operator==(const table_column &col, Type val) {
|
||||
return std::make_unique<binary_criteria>(col, binary_operator::EQUALS, utils::value(val));
|
||||
}
|
||||
|
||||
template<class Type>
|
||||
criteria_ptr operator!=(const table_column &col, Type val) {
|
||||
std::enable_if_t<!std::is_base_of_v<fetchable_query, std::decay_t<Type>>, criteria_ptr>
|
||||
operator!=(const table_column &col, Type val) {
|
||||
return std::make_unique<binary_criteria>(col, binary_operator::NOT_EQUALS, utils::value(val));
|
||||
}
|
||||
|
||||
|
|
@ -81,7 +84,7 @@ criteria_ptr in(const table_column &col, std::initializer_list<Type> args) {
|
|||
template <>
|
||||
criteria_ptr in(const table_column &col, std::initializer_list<utils::placeholder> args);
|
||||
|
||||
criteria_ptr in(const table_column &col, sql::query_context &&ctx);
|
||||
criteria_ptr in(const table_column &col, fetchable_query &&q);
|
||||
|
||||
template < class Type >
|
||||
criteria_ptr out(const table_column &col, std::initializer_list<Type> args) {
|
||||
|
|
@ -94,8 +97,7 @@ criteria_ptr out(const table_column &col, std::initializer_list<Type> args) {
|
|||
|
||||
template <>
|
||||
criteria_ptr out(const table_column &col, std::initializer_list<utils::placeholder> args);
|
||||
|
||||
criteria_ptr out(const table_column &col, sql::query_context &&ctx);
|
||||
criteria_ptr out(const table_column &col, fetchable_query &&q);
|
||||
|
||||
criteria_ptr between(const table_column &col, int64_t min, int64_t max);
|
||||
criteria_ptr between(const table_column &col, utils::placeholder min, utils::placeholder max);
|
||||
|
|
|
|||
|
|
@ -1,11 +1,9 @@
|
|||
#ifndef FETCHABLE_QUERY_HPP
|
||||
#define FETCHABLE_QUERY_HPP
|
||||
|
||||
#include "query_intermediate.hpp"
|
||||
#include "matador/query/intermediates/query_intermediate.hpp"
|
||||
|
||||
#include "matador/query/query_compiler.hpp"
|
||||
#include "matador/sql/executor.hpp"
|
||||
|
||||
#include "matador/sql/query_result.hpp"
|
||||
#include "matador/sql/query_record_result.hpp"
|
||||
#include "matador/sql/record.hpp"
|
||||
|
|
@ -81,6 +79,7 @@ public:
|
|||
[[nodiscard]] utils::result<sql::statement, utils::error> prepare(sql::executor &exec) const;
|
||||
|
||||
[[nodiscard]] std::string str(const sql::executor &exec) const;
|
||||
[[nodiscard]] std::string str(const sql::dialect &d) const;
|
||||
[[nodiscard]] sql::query_context compile(const sql::dialect &d) const;
|
||||
|
||||
private:
|
||||
|
|
|
|||
|
|
@ -3,7 +3,8 @@
|
|||
|
||||
#include "matador/query/intermediates/executable_query.hpp"
|
||||
#include "matador/query/intermediates/query_intermediate.hpp"
|
||||
#include "matador/query/table_constraint.hpp"
|
||||
#include "matador/query/table_column.hpp"
|
||||
#include "matador/query/table.hpp"
|
||||
|
||||
#include "matador/object/restriction.hpp"
|
||||
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
#include "matador/query/intermediates/executable_query.hpp"
|
||||
|
||||
#include "matador/query/table_constraint.hpp"
|
||||
#include "matador/query/table_column.hpp"
|
||||
|
||||
#include "matador/object/attribute.hpp"
|
||||
#include "matador/object/restriction.hpp"
|
||||
|
|
@ -13,7 +14,7 @@
|
|||
#include <list>
|
||||
|
||||
namespace matador::query {
|
||||
|
||||
class table;
|
||||
class query_create_table_columns_intermediate : public executable_query {
|
||||
public:
|
||||
using executable_query::executable_query;
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@
|
|||
|
||||
#include "matador/query/intermediates/query_intermediate.hpp"
|
||||
|
||||
#include "matador/query/table.hpp"
|
||||
|
||||
namespace matador::query {
|
||||
|
||||
class query_delete_from_intermediate;
|
||||
|
|
|
|||
|
|
@ -4,13 +4,14 @@
|
|||
#include "matador/query/intermediates/executable_query.hpp"
|
||||
|
||||
namespace matador::query {
|
||||
class table;
|
||||
|
||||
class query_drop_intermediate : query_intermediate {
|
||||
public:
|
||||
query_drop_intermediate();
|
||||
|
||||
executable_query table(const table &tab);
|
||||
executable_query schema(const std::string &schema_name);
|
||||
// executable_query schema(const std::string &schema_name);
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
namespace matador::query {
|
||||
|
||||
class table_column;
|
||||
class query_execute_limit_intermediate;
|
||||
class query_execute_order_by_intermediate;
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
#define QUERY_GROUP_BY_INTERMEDIATE_HPP
|
||||
|
||||
#include "matador/query/intermediates/fetchable_query.hpp"
|
||||
#include "matador/query/table_column.hpp"
|
||||
|
||||
namespace matador::query {
|
||||
|
||||
|
|
|
|||
|
|
@ -1,11 +1,12 @@
|
|||
#ifndef QUERY_INTERMEDIATE_HPP
|
||||
#define QUERY_INTERMEDIATE_HPP
|
||||
|
||||
#include "matador/query/query_data.hpp"
|
||||
// #include "matador/query/query_data.hpp"
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace matador::query {
|
||||
struct query_data;
|
||||
|
||||
class query_intermediate {
|
||||
public:
|
||||
|
|
|
|||
|
|
@ -2,6 +2,11 @@
|
|||
#define QUERY_SELECT_INTERMEDIATE_HPP
|
||||
|
||||
#include "matador/query/intermediates/query_intermediate.hpp"
|
||||
#include "matador/query/intermediates/query_from_intermediate.hpp"
|
||||
|
||||
#include "matador/query/table_column.hpp"
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace matador::query {
|
||||
|
||||
|
|
@ -12,7 +17,14 @@ class query_select_intermediate : public query_intermediate
|
|||
public:
|
||||
explicit query_select_intermediate(const std::vector<table_column>& columns);
|
||||
|
||||
query_from_intermediate from(const table& t);
|
||||
template<typename... Tables>
|
||||
query_from_intermediate from(const Tables&... tables) {
|
||||
std::vector<table> v { tables... };
|
||||
return from(v);
|
||||
}
|
||||
|
||||
private:
|
||||
query_from_intermediate from(const std::vector<table>& tables);
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
#define QUERY_WHERE_INTERMEDIATE_HPP
|
||||
|
||||
#include "matador/query/intermediates/fetchable_query.hpp"
|
||||
#include "matador/query/table_column.hpp"
|
||||
|
||||
namespace matador::query {
|
||||
|
||||
|
|
|
|||
|
|
@ -132,15 +132,15 @@ private:
|
|||
class query_from_part final : public query_part
|
||||
{
|
||||
public:
|
||||
explicit query_from_part(class table tab);
|
||||
explicit query_from_part(std::vector<table> tables);
|
||||
|
||||
[[nodiscard]] const class table& table() const;
|
||||
[[nodiscard]] const std::vector<table>& tables() const;
|
||||
|
||||
private:
|
||||
void accept(query_part_visitor &visitor) override;
|
||||
|
||||
private:
|
||||
class table table_;
|
||||
std::vector<table> tables_;
|
||||
};
|
||||
|
||||
class query_join_part final : public query_part
|
||||
|
|
|
|||
|
|
@ -77,6 +77,7 @@ protected:
|
|||
void visit(internal::query_drop_schema_part& part) override;
|
||||
|
||||
static std::string build_table_name(sql::dialect_token token, const sql::dialect &d, const table& t);
|
||||
static std::string build_table_name(const sql::dialect &d, const table& t);
|
||||
static std::string determine_value(value_visitor &visitor, const std::variant<utils::placeholder, utils::database_type> &val);
|
||||
|
||||
[[nodiscard]] std::string build_add_constraint_string(const table_constraint& c) const;
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ private:
|
|||
|
||||
table operator ""_tab(const char *name, size_t len);
|
||||
|
||||
template<typename Type>
|
||||
template<typename Type = table>
|
||||
class typed_table : public table {
|
||||
public:
|
||||
using table::table;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,11 @@
|
|||
#include <utility>
|
||||
|
||||
#include "matador/query/criteria/binary_criteria.hpp"
|
||||
|
||||
#include "matador/query/criteria/criteria_visitor.hpp"
|
||||
|
||||
#include "matador/query/intermediates/fetchable_query.hpp"
|
||||
|
||||
namespace matador::query {
|
||||
binary_criteria::binary_criteria(const table_column& col, const binary_operator operand, criteria_value value)
|
||||
: abstract_column_criteria(col)
|
||||
|
|
@ -21,10 +25,10 @@ const criteria_value& binary_criteria::value() const {
|
|||
return value_;
|
||||
}
|
||||
|
||||
binary_column_criteria::binary_column_criteria(const table_column& left_column, const binary_operator operand, const table_column& right_column)
|
||||
: left_column_(left_column)
|
||||
binary_column_criteria::binary_column_criteria(table_column left_column, const binary_operator operand, table_column right_column)
|
||||
: left_column_(std::move(left_column))
|
||||
, operator_(operand)
|
||||
, right_column_(right_column){}
|
||||
, right_column_(std::move(right_column)){}
|
||||
|
||||
void binary_column_criteria::accept(criteria_visitor& visitor) const {
|
||||
visitor.visit(*this);
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ const std::vector<criteria_value>& collection_criteria::values() const {
|
|||
return values_;
|
||||
}
|
||||
|
||||
collection_query_criteria::collection_query_criteria(const table_column& col, collection_operator operand_, sql::query_context ctx)
|
||||
collection_query_criteria::collection_query_criteria(const table_column& col, const collection_operator operand_, fetchable_query ctx)
|
||||
: abstract_column_criteria(col)
|
||||
, operand_(operand_)
|
||||
, query_context_(std::move(ctx)){
|
||||
|
|
@ -42,7 +42,7 @@ collection_operator collection_query_criteria::operand() const {
|
|||
return operand_;
|
||||
}
|
||||
|
||||
const sql::query_context & collection_query_criteria::context() const {
|
||||
const fetchable_query& collection_query_criteria::query() const {
|
||||
return query_context_;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -90,8 +90,8 @@ criteria_ptr in(const table_column &col, const std::initializer_list<utils::plac
|
|||
return std::make_unique<collection_criteria>(col, collection_operator::In, std::move(values));
|
||||
}
|
||||
|
||||
criteria_ptr in(const table_column &col, sql::query_context &&ctx) {
|
||||
return std::make_unique<collection_query_criteria>(col, collection_operator::In, std::move(ctx));
|
||||
criteria_ptr in(const table_column &col, fetchable_query &&q) {
|
||||
return std::make_unique<collection_query_criteria>(col, collection_operator::In, std::move(q));
|
||||
}
|
||||
|
||||
template <>
|
||||
|
|
@ -103,8 +103,8 @@ criteria_ptr out(const table_column &col, const std::initializer_list<utils::pla
|
|||
return std::make_unique<collection_criteria>(col, collection_operator::Out, values);
|
||||
}
|
||||
|
||||
criteria_ptr out(const table_column &col, sql::query_context &&ctx) {
|
||||
return std::make_unique<collection_query_criteria>(col, collection_operator::In, std::move(ctx));
|
||||
criteria_ptr out(const table_column &col, fetchable_query &&q) {
|
||||
return std::make_unique<collection_query_criteria>(col, collection_operator::In, std::move(q));
|
||||
}
|
||||
|
||||
criteria_ptr between(const table_column &col, const int64_t min, const int64_t max) {
|
||||
|
|
|
|||
|
|
@ -88,7 +88,7 @@ void criteria_evaluator::visit(const collection_criteria &node) {
|
|||
void criteria_evaluator::visit(const collection_query_criteria &node) {
|
||||
clause_ += prepare_identifier(dialect_, node.col()) +
|
||||
(node.operand() == collection_operator::Out ? " " + dialect_.token_at(sql::dialect_token::Not) + " " : " ") +
|
||||
dialect_.token_at(sql::dialect_token::In) + " (" +node.context().sql + ")";
|
||||
dialect_.token_at(sql::dialect_token::In) + " (" + node.query().str( dialect_ ) + ")";
|
||||
}
|
||||
|
||||
void criteria_evaluator::visit(const like_criteria &node) {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
#include "matador/query/intermediates/fetchable_query.hpp"
|
||||
|
||||
#include "matador/query/query_compiler.hpp"
|
||||
|
||||
#include "matador/sql/executor.hpp"
|
||||
#include "matador/sql/field.hpp"
|
||||
#include "matador/sql/statement.hpp"
|
||||
|
|
@ -54,7 +56,10 @@ utils::result<std::optional<sql::record>, utils::error> fetchable_query::fetch_o
|
|||
}
|
||||
|
||||
std::string fetchable_query::str(const sql::executor &exec) const {
|
||||
return exec.str(compile(exec.dialect()));
|
||||
return str(exec.dialect());
|
||||
}
|
||||
std::string fetchable_query::str(const sql::dialect &d) const {
|
||||
return compile(d).sql;
|
||||
}
|
||||
|
||||
sql::query_context fetchable_query::compile(const sql::dialect &d) const {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
#include "matador/query/intermediates/query_alter_intermediate.hpp"
|
||||
|
||||
#include "matador/query/internal/query_parts.hpp"
|
||||
#include "matador/query/query_data.hpp"
|
||||
|
||||
namespace matador::query {
|
||||
query_alter_intermediate::query_alter_intermediate() {
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include "matador/object/object.hpp"
|
||||
#include "matador/query/internal/query_parts.hpp"
|
||||
#include "matador/query/query_data.hpp"
|
||||
|
||||
namespace matador::query {
|
||||
executable_query query_add_foreign_key_constraint_intermediate::references( const table& tab, const std::vector<table_column>& columns) {
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
#include "matador/query/intermediates/query_create_intermediate.hpp"
|
||||
|
||||
#include "matador/query/internal/query_parts.hpp"
|
||||
|
||||
#include "matador/query/table_constraint.hpp"
|
||||
#include "matador/query/query_data.hpp"
|
||||
|
||||
#include "matador/object/object.hpp"
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
#include "matador/query/intermediates/query_delete_from_intermediate.hpp"
|
||||
|
||||
#include "matador/query/internal/query_parts.hpp"
|
||||
#include "matador/query/query_data.hpp"
|
||||
|
||||
namespace matador::query {
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
#include "matador/query/intermediates/query_delete_from_intermediate.hpp"
|
||||
|
||||
#include "matador/query/internal/query_parts.hpp"
|
||||
#include "matador/query/query_data.hpp"
|
||||
|
||||
namespace matador::query {
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
#include "matador/query/internal/query_parts.hpp"
|
||||
|
||||
#include "matador/query/query_data.hpp"
|
||||
|
||||
namespace matador::query {
|
||||
|
||||
query_drop_intermediate::query_drop_intermediate() {
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
#include "matador/query/intermediates/query_execute_offset_intermediate.hpp"
|
||||
|
||||
#include "matador/query/internal/query_parts.hpp"
|
||||
#include "matador/query/query_data.hpp"
|
||||
|
||||
namespace matador::query {
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
#include "matador/query/intermediates/query_execute_limit_intermediate.hpp"
|
||||
|
||||
#include "matador/query/internal/query_parts.hpp"
|
||||
#include "matador/query/query_data.hpp"
|
||||
|
||||
namespace matador::query {
|
||||
query_execute_limit_intermediate query_execute_offset_intermediate::limit(size_t limit) {
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
#include "matador/query/intermediates/query_execute_order_direction_intermediate.hpp"
|
||||
|
||||
#include "matador/query/internal/query_parts.hpp"
|
||||
#include "matador/query/query_data.hpp"
|
||||
|
||||
namespace matador::query {
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
#include "matador/query/intermediates/query_execute_limit_intermediate.hpp"
|
||||
|
||||
#include "matador/query/internal/query_parts.hpp"
|
||||
#include "matador/query/query_data.hpp"
|
||||
|
||||
namespace matador::query {
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@
|
|||
|
||||
#include "matador/query/internal/query_parts.hpp"
|
||||
|
||||
#include "matador/query/query_data.hpp"
|
||||
|
||||
namespace matador::query {
|
||||
|
||||
query_execute_limit_intermediate query_execute_where_intermediate::limit(size_t limit) {
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
#include "matador/query/intermediates/query_order_by_intermediate.hpp"
|
||||
|
||||
#include "matador/query/internal/query_parts.hpp"
|
||||
#include "matador/query/query_data.hpp"
|
||||
|
||||
namespace matador::query {
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
#include "matador/query/intermediates/query_order_by_intermediate.hpp"
|
||||
|
||||
#include "matador/query/internal/query_parts.hpp"
|
||||
#include "matador/query/query_data.hpp"
|
||||
|
||||
namespace matador::query {
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
#include "matador/query/intermediates/query_into_intermediate.hpp"
|
||||
|
||||
#include "matador/query/internal/query_parts.hpp"
|
||||
#include "matador/query/query_data.hpp"
|
||||
|
||||
namespace matador::query {
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
#include "matador/query/intermediates/query_intermediate.hpp"
|
||||
|
||||
#include "matador/query/query_data.hpp"
|
||||
|
||||
namespace matador::query {
|
||||
|
||||
query_intermediate::query_intermediate()
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
#include "matador/query/intermediates/query_into_intermediate.hpp"
|
||||
|
||||
#include "matador/query/internal/query_parts.hpp"
|
||||
#include "matador/query/query_data.hpp"
|
||||
|
||||
namespace matador::query {
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
#include "matador/query/intermediates/query_join_intermediate.hpp"
|
||||
|
||||
#include "matador/query/internal/query_parts.hpp"
|
||||
#include "matador/query/query_data.hpp"
|
||||
|
||||
namespace matador::query {
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
#include "matador/query/intermediates/query_limit_intermediate.hpp"
|
||||
#include "matador/query/intermediates/query_offset_intermediate.hpp"
|
||||
#include "matador/query/internal/query_parts.hpp"
|
||||
#include "matador/query/query_data.hpp"
|
||||
|
||||
namespace matador::query {
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
#include "matador/query/intermediates/query_offset_intermediate.hpp"
|
||||
#include "matador/query/intermediates/query_limit_intermediate.hpp"
|
||||
#include "matador/query/internal/query_parts.hpp"
|
||||
#include "matador/query/query_data.hpp"
|
||||
|
||||
namespace matador::query {
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
#include "matador/query/intermediates/query_order_direction_intermediate.hpp"
|
||||
|
||||
#include "matador/query/internal/query_parts.hpp"
|
||||
#include "matador/query/query_data.hpp"
|
||||
|
||||
namespace matador::query {
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
#include "matador/query/intermediates/query_limit_intermediate.hpp"
|
||||
|
||||
#include "matador/query/internal/query_parts.hpp"
|
||||
#include "matador/query/query_data.hpp"
|
||||
|
||||
namespace matador::query {
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
#include "matador/query/intermediates/query_join_intermediate.hpp"
|
||||
|
||||
#include "matador/query/internal/query_parts.hpp"
|
||||
#include "matador/query/query_data.hpp"
|
||||
|
||||
namespace matador::query {
|
||||
|
||||
|
|
@ -10,10 +11,15 @@ query_select_intermediate::query_select_intermediate(const std::vector<table_col
|
|||
context_->parts.push_back(std::make_unique<internal::query_select_part>(columns));
|
||||
}
|
||||
|
||||
query_from_intermediate query_select_intermediate::from(const table& t) {
|
||||
context_->parts.push_back(std::make_unique<internal::query_from_part>(t));
|
||||
context_->tables.insert({t.name(), t});
|
||||
return {context_};
|
||||
// query_from_intermediate query_select_intermediate::from(const table& tab) {
|
||||
// return from(std::vector{tab});
|
||||
// }
|
||||
query_from_intermediate query_select_intermediate::from(const std::vector<table>& tables) {
|
||||
context_->parts.push_back(std::make_unique<internal::query_from_part>(tables));
|
||||
for (const auto& tab : tables) {
|
||||
context_->tables.insert({tab.name(), tab});
|
||||
}
|
||||
|
||||
return {context_};
|
||||
}
|
||||
} // namespace matador::query
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
#include "matador/query/intermediates/query_set_intermediate.hpp"
|
||||
|
||||
#include "matador/query/internal/query_parts.hpp"
|
||||
#include "matador/query/query_data.hpp"
|
||||
|
||||
namespace matador::query {
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
#include "matador/query/intermediates/query_update_intermediate.hpp"
|
||||
|
||||
#include "matador/query/internal/query_parts.hpp"
|
||||
#include "matador/query/query_data.hpp"
|
||||
|
||||
namespace matador::query {
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
#include "matador/query/intermediates/query_order_by_intermediate.hpp"
|
||||
|
||||
#include "matador/query/internal/query_parts.hpp"
|
||||
#include "matador/query/query_data.hpp"
|
||||
|
||||
namespace matador::query {
|
||||
query_group_by_intermediate query_where_intermediate::group_by(const table_column &column) {
|
||||
|
|
|
|||
|
|
@ -134,13 +134,13 @@ const std::vector<table_column> &query_select_part::columns() const {
|
|||
return columns_;
|
||||
}
|
||||
|
||||
query_from_part::query_from_part(class table tab)
|
||||
query_from_part::query_from_part(std::vector<table> tables)
|
||||
: query_part(sql::dialect_token::From)
|
||||
, table_(std::move(tab)) {
|
||||
, tables_(std::move(tables)) {
|
||||
}
|
||||
|
||||
const table &query_from_part::table() const {
|
||||
return table_;
|
||||
const std::vector<table> &query_from_part::tables() const {
|
||||
return tables_;
|
||||
}
|
||||
|
||||
void query_from_part::accept(query_part_visitor &visitor) {
|
||||
|
|
|
|||
|
|
@ -158,8 +158,20 @@ void query_compiler::visit(internal::query_select_part &part) {
|
|||
}
|
||||
|
||||
void query_compiler::visit(internal::query_from_part &part) {
|
||||
query_.table_name = part.table().name();
|
||||
query_.sql += " " + build_table_name(part.token(), *dialect_, part.table());
|
||||
query_.table_name = part.tables().front().name();
|
||||
query_.sql += " " + dialect_->from() + " ";
|
||||
if (const auto &tables = part.tables(); tables.size() < 2) {
|
||||
for (const auto &tab: tables) {
|
||||
query_.sql += build_table_name(*dialect_, tab);
|
||||
}
|
||||
} else {
|
||||
auto it = tables.begin();
|
||||
query_.sql.append(build_table_name(*dialect_, *it++));
|
||||
for (; it != tables.end(); ++it) {
|
||||
query_.sql.append(", ");
|
||||
query_.sql.append(build_table_name(*dialect_, *it));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void query_compiler::visit(internal::query_join_part &part) {
|
||||
|
|
@ -456,8 +468,11 @@ std::string build_constraint(const table_constraint& cons, const sql::dialect& d
|
|||
}
|
||||
|
||||
std::string query_compiler::build_table_name(const sql::dialect_token token, const sql::dialect &d, const table& t) {
|
||||
return d.token_at(token) + " " +
|
||||
(!d.default_schema_name().empty() ? d.prepare_identifier_string(d.default_schema_name()) + "." : "") +
|
||||
return d.token_at(token) + " " + build_table_name(d, t);
|
||||
}
|
||||
|
||||
std::string query_compiler::build_table_name(const sql::dialect &d, const table& t) {
|
||||
return (!d.default_schema_name().empty() ? d.prepare_identifier_string(d.default_schema_name()) + "." : "") +
|
||||
d.prepare_identifier_string(t.table_name()) +
|
||||
(!t.has_alias() ? "" : " " + d.prepare_identifier_string(t.name()));
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue