View on GitHub
ejpp
Embedded JSON Database engine for C++11/14
Classes | Public Member Functions | Friends | Related Functions | List of all members
ejdb::collection Struct Referencefinal

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_ttransaction () 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...
 

Detailed Description

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_codes set to std::errc::operation_not_permitted (EPERM). The parent ejdb::db object is guaranteed to stay alive for the duration of an operation.

Member Function Documentation

template<query_search_mode flags>
detail::query_return_type< flags > ejdb::collection::execute_query ( const query qry)

Executes a query on the collection.

Template Parameters
flagsThe mode by which to execute the query. Determines return type.
See also
detail::query_return_type
execute_query_impl
std::vector< char > ejdb::collection::load_document ( std::array< char, 12 >  oid,
std::error_code &  ec 
) const

Loads a matching document from the collection.

Parameters
oidOID of the document to fetch.
[out]ecSet to an appropriate error code on failure.
Returns
Document corresponding to 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.

Parameters
oidOID of the document to fetch.
Returns
Document corresponding to oid. Or empty vector if oid has no match.
Exceptions
std::system_errorwith appropriate error code and message on failure.
bool ejdb::collection::remove_document ( std::array< char, 12 >  oid,
std::error_code &  ec 
)
noexcept

Removes a document from the collection.

Parameters
oidOID of the document to remove.
[out]ecSet to an appropriate error code on failure.
Returns
true on success, false on failure.
void ejdb::collection::remove_document ( std::array< char, 12 >  oid)

Removes a document from the collection.

Parameters
oidOID of the document to remove.
Exceptions
std::system_errorwith 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.

collection::save_document

Parameters
dataBSON document to be saved.
[out]ecSet to an appropriate error code on failure.
Returns
OID of saved document on success, std::experimental::nullopt 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.

Parameters
docBSON document to be saved.
mergeWhether or not to merge with an existing, matching document.
[out]ecSet to an appropriate error code on failure.
Returns
OID of saved document on success, std::experimental::nullopt on failure.
std::array< char, 12 > ejdb::collection::save_document ( const std::vector< char > &  data,
bool  merge = false 
)

Parameters
dataBSON document to be saved.
mergeWhether or not to merge with an existing, matching document. Default = false.
Returns
OID of saved document.
Exceptions
std::system_errorwith 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.

Examples:

Parameters
ipathField path to set index on.
flagsejdb::index_mode flags controlling the mode of operation of the index.
[out]ecSet to an appropriate error code on failure.
Returns
true on success, false on failure.
void ejdb::collection::set_index ( const std::string ipath,
index_mode  flags 
)

Sets the index for a BSON field in the collection.

Parameters
ipathField path to set index on.
flagsejdb::index_mode flags controlling the mode of operation of the index.
Exceptions
std::system_errorwith appropriate error code and message on failure.
See also
set_index
bool ejdb::collection::sync ( std::error_code &  ec)
noexcept

Synchronises the EJDB database to disk.

Parameters
[out]ecSet to an appropriate error code on failure.
Returns
true on success, false on failure.
void ejdb::collection::sync ( )

Synchronises the EJDB database to disk.

Exceptions
std::system_errorwith appropriate error code and message on failure.

Friends And Related Function Documentation

std::vector< std::vector< char > > execute_query_impl< query_search_mode::normal > ( std::weak_ptr< EJDB >  m_db,
EJCOLL *  m_coll,
EJQ *  qry 
)
related

Instantiated with flags == query_search_mode::normal. Executes a query in normal mode.

Returns
All records which match the criteria in qry. If collection or qry is invalid, an empty vector is returned.
std::vector< char > execute_query_impl< query_search_mode::first_only > ( std::weak_ptr< EJDB >  m_db,
EJCOLL *  m_coll,
EJQ *  qry 
)
related

Instantiated with flags == query_search_mode::first_only. Executes a query in first-only mode.

Returns
Only the first record which matches the criteria in qry, or std::experimental::nullopt on failure or if none match.
uint32_t execute_query_impl< query_search_mode::count_only > ( std::weak_ptr< EJDB >  m_db,
EJCOLL *  m_coll,
EJQ *  qry 
)
related

Instantiated with flags == query_search_mode::count_only. Executes a query in count-only mode.

Returns
Number of records which match the criteria in qry.
uint32_t execute_query_impl< query_search_mode::count_only|query_search_mode::first_only > ( std::weak_ptr< EJDB >  m_db,
EJCOLL *  m_coll,
EJQ *  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).

Returns
One (1) when at least one documents match the criteria in qry, otherwise zero (0).

The documentation for this struct was generated from the following files: