27 #include <system_error>
30 #include <experimental/optional>
32 #include <boost/config.hpp>
39 #define EJPP_EXPORT BOOST_SYMBOL_IMPORT
41 #define EJPP_EXPORT BOOST_SYMBOL_EXPORT
46 #define EJPP_LOCAL __attribute__((__visibility__("hidden")))
73 return (
db_mode)((std::underlying_type<db_mode>::type)lhs | (std::underlying_type<db_mode>::type)rhs);
93 return (
index_mode)((std::underlying_type<index_mode>::type)lhs | (std::underlying_type<index_mode>::type)rhs);
109 (std::underlying_type<query_search_mode>::type)rhs);
114 return lhs = lhs | rhs;
120 (std::underlying_type<query_search_mode>::type)rhs);
125 return lhs = lhs & rhs;
185 template <>
struct is_error_code_enum<ejdb::errc> :
public true_type {};
195 struct EJPP_EXPORT
db final {
197 db() noexcept =
default;
200 explicit operator bool()
const noexcept;
203 std::error_code error()
const noexcept;
205 static std::error_code error(std::weak_ptr<EJDB>) noexcept;
213 bool is_open()
const noexcept;
216 bool close(std::error_code& ec) noexcept;
231 bool remove_collection(
const std::string& name,
bool unlink_file, std::error_code& ec);
233 void remove_collection(
const std::string& name,
bool unlink_file);
236 const std::vector<collection> get_collections()
const;
239 query create_query(
const std::vector<char>& doc, std::error_code& ec);
241 query create_query(
const std::vector<char>& doc);
244 bool sync(std::error_code& ec) noexcept;
249 std::vector<char> metadata(std::error_code& ec);
251 std::vector<char> metadata();
254 std::shared_ptr<EJDB> m_db;
267 template <query_search_mode flags>
271 std::vector<char>, std::vector<std::vector<char>>>::type>::type;
288 explicit operator bool()
const noexcept;
291 std::experimental::optional<std::array<char, 12>> save_document(
const std::vector<char>& data, std::error_code& ec);
293 std::experimental::optional<std::array<char, 12>> save_document(
const std::vector<char>& data,
bool merge,
294 std::error_code& ec);
296 std::array<char, 12> save_document(
const std::vector<char>& data,
bool merge =
false);
299 std::vector<char> load_document(std::array<char, 12> oid, std::error_code& ec)
const;
301 std::vector<char> load_document(std::array<char, 12> oid)
const;
304 bool remove_document(std::array<char, 12>, std::error_code& ec) noexcept;
306 void remove_document(std::array<char, 12>);
319 template <query_search_mode flags = query_search_mode::normal>
323 std::vector<std::vector<char>> get_all();
326 bool sync(std::error_code& ec) noexcept;
340 EJPP_LOCAL
collection(std::weak_ptr<EJDB> m_db, EJCOLL* m_coll) noexcept;
342 std::weak_ptr<EJDB> m_db;
343 EJCOLL* m_coll{
nullptr};
364 bool start() noexcept;
366 bool commit() noexcept;
368 bool abort() noexcept;
371 bool in_transaction()
const noexcept;
373 explicit operator bool()
const noexcept;
385 std::weak_ptr<EJDB> m_db;
392 #ifndef DOXYGEN_SHOULD_SKIP_THIS
393 extern template EJPP_EXPORT detail::query_return_type<query_search_mode::normal>
394 collection::execute_query<query_search_mode::normal>(
const query& qry);
395 extern template EJPP_EXPORT detail::query_return_type<query_search_mode::count_only>
396 collection::execute_query<query_search_mode::count_only>(
const query& qry);
397 extern template EJPP_EXPORT detail::query_return_type<query_search_mode::first_only>
398 collection::execute_query<query_search_mode::first_only>(
const query& qry);
399 extern template EJPP_EXPORT detail::query_return_type<query_search_mode::count_only | query_search_mode::first_only>
400 collection::execute_query<query_search_mode::count_only | query_search_mode::first_only>(
const query& qry);
401 #endif // DOXYGEN_SHOULD_SKIP_THIS
414 query() noexcept =
default;
417 explicit operator bool()
const noexcept;
438 query& set_hints(
const std::vector<char>&)&;
440 query&& set_hints(
const std::vector<char>&)&&;
445 EJPP_LOCAL
query(std::weak_ptr<EJDB> m_db, EJQ* m_qry) noexcept;
447 std::weak_ptr<EJDB> m_db;
449 struct eqry_deleter {
450 void operator()(EJQ* ptr)
const noexcept;
452 std::unique_ptr<EJQ, eqry_deleter> m_qry;
507 bool owns_transaction()
const noexcept;
509 explicit operator bool()
const noexcept;
517 std::shared_ptr<EJDB> m_db;
Exceeded the maximum number of collections per database.
Only one $elemMatch allowed in the fieldpath.
errc
Error codes. Tokyo Cabinet errors up to errc::miscellaneous.
Definition: ejdb.hpp:129
Invalid ejdb command specified.
constexpr query_search_mode operator&(query_search_mode lhs, query_search_mode rhs) noexcept
Allow bitwise-AND of query_search_mode.
Definition: ejdb.hpp:118
Main point of access to EJDB.
Definition: ejdb.hpp:195
Inconsistent database metadata.
std::error_code make_error_code(errc ecode) noexcept
Makes an std::error_code from an ejdb::errc.
Definition: ejdb.cpp:828
Tag type for expressing an adopted transaction.
Definition: ejdb.hpp:456
illegal transaction state
constexpr db_mode & operator|=(db_mode &lhs, db_mode rhs) noexcept
Allow bitwise-OR-assign of db_mode.
Definition: ejdb.hpp:77
action key in $do block can only be one of: $join.
constexpr db_mode operator|(db_mode lhs, db_mode rhs) noexcept
Allow bitwise-OR of db_mode.
Definition: ejdb.hpp:72
Invalid query control field starting with '$'.
Result set sorting error.
$strand, $stror, $in, $nin, $bt keys requires not empty array value.
Create if db file not exists.
typename std::conditional< (flags &query_search_mode::count_only)==query_search_mode::count_only, uint32_t, typename std::conditional<(flags &query_search_mode::first_only)==query_search_mode::first_only, std::vector< char >, std::vector< std::vector< char >>>::type >::type query_return_type
Determine the correct return type for query flags.
Definition: ejdb.hpp:271
Defines an exception-safe wrapper around collection::transaction_t with unique ownership.
Definition: ejdb.hpp:478
index_mode
Index modes, index types.
Definition: ejdb.hpp:80
EJDB export/import error.
query_search_mode
Query search mode flags.
Definition: ejdb.hpp:100
Tag type for expressing a transaction that only tries to start.
Definition: ejdb.hpp:458
Synchronize every transaction.
Invalid field path value.
Drop index for all types.
Represents an EJDB transaction.
Definition: ejdb.hpp:362
Simple collection::transaction_t wrapper for exception safe operation using RAII
Definition: ejdb.hpp:526
Class representing an EJDB query.
Definition: ejdb.hpp:412
constexpr query_search_mode & operator&=(query_search_mode &lhs, query_search_mode rhs) noexcept
Allow bitwise-AND-assign of query_search_mode.
Definition: ejdb.hpp:124
Invalid query regexp value.
constexpr adopt_transaction_t adopt_transaction
Tag constant for adopting a transaction.
Definition: ejdb.hpp:461
Class representing an EJDB collection.
Definition: ejdb.hpp:283
db_mode
Database open modes.
Definition: ejdb.hpp:61
constexpr try_transaction_t try_transaction
Tag constant for trying to start a transaction.
Definition: ejdb.hpp:463
$fields hint cannot mix include and exclude fields.
Case insensitive string index.