entity query builder progress
This commit is contained in:
@@ -22,7 +22,11 @@ struct column
|
||||
column(std::string table_name, std::string name, std::string as)
|
||||
: table(std::move(table_name))
|
||||
, name(std::move(name))
|
||||
, alias(std::move(as)) {} // NOLINT(*-explicit-constructor)
|
||||
, alias(std::move(as)) {}
|
||||
column(std::string table_name, const char* name, std::string as)
|
||||
: table(std::move(table_name))
|
||||
, name(name)
|
||||
, alias(std::move(as)) {}
|
||||
|
||||
column& as(std::string a) {
|
||||
alias = std::move(a);
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
#ifndef QUERY_ENTITY_QUERY_BUILDER_HPP
|
||||
#define QUERY_ENTITY_QUERY_BUILDER_HPP
|
||||
|
||||
#include "matador/sql/connection.hpp"
|
||||
#include "matador/sql/query_context.hpp"
|
||||
#include "matador/sql/query.hpp"
|
||||
#include "matador/sql/query_intermediates.hpp"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
namespace matador::sql {
|
||||
|
||||
@@ -9,43 +14,78 @@ template < typename PrimaryKeyType >
|
||||
class entity_query_builder
|
||||
{
|
||||
public:
|
||||
explicit entity_query_builder(const PrimaryKeyType &pk)
|
||||
: pk_(pk) {}
|
||||
|
||||
// determine pk
|
||||
// collect eager relations for joins
|
||||
template<class EntityType>
|
||||
query_context build() {
|
||||
std::optional<query_context> build(connection &db, const schema &scm) {
|
||||
EntityType obj;
|
||||
matador::utils::access::process(*this, obj);
|
||||
return {};
|
||||
|
||||
const auto info = scm.info<EntityType>();
|
||||
if (!info) {
|
||||
return std::nullopt;
|
||||
}
|
||||
columns_.clear();
|
||||
table_name_ = info.value().name;
|
||||
query q(db, scm);
|
||||
return q.select<EntityType>().from({table_name_}).build();
|
||||
// auto from_intermediate = q.select<EntityType>().from({"t"});
|
||||
// return {};
|
||||
}
|
||||
|
||||
template < class V >
|
||||
void on_primary_key(const char *id, V &, typename std::enable_if<std::is_integral<V>::value && !std::is_same<bool, V>::value>::type* = 0)
|
||||
{
|
||||
auto b = std::is_integral_v<PrimaryKeyType>;
|
||||
std::cout << "is matching primary key: " << std::boolalpha << b << "\n";
|
||||
columns_.emplace_back(table_name_, id, "");
|
||||
}
|
||||
|
||||
void on_primary_key(const char *id, std::string &, size_t)
|
||||
{
|
||||
auto b = std::is_same_v<PrimaryKeyType, std::string>;
|
||||
std::cout << "is matching primary key: " << std::boolalpha << b << "\n";
|
||||
columns_.emplace_back(table_name_, id, "");
|
||||
}
|
||||
|
||||
void on_revision(const char *id, unsigned long long &/*rev*/)
|
||||
{
|
||||
columns_.emplace_back(table_name_, id, "");
|
||||
}
|
||||
void on_revision(const char * /*id*/, unsigned long long &/*rev*/) {}
|
||||
|
||||
template<typename Type>
|
||||
void on_attribute(const char * /*id*/, Type &, const utils::field_attributes &/*attr*/ = utils::null_attributes) {}
|
||||
void on_attribute(const char *id, Type &, const utils::field_attributes &/*attr*/ = utils::null_attributes)
|
||||
{
|
||||
columns_.emplace_back(table_name_, id, "");
|
||||
}
|
||||
|
||||
template<class Pointer>
|
||||
void on_belongs_to(const char *id, Pointer &, const utils::foreign_attributes &/*attr*/)
|
||||
void on_belongs_to(const char *id, Pointer &, const utils::foreign_attributes &attr)
|
||||
{
|
||||
if (attr.fetch() == utils::fetch_type::EAGER) {
|
||||
// collect join information
|
||||
}
|
||||
columns_.emplace_back(table_name_, id, "");
|
||||
}
|
||||
|
||||
template<class Pointer>
|
||||
void on_has_one(const char *id, Pointer &, const utils::foreign_attributes &attr)
|
||||
{
|
||||
|
||||
if (attr.fetch() == utils::fetch_type::EAGER) {
|
||||
// collect join information
|
||||
}
|
||||
columns_.emplace_back(table_name_, id, "");
|
||||
}
|
||||
|
||||
template<class ContainerType>
|
||||
void on_has_many(const char *, ContainerType &, const char *, const char *, const utils::foreign_attributes &attr)
|
||||
{
|
||||
if (attr.fetch() == utils::fetch_type::EAGER) {
|
||||
// collect join information
|
||||
}
|
||||
}
|
||||
|
||||
template<class ContainerType>
|
||||
@@ -56,6 +96,8 @@ public:
|
||||
|
||||
private:
|
||||
PrimaryKeyType pk_;
|
||||
std::vector<column> columns_;
|
||||
std::string table_name_;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user