added column_expression and table_column_expression
This commit is contained in:
parent
1e78430855
commit
85c56584be
|
|
@ -1,4 +1,5 @@
|
||||||
add_executable(demo main.cpp)
|
add_executable(demo main.cpp
|
||||||
|
../include/matador/query/query_column.hpp)
|
||||||
|
|
||||||
target_link_libraries(demo PRIVATE
|
target_link_libraries(demo PRIVATE
|
||||||
matador-core
|
matador-core
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,18 @@
|
||||||
|
#ifndef MATADOR_ABSTRACT_COLUMN_EXPRESSION_HPP
|
||||||
|
#define MATADOR_ABSTRACT_COLUMN_EXPRESSION_HPP
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
namespace matador::query {
|
||||||
|
class expression_visitor;
|
||||||
|
class table_column;
|
||||||
|
class abstract_column_expression {
|
||||||
|
public:
|
||||||
|
virtual ~abstract_column_expression() = default;
|
||||||
|
|
||||||
|
virtual void accept(expression_visitor& visitor) const = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
using column_expression_ptr = std::unique_ptr<abstract_column_expression>;
|
||||||
|
}
|
||||||
|
#endif //MATADOR_ABSTRACT_COLUMN_EXPRESSION_HPP
|
||||||
|
|
@ -0,0 +1,102 @@
|
||||||
|
#ifndef MATADOR_COLUMN_EXPRESSION_HPP
|
||||||
|
#define MATADOR_COLUMN_EXPRESSION_HPP
|
||||||
|
|
||||||
|
#include "matador/query/table_column.hpp"
|
||||||
|
#include "matador/query/abstract_column_expression.hpp"
|
||||||
|
|
||||||
|
#include "matador/utils/placeholder.hpp"
|
||||||
|
#include "matador/utils/types.hpp"
|
||||||
|
|
||||||
|
namespace matador::query {
|
||||||
|
class binary_column_expression;
|
||||||
|
class table_column_expression;
|
||||||
|
class value_expression;
|
||||||
|
class placeholder_expression;
|
||||||
|
|
||||||
|
class expression_visitor {
|
||||||
|
public:
|
||||||
|
virtual ~expression_visitor() = default;
|
||||||
|
|
||||||
|
virtual void visit(const binary_column_expression& node) = 0;
|
||||||
|
virtual void visit(const table_column_expression& node) = 0;
|
||||||
|
virtual void visit(const value_expression& node) = 0;
|
||||||
|
virtual void visit(const placeholder_expression& node) = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
enum class binary_expression_operator {
|
||||||
|
Plus,
|
||||||
|
Minus,
|
||||||
|
Multiply,
|
||||||
|
Divide,
|
||||||
|
Modulo
|
||||||
|
};
|
||||||
|
|
||||||
|
class binary_column_expression : public abstract_column_expression {
|
||||||
|
public:
|
||||||
|
binary_column_expression() = delete;
|
||||||
|
binary_column_expression(column_expression_ptr left_column, binary_expression_operator operand, column_expression_ptr right_column);
|
||||||
|
|
||||||
|
void accept(expression_visitor& visitor) const override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
column_expression_ptr left_column_;
|
||||||
|
binary_expression_operator operand_;
|
||||||
|
column_expression_ptr right_column_;
|
||||||
|
};
|
||||||
|
|
||||||
|
class table_column_expression : public abstract_column_expression {
|
||||||
|
public:
|
||||||
|
table_column_expression() = delete;
|
||||||
|
table_column_expression(table_column col);
|
||||||
|
|
||||||
|
void accept(expression_visitor& visitor) const override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
table_column column_;
|
||||||
|
};
|
||||||
|
|
||||||
|
class value_expression : public abstract_column_expression {
|
||||||
|
public:
|
||||||
|
value_expression() = delete;
|
||||||
|
value_expression(utils::database_type value);
|
||||||
|
|
||||||
|
void accept(expression_visitor& visitor) const override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
utils::database_type value_;
|
||||||
|
};
|
||||||
|
|
||||||
|
class placeholder_expression : public abstract_column_expression {
|
||||||
|
public:
|
||||||
|
placeholder_expression() = default;
|
||||||
|
|
||||||
|
void accept(expression_visitor& visitor) const override;
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename Type>
|
||||||
|
column_expression_ptr operator+(const table_column& col, Type val) {
|
||||||
|
return std::make_unique<binary_column_expression>(std::make_unique<table_column_expression>(col), binary_expression_operator::Plus, std::make_unique<value_expression>(val));
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename Type>
|
||||||
|
column_expression_ptr operator+(Type val, const table_column& col) {
|
||||||
|
return std::make_unique<binary_column_expression>(std::make_unique<value_expression>(val), binary_expression_operator::Plus, std::make_unique<table_column_expression>(col));
|
||||||
|
}
|
||||||
|
|
||||||
|
column_expression_ptr operator+(const table_column& col, utils::placeholder /*val*/);
|
||||||
|
column_expression_ptr operator+(utils::placeholder /*val*/, const table_column& col);
|
||||||
|
|
||||||
|
template<typename Type>
|
||||||
|
column_expression_ptr operator-(const table_column& col, Type val) {
|
||||||
|
return std::make_unique<binary_column_expression>(std::make_unique<table_column_expression>(col), binary_expression_operator::Minus, std::make_unique<value_expression>(val));
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename Type>
|
||||||
|
column_expression_ptr operator-(Type val, const table_column& col) {
|
||||||
|
return std::make_unique<binary_column_expression>(std::make_unique<value_expression>(val), binary_expression_operator::Minus, std::make_unique<table_column_expression>(col));
|
||||||
|
}
|
||||||
|
|
||||||
|
column_expression_ptr operator-(const table_column& col, utils::placeholder /*val*/);
|
||||||
|
column_expression_ptr operator-(utils::placeholder /*val*/, const table_column& col);
|
||||||
|
}
|
||||||
|
#endif //MATADOR_COLUMN_EXPRESSION_HPP
|
||||||
|
|
@ -16,8 +16,8 @@ public:
|
||||||
using executable_query::executable_query;
|
using executable_query::executable_query;
|
||||||
|
|
||||||
template<typename... TableColumns>
|
template<typename... TableColumns>
|
||||||
fetchable_query returning(const TableColumns&... table_columns) {
|
fetchable_query returning(TableColumns... table_columns) {
|
||||||
const std::vector<table_column> tcv { table_columns... };
|
const std::vector<table_column> tcv { std::forward<TableColumns>(table_columns)... };
|
||||||
return returning(tcv);
|
return returning(tcv);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,9 @@
|
||||||
#define QUERY_UPDATE_INTERMEDIATE_HPP
|
#define QUERY_UPDATE_INTERMEDIATE_HPP
|
||||||
|
|
||||||
#include "matador/query/intermediates/query_intermediate.hpp"
|
#include "matador/query/intermediates/query_intermediate.hpp"
|
||||||
|
|
||||||
#include "matador/query/intermediates/query_set_intermediate.hpp"
|
#include "matador/query/intermediates/query_set_intermediate.hpp"
|
||||||
|
|
||||||
|
#include "matador/query/column_expression.hpp"
|
||||||
#include "matador/query/key_value_generator.hpp"
|
#include "matador/query/key_value_generator.hpp"
|
||||||
|
|
||||||
#include "matador/query/internal/column_value_pair.hpp"
|
#include "matador/query/internal/column_value_pair.hpp"
|
||||||
|
|
@ -15,12 +15,20 @@ class query_update_intermediate : public query_intermediate {
|
||||||
public:
|
public:
|
||||||
explicit query_update_intermediate(const table& tab);
|
explicit query_update_intermediate(const table& tab);
|
||||||
|
|
||||||
query_set_intermediate set(std::initializer_list<internal::column_value_pair> columns);
|
// query_set_intermediate set(std::initializer_list<internal::column_value_pair> columns);
|
||||||
query_set_intermediate set(std::vector<internal::column_value_pair> &&columns);
|
// query_set_intermediate set(std::vector<internal::column_value_pair> &&columns);
|
||||||
|
query_update_intermediate& set(const table_column& col, column_expression_ptr expression);
|
||||||
template<class Type>
|
template<class Type>
|
||||||
query_set_intermediate set(const Type &obj) {
|
query_set_intermediate set(const Type &obj) {
|
||||||
return set(key_value_generator::generate(obj));
|
return set(key_value_generator::generate(obj));
|
||||||
}
|
}
|
||||||
|
query_execute_where_intermediate where(std::unique_ptr<abstract_criteria> cond);
|
||||||
|
|
||||||
|
private:
|
||||||
|
query_execute_where_intermediate where_clause(std::unique_ptr<abstract_criteria> &&cond);
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::vector<internal::column_value_pair> key_value_pairs_;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
#define QUERY_KEY_VALUE_PAIR_HPP
|
#define QUERY_KEY_VALUE_PAIR_HPP
|
||||||
|
|
||||||
#include "matador/query/table_column.hpp"
|
#include "matador/query/table_column.hpp"
|
||||||
|
#include "matador/query/column_expression.hpp"
|
||||||
|
|
||||||
#include "matador/utils/placeholder.hpp"
|
#include "matador/utils/placeholder.hpp"
|
||||||
#include "matador/utils/types.hpp"
|
#include "matador/utils/types.hpp"
|
||||||
|
|
@ -11,9 +12,10 @@ namespace matador::query::internal {
|
||||||
class column_value_pair {
|
class column_value_pair {
|
||||||
public:
|
public:
|
||||||
column_value_pair(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 std::string& name, utils::database_type value);
|
||||||
column_value_pair(const char *name, utils::database_type value);
|
column_value_pair(const char *name, utils::database_type value);
|
||||||
column_value_pair(const char *name, utils::placeholder p);
|
column_value_pair(const char *name, utils::placeholder p);
|
||||||
|
column_value_pair(table_column col, column_expression_ptr expression);
|
||||||
|
|
||||||
friend bool operator==(const column_value_pair &lhs, const column_value_pair &rhs);
|
friend bool operator==(const column_value_pair &lhs, const column_value_pair &rhs);
|
||||||
friend bool operator!=(const column_value_pair &lhs, const column_value_pair &rhs);
|
friend bool operator!=(const column_value_pair &lhs, const column_value_pair &rhs);
|
||||||
|
|
@ -24,6 +26,8 @@ public:
|
||||||
private:
|
private:
|
||||||
table_column column_;
|
table_column column_;
|
||||||
std::variant<utils::placeholder, utils::database_type> value_;
|
std::variant<utils::placeholder, utils::database_type> value_;
|
||||||
|
column_expression_ptr expression_;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -374,15 +374,15 @@ private:
|
||||||
class query_set_part final : public query_part
|
class query_set_part final : public query_part
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit query_set_part(const std::vector<internal::column_value_pair>& key_value_pairs);
|
explicit query_set_part(std::vector<column_value_pair>&& key_value_pairs);
|
||||||
|
|
||||||
[[nodiscard]] const std::vector<internal::column_value_pair>& column_values() const;
|
[[nodiscard]] const std::vector<column_value_pair>& column_values() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void accept(query_part_visitor &visitor) override;
|
void accept(query_part_visitor &visitor) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<internal::column_value_pair> key_value_pairs_;
|
std::vector<column_value_pair> key_value_pairs_;
|
||||||
};
|
};
|
||||||
|
|
||||||
class query_delete_part final : public query_part
|
class query_delete_part final : public query_part
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,14 @@
|
||||||
|
#ifndef MATADOR_QUERY_COLUMN_HPP
|
||||||
|
#define MATADOR_QUERY_COLUMN_HPP
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace matador::query {
|
||||||
|
class query_column {
|
||||||
|
public:
|
||||||
|
query_column() = default;
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::string name_;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif //MATADOR_QUERY_COLUMN_HPP
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
#ifndef QUERY_COLUMN_HPP
|
#ifndef QUERY_COLUMN_HPP
|
||||||
#define QUERY_COLUMN_HPP
|
#define QUERY_COLUMN_HPP
|
||||||
|
|
||||||
|
#include "matador/query/abstract_column_expression.hpp"
|
||||||
|
|
||||||
#include "matador/sql/sql_functions.hpp"
|
#include "matador/sql/sql_functions.hpp"
|
||||||
|
|
||||||
#include "matador/utils/basic_types.hpp"
|
#include "matador/utils/basic_types.hpp"
|
||||||
|
|
@ -29,6 +31,9 @@ public:
|
||||||
utils::basic_type type,
|
utils::basic_type type,
|
||||||
const utils::field_attributes& attributes,
|
const utils::field_attributes& attributes,
|
||||||
sql::sql_function_t func = sql::sql_function_t::None);
|
sql::sql_function_t func = sql::sql_function_t::None);
|
||||||
|
|
||||||
|
|
||||||
|
table_column(column_expression_ptr expression) noexcept;
|
||||||
table_column& operator=(const table_column& other);
|
table_column& operator=(const table_column& other);
|
||||||
table_column(const table_column& other) = default;
|
table_column(const table_column& other) = default;
|
||||||
table_column(table_column&& other) noexcept = default;
|
table_column(table_column&& other) noexcept = default;
|
||||||
|
|
|
||||||
|
|
@ -202,6 +202,10 @@ add_library(matador-orm STATIC
|
||||||
query/intermediates/query_values_intermediate.cpp
|
query/intermediates/query_values_intermediate.cpp
|
||||||
../../include/matador/query/error_code.hpp
|
../../include/matador/query/error_code.hpp
|
||||||
query/error_code.cpp
|
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
|
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));
|
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) {
|
// 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});
|
// 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) {
|
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(columns)));
|
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_};
|
return {context_};
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,8 @@
|
||||||
|
|
||||||
namespace matador::query::internal {
|
namespace matador::query::internal {
|
||||||
|
|
||||||
column_value_pair::column_value_pair(std::string name, utils::database_type value)
|
column_value_pair::column_value_pair(const std::string& name, utils::database_type value)
|
||||||
: column_(std::move(name))
|
: column_(name)
|
||||||
, value_(std::move(value)) {
|
, value_(std::move(value)) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -23,6 +23,11 @@ column_value_pair::column_value_pair( const char* name, utils::placeholder p )
|
||||||
: column_(name)
|
: column_(name)
|
||||||
, value_(p) {}
|
, 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 {
|
const table_column &column_value_pair::col() const {
|
||||||
return column_;
|
return column_;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -350,9 +350,9 @@ void query_update_part::accept(query_part_visitor &visitor) {
|
||||||
visitor.visit(*this);
|
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)
|
: 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 {
|
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/table_pk_generator.hpp"
|
||||||
#include "matador/query/query.hpp"
|
#include "matador/query/query.hpp"
|
||||||
|
#include "matador/query/criteria.hpp"
|
||||||
#include "matador/query/error_code.hpp"
|
#include "matador/query/error_code.hpp"
|
||||||
|
#include "matador/query/internal/column_value_pair.hpp"
|
||||||
|
|
||||||
namespace matador::query {
|
namespace matador::query {
|
||||||
table_pk_generator::table_pk_generator(const std::string& table_name, const std::string &sequence_name)
|
table_pk_generator::table_pk_generator(const std::string& table_name, const std::string &sequence_name)
|
||||||
: abstract_pk_generator(utils::generator_type::Table) {
|
: abstract_pk_generator(utils::generator_type::Table) {
|
||||||
|
|
||||||
// query::update(table_name)
|
query::update(table_name)
|
||||||
// .set("next_id", "next_id + 1")
|
.set("next_id"_col, "next_id"_col + 1)
|
||||||
// .where("name", "=", table_name)
|
.where("name"_col == sequence_name)
|
||||||
// .returning("next_id - 1 AS id");
|
.returning(("next_id"_col - 1));
|
||||||
/*
|
/*
|
||||||
*UPDATE id_table
|
*UPDATE id_table
|
||||||
SET next_id = next_id + 1
|
SET next_id = next_id + 1
|
||||||
|
|
|
||||||
|
|
@ -115,21 +115,17 @@ TEST_CASE_METHOD(QueryFixture, "Test insert sql statement string", "[query]") {
|
||||||
|
|
||||||
TEST_CASE_METHOD(QueryFixture, "Test update sql statement string", "[query]") {
|
TEST_CASE_METHOD(QueryFixture, "Test update sql statement string", "[query]") {
|
||||||
auto result = query::update("person")
|
auto result = query::update("person")
|
||||||
.set({
|
.set("id", 7U)
|
||||||
{"id", 7U},
|
.set("name", "george")
|
||||||
{"name", "george"},
|
.set("age", 65U)
|
||||||
{"age", 65U}
|
|
||||||
})
|
|
||||||
.str(*db);
|
.str(*db);
|
||||||
|
|
||||||
REQUIRE(result == R"(UPDATE "person" SET "id"=7, "name"='george', "age"=65)");
|
REQUIRE(result == R"(UPDATE "person" SET "id"=7, "name"='george', "age"=65)");
|
||||||
|
|
||||||
result = query::update("person")
|
result = query::update("person")
|
||||||
.set({
|
.set("id", 7U)
|
||||||
{"id", 7U},
|
.set("name", "george")
|
||||||
{"name", "george"},
|
.set("age", 65U)
|
||||||
{"age", 65U}
|
|
||||||
})
|
|
||||||
.where("id"_col > 9)
|
.where("id"_col > 9)
|
||||||
.order_by("id").asc()
|
.order_by("id").asc()
|
||||||
.limit(3)
|
.limit(3)
|
||||||
|
|
@ -141,8 +137,10 @@ TEST_CASE_METHOD(QueryFixture, "Test update sql statement string", "[query]") {
|
||||||
|
|
||||||
TEST_CASE_METHOD(QueryFixture, "Test update returning statement", "[query][update][returning]") {
|
TEST_CASE_METHOD(QueryFixture, "Test update returning statement", "[query][update][returning]") {
|
||||||
const auto result = query::update("person")
|
const auto result = query::update("person")
|
||||||
.set({{"id", 7U}, {"name", "george"}, {"age", 65U}})
|
.set("id", 7U)
|
||||||
.where("name"_col == "george")
|
.set("name", "george")
|
||||||
|
.set("age", 65U)
|
||||||
|
.where("name"_col == "george")
|
||||||
.returning("id"_col, "name"_col, "age"_col)
|
.returning("id"_col, "name"_col, "age"_col)
|
||||||
.str(*db);
|
.str(*db);
|
||||||
|
|
||||||
|
|
@ -151,7 +149,9 @@ TEST_CASE_METHOD(QueryFixture, "Test update returning statement", "[query][updat
|
||||||
|
|
||||||
TEST_CASE_METHOD(QueryFixture, "Test update limit sql statement", "[query][update][limit]") {
|
TEST_CASE_METHOD(QueryFixture, "Test update limit sql statement", "[query][update][limit]") {
|
||||||
const auto result = query::update("person")
|
const auto result = query::update("person")
|
||||||
.set({{"id", 7U}, {"name", "george"}, {"age", 65U}})
|
.set("id", 7U)
|
||||||
|
.set("name", "george")
|
||||||
|
.set("age", 65U)
|
||||||
.where("name"_col == "george")
|
.where("name"_col == "george")
|
||||||
.order_by("id"_col).asc()
|
.order_by("id"_col).asc()
|
||||||
.limit(2)
|
.limit(2)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue