criteria progress

This commit is contained in:
Sascha Kühl
2026-01-21 16:08:27 +01:00
parent ac514c3765
commit 328d164c05
58 changed files with 230 additions and 82 deletions
+2 -2
View File
@@ -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_;
};
}
+7 -7
View File
@@ -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,16 +1,17 @@
#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:
query_intermediate();
query_intermediate(const std::shared_ptr<query_data> &context); // NOLINT(*-explicit-constructor)
query_intermediate(const std::shared_ptr<query_data> &context); // NOLINT(*-explicit-constructor)
protected:
std::shared_ptr<query_data> context_;
@@ -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
+1
View File
@@ -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;
+1 -1
View File
@@ -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;