123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510 |
- #ifndef MYSQLX_TABLE_CRUD_H
- #define MYSQLX_TABLE_CRUD_H
- #include "common.h"
- #include "result.h"
- #include "executable.h"
- #include "crud.h"
- namespace mysqlx {
- class Table;
- class TableInsert;
- namespace internal {
- struct Table_insert_base
- : public Executable<Result, TableInsert>
- {};
- }
- class TableInsert
- : public internal::Table_insert_base
- , internal::Table_insert_detail
- {
- protected:
- template <class... Cols>
- TableInsert(Table &table, const Cols&... cols)
- : TableInsert(table)
- {
- add_columns(get_impl(), cols...);
- }
- public:
-
- TableInsert(Table &table)
- {
- try {
- reset(internal::Crud_factory::mk_insert(table));
- }
- CATCH_AND_WRAP
- }
- TableInsert(const internal::Table_insert_base &other)
- {
- internal::Table_insert_base::operator=(other);
- }
- TableInsert(internal::Table_insert_base &&other)
- {
- internal::Table_insert_base::operator=(std::move(other));
- }
-
- virtual TableInsert& values(const Row &row)
- {
- try {
- add_rows(get_impl(), row);
- return *this;
- }
- CATCH_AND_WRAP
- }
-
- template<typename... Types>
- TableInsert& values(Types... rest)
- {
- try {
- add_values(get_impl(), rest...);
- return *this;
- }
- CATCH_AND_WRAP
- }
-
- template<typename Container>
- TableInsert& rows(const Container &cont)
- {
- try {
- add_rows(get_impl(), cont);
- return *this;
- }
- CATCH_AND_WRAP
- }
-
- template<typename It>
- TableInsert& rows(const It &begin, const It &end)
- {
- try {
- add_rows(get_impl(), begin, end);
- return *this;
- }
- CATCH_AND_WRAP
- }
-
- template<typename... Types>
- TableInsert& rows(const Row &first, Types... rest)
- {
- try {
- add_rows(get_impl(), first, rest...);
- return *this;
- }
- CATCH_AND_WRAP
- }
- protected:
- using Table_insert_detail::Impl;
- Impl* get_impl()
- {
- return static_cast<Impl*>(internal::Table_insert_base::get_impl());
- }
-
- friend Table;
-
- };
- class TableSelect;
- namespace internal {
- class Op_view_create_alter;
- struct Table_select_cmd
- : public Executable<RowResult, TableSelect>
- {};
- struct Table_select_base
- : public Group_by < Having < Order_by < Limit < Offset< Bind_parameters<
- Set_lock< Table_select_cmd, common::Table_select_if >
- > > > > > >
- {};
- }
- class TableSelect
- : public internal::Table_select_base
- , internal::Table_select_detail
- {
- using Operation = Table_select_base;
- public:
- TableSelect(Table &table)
- {
- try{
- reset(internal::Crud_factory::mk_select(table));
- }
- CATCH_AND_WRAP
- }
- template <typename...PROJ>
- TableSelect(Table &table, const PROJ&... proj)
- : TableSelect(table)
- {
- try {
- add_proj(get_impl(), proj...);
- }
- CATCH_AND_WRAP
- }
- TableSelect(const internal::Table_select_cmd &other)
- {
- internal::Table_select_cmd::operator=(other);
- }
- TableSelect(internal::Table_select_cmd &&other)
- {
- internal::Table_select_cmd::operator=(std::move(other));
- }
-
- Operation& where(const string& expr)
- {
- try {
- get_impl()->set_where(expr);
- return *this;
- }
- CATCH_AND_WRAP
- }
- protected:
- using Impl = common::Table_select_if;
- Impl* get_impl()
- {
- return static_cast<Impl*>(internal::Table_select_base::get_impl());
- }
-
- friend Table;
- friend internal::Op_view_create_alter;
-
- };
- class TableUpdate;
- namespace internal {
- struct Table_update_cmd
- : public Executable<Result, TableUpdate>
- {};
- struct Table_update_base
- : public Order_by< Limit< Bind_parameters< Table_update_cmd > > >
- {};
- }
- class TableUpdate
- : public internal::Table_update_base
- {
- using Operation = internal::Table_update_base;
- TableUpdate(Table& table)
- {
- try{
- reset(internal::Crud_factory::mk_update(table));
- }
- CATCH_AND_WRAP
- }
- public:
- TableUpdate(Table &table, const string &expr)
- : TableUpdate(table)
- {
- where(expr);
- }
- TableUpdate(const internal::Table_update_cmd &other)
- {
- internal::Table_update_cmd::operator=(other);
- }
- TableUpdate(internal::Table_update_cmd &&other)
- {
- internal::Table_update_cmd::operator=(std::move(other));
- }
-
- TableUpdate& set(const string& field, const Value &val)
- {
- try {
- get_impl()->add_set(field, (const common::Value&)val);
- return *this;
- }
- CATCH_AND_WRAP
- }
-
- Operation& where(const string& expr)
- {
- try {
- get_impl()->set_where(expr);
- return *this;
- }
- CATCH_AND_WRAP
- }
- protected:
- using Impl = common::Table_update_if;
- Impl* get_impl()
- {
- return static_cast<Impl*>(internal::Table_update_base::get_impl());
- }
-
- friend Table;
-
- };
- class TableRemove;
- namespace internal {
- struct Table_remove_cmd
- : public Executable<Result, TableRemove>
- {};
- struct Table_remove_base
- : Order_by< Limit< Bind_parameters< Table_remove_cmd > > >
- {};
- }
- class TableRemove
- : public internal::Table_remove_base
- {
- using Operation = internal::Table_remove_base;
- TableRemove(Table& table)
- {
- try {
- reset(internal::Crud_factory::mk_remove(table));
- }
- CATCH_AND_WRAP
- }
- public:
- TableRemove(Table &table, const string &expr)
- : TableRemove(table)
- {
- where(expr);
- }
- TableRemove(const internal::Table_remove_cmd &other)
- {
- internal::Table_remove_cmd::operator=(other);
- }
- TableRemove(internal::Table_remove_cmd &&other)
- {
- internal::Table_remove_cmd::operator=(std::move(other));
- }
-
- Operation& where(const string &expr)
- {
- try {
- get_impl()->set_where(expr);
- return *this;
- }
- CATCH_AND_WRAP
- }
- protected:
- using Impl = common::Table_remove_if;
- Impl* get_impl()
- {
- return static_cast<Impl*>(internal::Table_remove_base::get_impl());
- }
-
- friend Table;
-
- };
- }
- #endif
|