added column_expression and table_column_expression
This commit is contained in:
@@ -202,6 +202,10 @@ add_library(matador-orm STATIC
|
||||
query/intermediates/query_values_intermediate.cpp
|
||||
../../include/matador/query/error_code.hpp
|
||||
query/error_code.cpp
|
||||
../../include/matador/query/column_expression.hpp
|
||||
query/column_expression.cpp
|
||||
../../include/matador/query/abstract_column_expression.hpp
|
||||
../../include/matador/query/query_column.hpp
|
||||
)
|
||||
|
||||
target_include_directories(matador-orm
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
#include "matador/query/column_expression.hpp"
|
||||
|
||||
namespace matador::query {
|
||||
binary_column_expression::binary_column_expression(column_expression_ptr left_column, binary_expression_operator operand, column_expression_ptr right_column)
|
||||
: left_column_(std::move(left_column))
|
||||
, operand_(operand)
|
||||
, right_column_(std::move(right_column)) {
|
||||
}
|
||||
|
||||
void binary_column_expression::accept(expression_visitor &visitor) const {
|
||||
visitor.visit(*this);
|
||||
}
|
||||
|
||||
table_column_expression::table_column_expression(table_column col)
|
||||
: column_(std::move(col)){
|
||||
}
|
||||
|
||||
void table_column_expression::accept(expression_visitor &visitor) const {
|
||||
visitor.visit(*this);
|
||||
}
|
||||
|
||||
value_expression::value_expression(utils::database_type value)
|
||||
: value_(std::move(value)) {
|
||||
}
|
||||
|
||||
void value_expression::accept(expression_visitor &visitor) const {
|
||||
visitor.visit(*this);
|
||||
}
|
||||
|
||||
void placeholder_expression::accept(expression_visitor &visitor) const {
|
||||
visitor.visit(*this);
|
||||
}
|
||||
|
||||
column_expression_ptr operator+(const table_column &col, utils::placeholder /*placeholder*/) {
|
||||
return std::make_unique<binary_column_expression>(std::make_unique<table_column_expression>(col), binary_expression_operator::Plus, std::make_unique<placeholder_expression>());
|
||||
}
|
||||
|
||||
column_expression_ptr operator+(utils::placeholder /*placeholder*/, const table_column &col) {
|
||||
return std::make_unique<binary_column_expression>(std::make_unique<placeholder_expression>(), binary_expression_operator::Plus, std::make_unique<table_column_expression>(col));
|
||||
}
|
||||
|
||||
column_expression_ptr operator-(const table_column &col, utils::placeholder /*placeholder*/) {
|
||||
return std::make_unique<binary_column_expression>(std::make_unique<table_column_expression>(col), binary_expression_operator::Minus, std::make_unique<placeholder_expression>());
|
||||
}
|
||||
|
||||
column_expression_ptr operator-(utils::placeholder /*placeholder*/, const table_column &col) {
|
||||
return std::make_unique<binary_column_expression>(std::make_unique<placeholder_expression>(), binary_expression_operator::Minus, std::make_unique<table_column_expression>(col));
|
||||
}
|
||||
}
|
||||
@@ -9,13 +9,26 @@ query_update_intermediate::query_update_intermediate(const table& tab) {
|
||||
context_->parts.push_back(std::make_unique<internal::query_update_part>(tab));
|
||||
}
|
||||
|
||||
query_set_intermediate query_update_intermediate::set(const std::initializer_list<internal::column_value_pair> columns) {
|
||||
return set(std::vector<internal::column_value_pair>{columns});
|
||||
// query_set_intermediate query_update_intermediate::set(const std::initializer_list<internal::column_value_pair> columns) {
|
||||
// return set(std::vector<internal::column_value_pair>{columns});
|
||||
// }
|
||||
|
||||
// query_set_intermediate query_update_intermediate::set(std::vector<internal::column_value_pair> &&columns) {
|
||||
// context_->parts.push_back(std::make_unique<internal::query_set_part>(std::move(columns)));
|
||||
// return {context_};
|
||||
// }
|
||||
query_update_intermediate& query_update_intermediate::set(const table_column &col, column_expression_ptr expression) {
|
||||
key_value_pairs_.emplace_back(col, std::move(expression));
|
||||
return *this;
|
||||
}
|
||||
|
||||
query_set_intermediate query_update_intermediate::set(std::vector<internal::column_value_pair> &&columns) {
|
||||
context_->parts.push_back(std::make_unique<internal::query_set_part>(std::move(columns)));
|
||||
query_execute_where_intermediate query_update_intermediate::where(std::unique_ptr<abstract_criteria> cond) {
|
||||
context_->parts.push_back(std::make_unique<internal::query_set_part>(std::move(key_value_pairs_)));
|
||||
return where_clause(std::move(cond));
|
||||
}
|
||||
|
||||
query_execute_where_intermediate query_update_intermediate::where_clause(std::unique_ptr<abstract_criteria> &&cond) {
|
||||
context_->parts.push_back(std::make_unique<internal::query_where_part>(std::move(cond)));
|
||||
return {context_};
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
|
||||
namespace matador::query::internal {
|
||||
|
||||
column_value_pair::column_value_pair(std::string name, utils::database_type value)
|
||||
: column_(std::move(name))
|
||||
column_value_pair::column_value_pair(const std::string& name, utils::database_type value)
|
||||
: column_(name)
|
||||
, value_(std::move(value)) {
|
||||
}
|
||||
|
||||
@@ -23,6 +23,11 @@ column_value_pair::column_value_pair( const char* name, utils::placeholder p )
|
||||
: column_(name)
|
||||
, value_(p) {}
|
||||
|
||||
column_value_pair::column_value_pair(table_column col, column_expression_ptr expression)
|
||||
: column_(std::move(col))
|
||||
, expression_(std::move(expression)){
|
||||
}
|
||||
|
||||
const table_column &column_value_pair::col() const {
|
||||
return column_;
|
||||
}
|
||||
|
||||
@@ -350,9 +350,9 @@ void query_update_part::accept(query_part_visitor &visitor) {
|
||||
visitor.visit(*this);
|
||||
}
|
||||
|
||||
query_set_part::query_set_part(const std::vector<column_value_pair> &key_value_pairs)
|
||||
query_set_part::query_set_part(std::vector<column_value_pair> &&key_value_pairs)
|
||||
: query_part(sql::dialect_token::Set)
|
||||
, key_value_pairs_(key_value_pairs) {
|
||||
, key_value_pairs_(std::move(key_value_pairs)) {
|
||||
}
|
||||
|
||||
const std::vector<column_value_pair> &query_set_part::column_values() const {
|
||||
|
||||
@@ -1,15 +1,17 @@
|
||||
#include "matador/query/table_pk_generator.hpp"
|
||||
#include "matador/query/query.hpp"
|
||||
#include "matador/query/criteria.hpp"
|
||||
#include "matador/query/error_code.hpp"
|
||||
#include "matador/query/internal/column_value_pair.hpp"
|
||||
|
||||
namespace matador::query {
|
||||
table_pk_generator::table_pk_generator(const std::string& table_name, const std::string &sequence_name)
|
||||
: abstract_pk_generator(utils::generator_type::Table) {
|
||||
|
||||
// query::update(table_name)
|
||||
// .set("next_id", "next_id + 1")
|
||||
// .where("name", "=", table_name)
|
||||
// .returning("next_id - 1 AS id");
|
||||
query::update(table_name)
|
||||
.set("next_id"_col, "next_id"_col + 1)
|
||||
.where("name"_col == sequence_name)
|
||||
.returning(("next_id"_col - 1));
|
||||
/*
|
||||
*UPDATE id_table
|
||||
SET next_id = next_id + 1
|
||||
|
||||
Reference in New Issue
Block a user