fixed PostgreSQL tests
This commit is contained in:
@@ -137,7 +137,7 @@ template<typename ValueType>
|
||||
void object_generator::on_primary_key(const char *id, ValueType &x, const utils::primary_key_attribute& attr) {
|
||||
auto &ref = emplace_attribute<ValueType>(id, { attr.size(), utils::constraints::PrimaryKey }, null_option_type::NotNull);
|
||||
prepare_primary_key(ref, utils::identifier(x));
|
||||
create_pk_constraint(id);
|
||||
// create_pk_constraint(id);
|
||||
}
|
||||
|
||||
template<typename Type>
|
||||
|
||||
@@ -84,15 +84,7 @@ private:
|
||||
};
|
||||
class session final : public sql::executor {
|
||||
public:
|
||||
explicit session(session_context &&ctx);
|
||||
|
||||
template<typename Type>
|
||||
[[nodiscard]] utils::result<void, utils::error> attach(const std::string &table_name) const;
|
||||
template<typename Type, typename SuperType>
|
||||
[[nodiscard]] utils::result<void, utils::error> attach(const std::string &table_name) const;
|
||||
|
||||
utils::result<void, utils::error> create_schema() const;
|
||||
utils::result<void, utils::error> drop_schema() const;
|
||||
session(session_context &&ctx, const query::schema &scm);
|
||||
|
||||
/**
|
||||
* Insert the given object into the session.
|
||||
@@ -138,35 +130,24 @@ private:
|
||||
friend class query_select;
|
||||
|
||||
static query::fetchable_query build_select_query(entity_query_data &&data);
|
||||
static sql::query_context build_add_constraint_context(const std::string& table_name, const class object::restriction& cons, const sql::connection_ptr &conn) ;
|
||||
|
||||
private:
|
||||
mutable sql::statement_cache cache_;
|
||||
const sql::dialect &dialect_;
|
||||
|
||||
std::unique_ptr<query::schema> schema_;
|
||||
const query::schema& schema_;
|
||||
mutable std::unordered_map<std::string, std::vector<object::attribute>> prototypes_;
|
||||
};
|
||||
|
||||
template<typename Type>
|
||||
[[nodiscard]] utils::result<void, utils::error> session::attach(const std::string &table_name) const {
|
||||
return schema_->attach<Type>(table_name);
|
||||
}
|
||||
|
||||
template<typename Type, typename SuperType>
|
||||
utils::result<void, utils::error> session::attach( const std::string& table_name ) const {
|
||||
return schema_->attach<Type, SuperType>(table_name);
|
||||
}
|
||||
|
||||
template<typename Type>
|
||||
utils::result<object::object_ptr<Type>, utils::error> session::insert(Type *obj) {
|
||||
auto info = schema_->repo().info<Type>();
|
||||
auto info = schema_.repo().info<Type>();
|
||||
if (!info) {
|
||||
return utils::failure(info.err());
|
||||
}
|
||||
|
||||
auto res = query::query::insert()
|
||||
.into(info->get().name(), query::generator::columns<Type>(*schema_))
|
||||
.into(info->get().name(), query::generator::columns<Type>(schema_))
|
||||
.values(query::generator::placeholders<Type>())
|
||||
.prepare(*this);
|
||||
if (!res) {
|
||||
@@ -233,7 +214,7 @@ private:
|
||||
|
||||
template<typename Type>
|
||||
utils::result<object::object_ptr<Type>, utils::error> session::update( const object::object_ptr<Type>& obj ) {
|
||||
auto info = schema_->repo().info<Type>();
|
||||
auto info = schema_.repo().info<Type>();
|
||||
if (!info) {
|
||||
return utils::failure(info.err());
|
||||
}
|
||||
@@ -259,7 +240,7 @@ utils::result<object::object_ptr<Type>, utils::error> session::update( const obj
|
||||
|
||||
template<typename Type>
|
||||
utils::result<void, utils::error> session::remove( const object::object_ptr<Type>& obj ) {
|
||||
auto info = schema_->repo().info<Type>();
|
||||
auto info = schema_.repo().info<Type>();
|
||||
if (!info) {
|
||||
return utils::failure(info.err());
|
||||
}
|
||||
@@ -284,8 +265,8 @@ utils::result<void, utils::error> session::remove( const object::object_ptr<Type
|
||||
|
||||
template<typename Type, typename PrimaryKeyType>
|
||||
utils::result<object::object_ptr<Type>, utils::error> session::find(const PrimaryKeyType& pk) {
|
||||
const auto it = schema_->find(typeid(Type));
|
||||
if (it == schema_->end()) {
|
||||
const auto it = schema_.find(typeid(Type));
|
||||
if (it == schema_.end()) {
|
||||
return utils::failure(make_error(error_code::UnknownType, "Failed to determine requested type."));
|
||||
}
|
||||
const auto& info = it->second.node().info();
|
||||
@@ -296,7 +277,7 @@ utils::result<object::object_ptr<Type>, utils::error> session::find(const Primar
|
||||
return utils::failure(make_error(error_code::NoPrimaryKey, "Type hasn't primary key."));
|
||||
}
|
||||
|
||||
session_query_builder eqb(*schema_, *this);
|
||||
session_query_builder eqb(schema_, *this);
|
||||
const query::table_column c(&it->second.table(),info.primary_key_attribute()->name());
|
||||
using namespace matador::query;
|
||||
auto data = eqb.build<Type>(c == utils::_);
|
||||
@@ -318,12 +299,12 @@ utils::result<object::object_ptr<Type>, utils::error> session::find(const Primar
|
||||
|
||||
template<typename Type>
|
||||
utils::result<sql::query_result<Type>, utils::error> session::find(query::criteria_ptr clause) {
|
||||
auto info = schema_->repo().info<Type>();
|
||||
auto info = schema_.repo().info<Type>();
|
||||
if (!info) {
|
||||
return utils::failure(make_error(error_code::UnknownType, "Failed to determine requested type."));
|
||||
}
|
||||
|
||||
session_query_builder eqb(*schema_, *this);
|
||||
session_query_builder eqb(schema_, *this);
|
||||
auto data = eqb.build<Type>(std::move(clause));
|
||||
if (!data.is_ok()) {
|
||||
return utils::failure(make_error(error_code::FailedToBuildQuery, "Failed to build query for type " + info->get().name() + "."));
|
||||
@@ -339,7 +320,7 @@ utils::result<sql::query_result<Type>, utils::error> session::find(query::criter
|
||||
|
||||
template<typename Type>
|
||||
utils::result<void, utils::error> session::drop_table() {
|
||||
auto info = schema_->repo().info<Type>();
|
||||
auto info = schema_.repo().info<Type>();
|
||||
if (info) {
|
||||
return drop_table(info->get().name());
|
||||
}
|
||||
|
||||
@@ -13,10 +13,13 @@
|
||||
#define META_TABLE(TABLE_NAME, VARIABLE_NAME, ...) \
|
||||
namespace matador::query::meta { \
|
||||
namespace internal { \
|
||||
class TABLE_NAME##_table : public table { \
|
||||
class TABLE_NAME##_table : public typed_table<TABLE_NAME##_table> { \
|
||||
public: \
|
||||
TABLE_NAME##_table() \
|
||||
: table(#TABLE_NAME, {MAP(FIELD_STRING, __VA_ARGS__)}) \
|
||||
TABLE_NAME##_table()\
|
||||
: TABLE_NAME##_table("") \
|
||||
{} \
|
||||
TABLE_NAME##_table(const std::string& alias) \
|
||||
: typed_table(#TABLE_NAME, alias, {MAP(FIELD_STRING, __VA_ARGS__)}) \
|
||||
MAP(INIT_FIELD, __VA_ARGS__) \
|
||||
{} \
|
||||
MAP(FIELD, __VA_ARGS__) \
|
||||
|
||||
@@ -40,7 +40,6 @@ public:
|
||||
protected:
|
||||
static const table_column& create_column(class table& tab, const std::string& name);
|
||||
|
||||
private:
|
||||
table(std::string name, std::string alias, const std::vector<table_column>& columns);
|
||||
|
||||
private:
|
||||
@@ -55,6 +54,13 @@ private:
|
||||
|
||||
table operator ""_tab(const char *name, size_t len);
|
||||
|
||||
template<typename Type>
|
||||
class typed_table : public table {
|
||||
public:
|
||||
using table::table;
|
||||
|
||||
Type as(std::string alias) const { return Type{std::move(alias)}; }
|
||||
};
|
||||
}
|
||||
|
||||
#endif //QUERY_TABLE_HPP
|
||||
|
||||
@@ -24,15 +24,18 @@ public:
|
||||
table_column(const class table* tab, std::string name);
|
||||
table_column(const class table* tab, std::string name, std::string alias);
|
||||
table_column(const class table* tab, std::string name, utils::basic_type type, const utils::field_attributes& attributes);
|
||||
table_column(const class table*, std::string name, std::string alias, utils::basic_type type, const utils::field_attributes& attributes);
|
||||
table_column(const class table*, std::string name, std::string alias, utils::basic_type type, const utils::field_attributes& attributes, sql::sql_function_t func = sql::sql_function_t::None);
|
||||
table_column& operator=(const table_column& other);
|
||||
table_column(const table_column& other);
|
||||
table_column(const table_column& other) = default;
|
||||
table_column(table_column&& other) noexcept = default;
|
||||
~table_column() = default;
|
||||
|
||||
[[nodiscard]] bool equals(const table_column &x) const;
|
||||
|
||||
table_column as(std::string a);
|
||||
|
||||
[[nodiscard]] const std::string& name() const;
|
||||
[[nodiscard]] std::string canonical_name() const;
|
||||
[[nodiscard]] const std::string& alias() const;
|
||||
[[nodiscard]] utils::basic_type type() const;
|
||||
[[nodiscard]] utils::field_attributes attributes() const;
|
||||
|
||||
Reference in New Issue
Block a user