Merge remote-tracking branch 'origin/main'
# Conflicts: # demo/main.cpp
This commit is contained in:
commit
27f6c81da2
|
|
@ -1,3 +1,4 @@
|
|||
.idea
|
||||
cmake-build-debug
|
||||
Testing
|
||||
debug
|
||||
|
|
|
|||
|
|
@ -15,8 +15,9 @@ struct column;
|
|||
class record
|
||||
{
|
||||
private:
|
||||
using field_by_index = std::vector<field>;
|
||||
using field_index_pair = std::pair<std::reference_wrapper<field>, field_by_index::difference_type>;
|
||||
using field_ref = std::reference_wrapper<field>;
|
||||
using field_by_index = std::vector<field_ref>;
|
||||
using field_index_pair = std::pair<field, field_by_index::difference_type>;
|
||||
using field_by_name_map = std::unordered_map<std::string, field_index_pair>;
|
||||
|
||||
public:
|
||||
|
|
@ -36,13 +37,13 @@ public:
|
|||
void process(Operator &op)
|
||||
{
|
||||
for(auto &f : fields_) {
|
||||
f.process(op);
|
||||
f.get().process(op);
|
||||
}
|
||||
}
|
||||
|
||||
void append(field col);
|
||||
void append(const field &col);
|
||||
|
||||
[[nodiscard]] const std::vector<field>& columns() const;
|
||||
[[nodiscard]] const std::vector<field_ref>& columns() const;
|
||||
|
||||
[[nodiscard]] const field& at(const column &col) const;
|
||||
[[nodiscard]] const field& at(size_t index) const;
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
#include "matador/sql/noop_connection.hpp"
|
||||
#include "matador/sql/dialect_builder.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <stdexcept>
|
||||
|
||||
namespace matador::sql {
|
||||
|
|
|
|||
|
|
@ -7,23 +7,27 @@
|
|||
namespace matador::sql {
|
||||
|
||||
record::record(std::initializer_list<field> columns)
|
||||
: fields_(columns)
|
||||
{
|
||||
init();
|
||||
for (auto &&col :columns) {
|
||||
const auto it = fields_by_name_.emplace(col.name(), field_index_pair {col, fields_.size()});
|
||||
fields_.push_back(std::ref(it.first->second.first));
|
||||
}
|
||||
}
|
||||
|
||||
record::record(const std::vector<field> &columns)
|
||||
: fields_(columns)
|
||||
{
|
||||
init();
|
||||
for (auto &&col :columns) {
|
||||
const auto it = fields_by_name_.emplace(col.name(), field_index_pair {col, fields_.size()});
|
||||
fields_.push_back(std::ref(it.first->second.first));
|
||||
}
|
||||
}
|
||||
|
||||
record::record(const record &x)
|
||||
: fields_(x.fields_)
|
||||
: fields_by_name_(x.fields_by_name_)
|
||||
//, pk_index_(x.pk_index_)
|
||||
{
|
||||
for (auto& col : fields_) {
|
||||
add_to_map(col, col.index());
|
||||
for (auto& col : fields_by_name_) {
|
||||
fields_.push_back(std::ref(col.second.first));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -33,16 +37,16 @@ record &record::operator=(const record &x)
|
|||
return *this;
|
||||
}
|
||||
|
||||
fields_ = x.fields_;
|
||||
fields_by_name_.clear();
|
||||
fields_by_name_ = x.fields_by_name_;
|
||||
fields_.clear();
|
||||
// pk_index_ = x.pk_index_;
|
||||
for (auto& col : fields_) {
|
||||
add_to_map(col, col.index());
|
||||
for (auto& col : fields_by_name_) {
|
||||
fields_.push_back(std::ref(col.second.first));
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
const std::vector<field> &record::columns() const
|
||||
const std::vector<record::field_ref> &record::columns() const
|
||||
{
|
||||
return fields_;
|
||||
}
|
||||
|
|
@ -63,7 +67,9 @@ const std::vector<field> &record::columns() const
|
|||
|
||||
const field &record::at(const column &col) const
|
||||
{
|
||||
return fields_by_name_.at(col.name).first;
|
||||
const auto &res = fields_by_name_.at(col.name);
|
||||
const auto &f = res.first;
|
||||
return f;
|
||||
}
|
||||
|
||||
const field &record::at(size_t index) const
|
||||
|
|
@ -82,10 +88,10 @@ record::const_iterator record::find(const std::string &column_name) const {
|
|||
return it != fields_by_name_.end() ? fields_.begin() + it->second.second : fields_.end();
|
||||
}
|
||||
|
||||
void record::append(field col)
|
||||
void record::append(const field &col)
|
||||
{
|
||||
auto &ref = fields_.emplace_back(std::move(col));
|
||||
add_to_map(ref, fields_.size() - 1);
|
||||
const auto it = fields_by_name_.emplace(col.name(), field_index_pair {col, fields_.size()});
|
||||
fields_.push_back(std::ref(it.first->second.first));
|
||||
}
|
||||
|
||||
record::iterator record::begin()
|
||||
|
|
|
|||
Loading…
Reference in New Issue