added date_type_t, time_type_t and timestamp, ensure allocated postgres resources are released, split repository into basic_repository and repository.

This commit is contained in:
2026-01-06 15:43:20 +01:00
parent f07a360da2
commit 0c6b5a0a93
60 changed files with 1132 additions and 1225 deletions
@@ -38,8 +38,9 @@ public:
void write_value(size_t pos, const bool& x) override;
void write_value(size_t pos, const float& x) override;
void write_value(size_t pos, const double& x) override;
void write_value(size_t pos, const time& x) override;
void write_value(size_t pos, const date& x) override;
void write_value(size_t pos, const utils::date_type_t& x) override;
void write_value(size_t pos, const utils::time_type_t& x) override;
void write_value(size_t pos, const utils::timestamp& x) override;
void write_value(size_t pos, const char* x) override;
void write_value(size_t pos, const char* x, size_t size) override;
void write_value(size_t pos, const std::string& x) override;
+33 -34
View File
@@ -46,7 +46,7 @@ constexpr auto default_column_generator_options = column_generator_options::Forc
class column_generator {
public:
explicit column_generator(const schema &repo,
const std::string &table_name = "",
const table* tab,
column_generator_options options = default_column_generator_options);
template< class Type >
@@ -88,21 +88,19 @@ public:
if (attr.fetch() == utils::fetch_type::Lazy || is_column_generator_option_set(options_, column_generator_options::ForceLazy)) {
return;
}
if (!repo_) {
return;
}
const auto info = repo_->get().repo().info<typename ContainerType::value_type::value_type>();
if (!info) {
const auto it = repo_.find(typeid(typename ContainerType::value_type::value_type));
if (it == repo_.end()) {
// Todo: throw exception
return;
}
if (seen_tables.count(info->get().name()) == 0) {
auto it = seen_tables.insert(info->get().name()).first;
table_stack_.push(std::make_shared<table>(info.value().get().name()));
if (seen_tables.count(it->second.name()) == 0) {
const auto itt = seen_tables.insert(it->second.name()).first;
table_stack_.push(&it->second.table());
typename ContainerType::value_type::value_type obj;
access::process(*this, obj);
table_stack_.pop();
seen_tables.erase(it);
seen_tables.erase(itt);
}
}
@@ -124,20 +122,18 @@ private:
if (attr.fetch() == utils::fetch_type::Lazy || is_column_generator_option_set(options_, column_generator_options::ForceLazy)) {
push(id);
} else {
if (!repo_) {
const auto it = repo_.find(typeid(typename Pointer::value_type));
if (it == repo_.end()) {
// Todo: throw exception
return;
}
const auto info = repo_->get().repo().info<typename Pointer::value_type>();
if (!info) {
return;
}
if (seen_tables.count(info->get().name()) == 0) {
auto it = seen_tables.insert(info->get().name()).first;
table_stack_.push(std::make_shared<table>(info.value().get().name()));
if (seen_tables.count(it->second.name()) == 0) {
const auto iit = seen_tables.insert(it->second.name()).first;
table_stack_.push(&it->second.table());
typename Pointer::value_type obj;
access::process(*this, obj);
table_stack_.pop();
seen_tables.erase(it);
seen_tables.erase(iit);
}
}
}
@@ -145,9 +141,9 @@ private:
void push(const std::string &column_name);
private:
std::optional<std::reference_wrapper<const schema>> repo_;
const schema &repo_;
std::vector<table_column> result_;
std::stack<std::shared_ptr<table>> table_stack_;
std::stack<const table*> table_stack_;
std::unordered_set<std::string> seen_tables;
int column_index{0};
column_generator_options options_{false};
@@ -294,29 +290,32 @@ std::vector<internal::column_value_pair> column_value_pairs() {
template<typename Type>
std::vector<table_column> columns(const schema &repo,
const std::string &table_name = "",
const table &tab,
const column_generator_options options = default_column_generator_options) {
column_generator generator(repo, table_name, options);
column_generator generator(repo, &tab, options);
return generator.generate<Type>();
}
template<typename Type>
std::vector<table_column> columns(const schema &repo,
const column_generator_options options) {
std::string table_name;
if (const auto result = repo.repo().info<Type>()) {
table_name = result.value().get().name();
}
column_generator generator(repo, table_name, options);
return generator.generate<Type>();
const column_generator_options options = default_column_generator_options) {
const auto it = repo.find(typeid(Type));
if (it == repo.end()) {
return {};
}
column_generator generator(repo, &it->second.table(), options);
return generator.generate<Type>();
}
template<typename Type>
std::vector<table_column> columns(const Type &obj,
const schema &repo,
const std::string &table_name = "",
const column_generator_options options = default_column_generator_options) {
column_generator generator(repo, table_name, options);
const schema &repo,
const column_generator_options options = default_column_generator_options) {
const auto it = repo.find(typeid(Type));
if (it == repo.end()) {
return {};
}
column_generator generator(repo, &it->second.table(), options);
return generator.generate(obj);
}
@@ -17,7 +17,7 @@ public:
return into(tab, generator::columns<Type>(scm));
}
query_into_intermediate into(const table &tab, std::initializer_list<table_column> columns);
query_into_intermediate into(const table &tab, std::vector<table_column> &&columns);
query_into_intermediate into(const table &tab, const std::vector<table_column> &columns);
query_into_intermediate into(const table &tab, const std::vector<std::string> &column_names);
query_into_intermediate into(const table &tab);
};
@@ -7,11 +7,6 @@
#include <string>
namespace matador {
class date;
class time;
}
namespace matador::sql {
class dialect;
struct query_context;
@@ -36,8 +31,9 @@ struct basic_type_to_string_visitor
void operator()(const double &x) { result = writer->to_string(x); }
void operator()(const char *x) { result = writer->to_string(x); }
void operator()(const std::string &x) { result = writer->to_string(x); }
void operator()(const matador::date &x) { result = writer->to_string(x); }
void operator()(const matador::time &x) { result = writer->to_string(x); }
void operator()(const utils::date_type_t &x) { result = writer->to_string(x); }
void operator()(const utils::time_type_t &x) { result = writer->to_string(x); }
void operator()(const utils::timestamp &x) { result = writer->to_string(x); }
void operator()(const utils::blob &x) { result = writer->to_string(x); }
attribute_string_writer *writer{};
@@ -10,7 +10,7 @@ namespace matador::query::internal {
class column_value_pair {
public:
column_value_pair(const table_column &col, utils::database_type value);
column_value_pair(table_column col, utils::database_type value);
column_value_pair(std::string name, utils::database_type value);
column_value_pair(const char *name, utils::database_type value);
column_value_pair(const char *name, utils::placeholder p);
+3 -3
View File
@@ -92,9 +92,9 @@ public:
template<typename Type>
[[nodiscard]] utils::result<void, utils::error> drop_table(const sql::connection &conn);
[[nodiscard]] utils::result<void, utils::error> drop_table(const std::string &table_name, const sql::connection &conn) const;
[[nodiscard]] static utils::result<void, utils::error> drop_table(const std::string &table_name, const sql::connection &conn);
[[nodiscard]] utils::result<std::vector<object::attribute>, utils::error> describe_table(const std::string &table_name, const sql::connection &conn) const;
[[nodiscard]] static utils::result<std::vector<object::attribute>, utils::error> describe_table(const std::string &table_name, const sql::connection &conn) ;
[[nodiscard]] utils::result<bool, utils::error> table_exists(const std::string &table_name, const sql::connection &conn) const;
iterator begin();
@@ -127,7 +127,7 @@ private:
template<typename Type>
utils::result<void, utils::error> schema::drop_table(const sql::connection &conn) {
auto info = repo_.info<Type>();
auto info = repo_.basic_info<Type>();
if (info) {
return drop_table(info->get().name(), conn);
}
+3 -2
View File
@@ -71,8 +71,9 @@ public:
void write_value(size_t pos, const bool &x) override;
void write_value(size_t pos, const float &x) override;
void write_value(size_t pos, const double &x) override;
void write_value(size_t pos, const time &x ) override;
void write_value(size_t pos, const date &x ) override;
void write_value(size_t pos, const utils::date_type_t &x ) override;
void write_value(size_t pos, const utils::time_type_t &x ) override;
void write_value(size_t pos, const utils::timestamp &x ) override;
void write_value(size_t pos, const char *x) override;
void write_value(size_t pos, const char *x, size_t size) override;
void write_value(size_t pos, const std::string &x) override;