123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275 |
- #ifndef MYSQLX_DETAIL_CRUD_H
- #define MYSQLX_DETAIL_CRUD_H
- #include "../common.h"
- #include "../executable.h"
- namespace mysqlx {
- namespace internal {
- struct PUBLIC_API Bind_detail
- {
- protected:
- using Impl = common::Bind_if;
- using Args_prc = Args_processor<Bind_detail, Impl*>;
- static void process_one(Impl *impl, const Value &val)
- {
- impl->add_param((const common::Value&)val);
- }
- template <typename... T>
- static void add_params(Impl *impl, T&&... vals)
- {
- Args_prc::process_args(impl, std::forward<T>(vals)...);
- }
- friend Args_prc;
- };
- struct PUBLIC_API Sort_detail
- {
- protected:
- using Impl = common::Sort_if;
- using Args_prc = Args_processor<Sort_detail, Impl*>;
- static void process_one(Impl *impl, const string &ord_spec)
- {
- impl->add_sort(ord_spec);
- }
- template <typename... T>
- static void add_sort(Impl *impl, T... args)
- {
- Args_prc::process_args(impl, args...);
- }
- friend Args_prc;
- };
- struct PUBLIC_API Group_by_detail
- {
- protected:
- using Impl = common::Group_by_if;
- using Args_prc = Args_processor<Group_by_detail, Impl*>;
- static void process_one(Impl *impl, const string &spec)
- {
- impl->add_group_by(spec);
- }
- template <typename... T>
- static void do_group_by(Impl *impl, T... args)
- {
- Args_prc::process_args(impl, args...);
- }
- friend Args_prc;
- };
- struct PUBLIC_API Proj_detail
- {
- protected:
- using Impl = common::Proj_if;
- using Args_prc = Args_processor<Proj_detail, Impl*>;
- static void process_one(Impl *impl, const string &spec)
- {
- impl->add_proj(spec);
- }
- template <typename... T>
- static void add_proj(Impl *impl, T... proj_spec)
- {
- Args_prc::process_args(impl, proj_spec...);
- }
- friend Args_prc;
- };
- struct PUBLIC_API Collection_add_detail
- {
- protected:
- using Impl = common::Collection_add_if;
- using Args_prc = Args_processor<Collection_add_detail, Impl*>;
- static void process_one(Impl *impl, const string &json)
- {
- impl->add_json(json);
- }
- static void process_one(Impl *impl, const DbDoc &doc)
- {
-
-
- std::ostringstream buf;
- buf << doc;
-
- impl->add_json(mysqlx::string(buf.str()));
- }
- template <typename... T>
- static void do_add(Impl *impl, T... args)
- {
- Args_prc::process_args(impl, args...);
- }
- friend Args_prc;
- };
- struct PUBLIC_API Collection_find_detail
- {
- protected:
- using Impl = common::Proj_if;
- using Args_prc = Args_processor<Collection_find_detail, Impl*>;
- static void process_one(Impl *impl, const string &proj)
- {
- impl->add_proj(proj);
- }
- static void do_fields(Impl *impl, const Expression &proj)
- {
- impl->set_proj(proj.get<string>());
- }
-
- template <
- typename T, typename... R,
- typename std::enable_if<!std::is_same<T, Expression>::value>::type* = nullptr
- >
- static void do_fields(Impl *impl, T first, R... rest)
- {
- Args_prc::process_args(impl, first, rest...);
- }
- friend Args_prc;
- };
- struct PUBLIC_API Table_insert_detail
- {
- protected:
- using Row_impl = internal::Row_detail::Impl;
- using Impl = common::Table_insert_if<Row_impl>;
-
- struct Add_column
- {
- static void process_one(Impl *impl, const string &col)
- {
- impl->add_column(col);
- }
- };
- struct Add_value
- {
- using Impl = std::pair<Row, unsigned>;
- static void process_one(Impl *impl, const mysqlx::Value &val)
- {
- impl->first.set((impl->second)++, val);
- }
- };
- struct Add_row
- {
- static void process_one(Impl *impl, const Row &row)
- {
- impl->add_row(*row.m_impl);
- }
- };
- template <typename... T>
- static void add_columns(Impl *impl, T... args)
- {
- Args_processor<Add_column,Impl*>::process_args(impl, args...);
- }
- template <typename... T>
- static void add_rows(Impl *impl, T... args)
- {
- Args_processor<Add_row,Impl*>::process_args(impl, args...);
- }
- template <typename... T>
- static void add_values(Impl *impl, T... args)
- {
- Add_value::Impl row{ {}, 0 };
- Args_processor<Add_value>::process_args(&row, args...);
- Add_row::process_one(impl, row.first);
- }
- friend Args_processor<Add_column, Impl*>;
- friend Args_processor<Add_row, Impl*>;
- friend Args_processor<Add_value, Impl*>;
- };
- using Table_select_detail = Proj_detail;
- }}
- #endif
|