record refactoring
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
|
||||
#include "matador/utils/access.hpp"
|
||||
|
||||
#include "matador/sql/column_definition.hpp"
|
||||
#include "matador/sql/field.hpp"
|
||||
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
@@ -15,17 +15,17 @@ struct column;
|
||||
class record
|
||||
{
|
||||
private:
|
||||
using column_by_index = std::vector<column_definition>;
|
||||
using column_index_pair = std::pair<std::reference_wrapper<column_definition>, size_t>;
|
||||
using column_by_name_map = std::unordered_map<std::string, column_index_pair>;
|
||||
using field_by_index = std::vector<field>;
|
||||
using field_index_pair = std::pair<std::reference_wrapper<field>, field_by_index::difference_type>;
|
||||
using field_by_name_map = std::unordered_map<std::string, field_index_pair>;
|
||||
|
||||
public:
|
||||
using iterator = column_by_index::iterator;
|
||||
using const_iterator = column_by_index::const_iterator;
|
||||
using iterator = field_by_index::iterator;
|
||||
using const_iterator = field_by_index::const_iterator;
|
||||
|
||||
record() = default;
|
||||
record(std::initializer_list<column_definition> columns);
|
||||
explicit record(const std::vector<column_definition> &columns);
|
||||
record(std::initializer_list<field> columns);
|
||||
explicit record(const std::vector<field> &columns);
|
||||
record(const record &x);
|
||||
record& operator=(const record &x);
|
||||
record(record&&) noexcept = default;
|
||||
@@ -35,25 +35,17 @@ public:
|
||||
template<class Operator>
|
||||
void process(Operator &op)
|
||||
{
|
||||
for(auto &col : columns_) {
|
||||
col.process(op);
|
||||
for(auto &f : fields_) {
|
||||
f.process(op);
|
||||
}
|
||||
}
|
||||
template < typename Type >
|
||||
void append(const std::string &name, long size = -1)
|
||||
{
|
||||
append(make_column<Type>(name, size));
|
||||
}
|
||||
|
||||
void append(column_definition col);
|
||||
void append(field col);
|
||||
|
||||
[[nodiscard]] bool has_primary_key() const;
|
||||
[[nodiscard]] std::optional<column_definition> primary_key() const;
|
||||
[[nodiscard]] const std::vector<field>& columns() const;
|
||||
|
||||
[[nodiscard]] const std::vector<column_definition>& columns() const;
|
||||
|
||||
[[nodiscard]] const column_definition& at(const column &col) const;
|
||||
[[nodiscard]] const column_definition& at(size_t index) const;
|
||||
[[nodiscard]] const field& at(const column &col) const;
|
||||
[[nodiscard]] const field& at(size_t index) const;
|
||||
|
||||
iterator find(const std::string &column_name);
|
||||
[[nodiscard]] const_iterator find(const std::string &column_name) const;
|
||||
@@ -70,17 +62,17 @@ public:
|
||||
[[nodiscard]] bool empty() const;
|
||||
void clear();
|
||||
|
||||
[[nodiscard]] bool unknown() const;
|
||||
// [[nodiscard]] bool unknown() const;
|
||||
|
||||
private:
|
||||
void init();
|
||||
void add_to_map(column_definition &col, size_t index);
|
||||
void add_to_map(field &col, size_t index);
|
||||
|
||||
private:
|
||||
column_by_index columns_;
|
||||
column_by_name_map columns_by_name_;
|
||||
field_by_index fields_;
|
||||
field_by_name_map fields_by_name_;
|
||||
|
||||
int pk_index_{-1};
|
||||
// int pk_index_{-1};
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user