introduced table repository
This commit is contained in:
+47
-5
@@ -1,13 +1,38 @@
|
||||
#include "matador/sql/record.hpp"
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
namespace matador::sql {
|
||||
|
||||
record::record(std::initializer_list<column> columns)
|
||||
: columns_(columns) {
|
||||
size_t index{0};
|
||||
for(auto &col : columns_) {
|
||||
columns_by_name_.emplace(col.name(), column_index_pair {std::ref(col), index++});
|
||||
: columns_(columns)
|
||||
{
|
||||
init();
|
||||
}
|
||||
|
||||
record::record(const std::vector<column> &columns)
|
||||
: columns_(columns)
|
||||
{
|
||||
init();
|
||||
}
|
||||
|
||||
bool record::has_primary_key() const
|
||||
{
|
||||
return pk_index_ > -1;
|
||||
}
|
||||
|
||||
const column &record::primary_key() const
|
||||
{
|
||||
if (!has_primary_key()) {
|
||||
throw std::logic_error("record has no primary key");
|
||||
}
|
||||
|
||||
return columns_[pk_index_];
|
||||
}
|
||||
|
||||
const std::vector<column> &record::columns() const
|
||||
{
|
||||
return columns_;
|
||||
}
|
||||
|
||||
const column &record::at(const std::string &name) const
|
||||
@@ -34,7 +59,7 @@ record::const_iterator record::find(const std::string &column_name) const {
|
||||
void record::append(column col)
|
||||
{
|
||||
auto &ref = columns_.emplace_back(std::move(col));
|
||||
columns_by_name_.emplace(ref.name(), column_index_pair{std::ref(ref), columns_.size()-1});
|
||||
add_to_map(ref, columns_.size()-1);
|
||||
}
|
||||
|
||||
record::iterator record::begin()
|
||||
@@ -83,4 +108,21 @@ void record::clear()
|
||||
columns_by_name_.clear();
|
||||
}
|
||||
|
||||
void record::init()
|
||||
{
|
||||
size_t index{0};
|
||||
for(auto &col : columns_) {
|
||||
add_to_map(col, index++);
|
||||
// columns_by_name_.emplace(col.name(), column_index_pair {std::ref(col), index++});
|
||||
}
|
||||
}
|
||||
|
||||
void record::add_to_map(column &col, size_t index)
|
||||
{
|
||||
columns_by_name_.emplace(col.name(), column_index_pair {std::ref(col), index});
|
||||
if (utils::is_constraint_set(col.attributes().options(), utils::constraints::PRIMARY_KEY)) {
|
||||
pk_index_ = static_cast<int>(index);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user