ejpp
Embedded JSON Database engine for C++11/14
|
View on GitHub
Class representing an EJDB collection. More...
#include <ejdb.hpp>
Classes | |
struct | transaction_t |
Represents an EJDB transaction. More... | |
Public Member Functions | |
collection () noexcept=default | |
Default constructor. Results in an invalid collection, not associated with a db. | |
template<query_search_mode flags = query_search_mode::normal> | |
detail::query_return_type< flags > | execute_query (const query &) |
Executes a query on the collection. More... | |
std::vector< std::vector< char > > | get_all () |
Returns all documents in the collection. | |
std::vector< char > | load_document (std::array< char, 12 > oid, std::error_code &ec) const |
Loads a matching document from the collection. More... | |
std::vector< char > | load_document (std::array< char, 12 > oid) const |
Loads a matching document from the collection. More... | |
std::string | name () const |
Returns the name of the collection. | |
operator bool () const noexcept | |
Returns whether the associated ejdb::db and represented EJDB collection are both valid. | |
bool | remove_document (std::array< char, 12 >, std::error_code &ec) noexcept |
Removes a document from the collection. More... | |
void | remove_document (std::array< char, 12 >) |
Removes a document from the collection. More... | |
std::experimental::optional < std::array< char, 12 > > | save_document (const std::vector< char > &data, std::error_code &ec) |
Saves a document to the collection, overwriting an existing, matching document. More... | |
std::experimental::optional < std::array< char, 12 > > | save_document (const std::vector< char > &data, bool merge, std::error_code &ec) |
Saves a document to the collection, optionally merging with an existing, matching document. More... | |
std::array< char, 12 > | save_document (const std::vector< char > &data, bool merge=false) |
bool | set_index (const std::string &ipath, index_mode flags, std::error_code &ec) |
Sets the index for a BSON field in the collection. More... | |
void | set_index (const std::string &ipath, index_mode flags) |
Sets the index for a BSON field in the collection. More... | |
bool | sync (std::error_code &ec) noexcept |
Synchronises the EJDB database to disk. More... | |
void | sync () |
Synchronises the EJDB database to disk. More... | |
transaction_t & | transaction () noexcept |
Returns this collection's transaction_t. | |
Friends | |
struct | db |
Related Functions | |
(Note that these are not member functions.) | |
template<> | |
std::vector< std::vector< char > > | execute_query_impl (std::weak_ptr< EJDB > m_db, EJCOLL *m_coll, EJQ *qry) |
Instantiated with flags == query_search_mode::normal . Executes a query in normal mode. More... | |
template<> | |
uint32_t | execute_query_impl (std::weak_ptr< EJDB > m_db, EJCOLL *m_coll, EJQ *qry) |
Instantiated with flags == query_search_mode::count_only . Executes a query in count-only mode. More... | |
template<> | |
std::vector< char > | execute_query_impl (std::weak_ptr< EJDB > m_db, EJCOLL *m_coll, EJQ *qry) |
Instantiated with flags == query_search_mode::first_only . Executes a query in first-only mode. More... | |
template<> | |
uint32_t | execute_query_impl (std::weak_ptr< EJDB > m_db, EJCOLL *m_coll, EJQ *qry) |
Instantiated with flags == query_search_mode::count_only | query_search_mode::first_only . Executes a query in count-only mode, but only counts up to one (1). More... | |
Class representing an EJDB collection.
Valid collections can only be created via ejdb::db::create_collection or ejdb::db::get_collection.
Should the parent ejdb::db object expire before the collection, all operations performed on or with the collection will fail, with any std::error_code
s set to std::errc::operation_not_permitted
(EPERM
). The parent ejdb::db object is guaranteed to stay alive for the duration of an operation.
detail::query_return_type< flags > ejdb::collection::execute_query | ( | const query & | qry | ) |
Executes a query on the collection.
flags | The mode by which to execute the query. Determines return type. |
std::vector< char > ejdb::collection::load_document | ( | std::array< char, 12 > | oid, |
std::error_code & | ec | ||
) | const |
Loads a matching document from the collection.
oid | OID of the document to fetch. | |
[out] | ec | Set to an appropriate error code on failure. |
oid
on success, empty vector on failure or if oid
has no match. std::vector< char > ejdb::collection::load_document | ( | std::array< char, 12 > | oid | ) | const |
Loads a matching document from the collection.
oid | OID of the document to fetch. |
oid
. Or empty vector if oid
has no match.std::system_error | with appropriate error code and message on failure. |
|
noexcept |
Removes a document from the collection.
oid | OID of the document to remove. | |
[out] | ec | Set to an appropriate error code on failure. |
void ejdb::collection::remove_document | ( | std::array< char, 12 > | oid | ) |
Removes a document from the collection.
oid | OID of the document to remove. |
std::system_error | with appropriate error code and message on failure. |
std::experimental::optional< std::array< char, 12 > > ejdb::collection::save_document | ( | const std::vector< char > & | data, |
std::error_code & | ec | ||
) |
Saves a document to the collection, overwriting an existing, matching document.
data | BSON document to be saved. | |
[out] | ec | Set to an appropriate error code on failure. |
std::experimental::optional< std::array< char, 12 > > ejdb::collection::save_document | ( | const std::vector< char > & | doc, |
bool | merge, | ||
std::error_code & | ec | ||
) |
Saves a document to the collection, optionally merging with an existing, matching document.
doc | BSON document to be saved. | |
merge | Whether or not to merge with an existing, matching document. | |
[out] | ec | Set to an appropriate error code on failure. |
std::array< char, 12 > ejdb::collection::save_document | ( | const std::vector< char > & | data, |
bool | merge = false |
||
) |
data | BSON document to be saved. |
merge | Whether or not to merge with an existing, matching document. Default = false. |
std::system_error | with appropriate error code and message on failure. |
bool ejdb::collection::set_index | ( | const std::string & | ipath, |
index_mode | flags, | ||
std::error_code & | ec | ||
) |
Sets the index for a BSON field in the collection.
EJDB's setindex documentation follows.
index_mode::string
: String index for JSON string values.index_mode::istring
: Case insensitive string index for JSON string values.index_mode::number
: Index for JSON number values.index_mode::array
: Token index for JSON arrays and string values.index_mode::drop
Drop index of specified type.index_mode::drop_all
Drop index for all types.index_mode::rebuild
Rebuild index of specified type.index_mode::optimize
Optimize index of specified type. (Optimize the B+ tree index file)Examples:
"addressbook.number"
for strings and numbers: ipath | Field path to set index on. | |
flags | ejdb::index_mode flags controlling the mode of operation of the index. | |
[out] | ec | Set to an appropriate error code on failure. |
void ejdb::collection::set_index | ( | const std::string & | ipath, |
index_mode | flags | ||
) |
Sets the index for a BSON field in the collection.
ipath | Field path to set index on. |
flags | ejdb::index_mode flags controlling the mode of operation of the index. |
std::system_error | with appropriate error code and message on failure. |
|
noexcept |
Synchronises the EJDB database to disk.
[out] | ec | Set to an appropriate error code on failure. |
void ejdb::collection::sync | ( | ) |
Synchronises the EJDB database to disk.
std::system_error | with appropriate error code and message on failure. |
|
related |
Instantiated with flags == query_search_mode::normal
. Executes a query in normal mode.
qry
. If collection or qry
is invalid, an empty vector is returned.
|
related |
Instantiated with flags == query_search_mode::first_only
. Executes a query in first-only mode.
qry
, or std::experimental::nullopt on failure or if none match.
|
related |
Instantiated with flags == query_search_mode::count_only
. Executes a query in count-only mode.
qry
.
|
related |
Instantiated with flags == query_search_mode::count_only | query_search_mode::first_only
. Executes a query in count-only mode, but only counts up to one (1).
qry
, otherwise zero (0).