docudb  1.0
Loading...
Searching...
No Matches
docudb::db_collection Struct Reference

Represents a collection of documents in the database. More...

#include <docudb.hpp>

Public Member Functions

 db_collection ()=default
 Constructs an empty db_collection object.
 
 db_collection (db_collection const &)=delete
 
db_collectionoperator= (db_collection const &)=delete
 
 db_collection (db_collection &&)=default
 
db_collectionoperator= (db_collection &&)=default
 
 db_collection (std::string_view name, sqlite3 *db_handle)
 Constructs a new db_collection object.
 
std::string name () const noexcept
 Gets the collection name.
 
db_document doc (std::string_view doc_id) const
 Gets a document by ID.
 
db_document doc ()
 Creates a new document with a generated UUID.
 
db_document create (std::string_view doc_id)
 Creates a new document with the given ID.
 
std::size_t count () const
 Gets the number of documents in the collection.
 
std::size_t count (query::queryable_type_eraser q) const
 Gets the number of documents that matches the given query.
 
std::vector< db_document_refdocs () const
 Gets all documents in the collection.
 
void remove (std::string_view doc_id)
 Removes a document by ID.
 
std::vector< db_document_reffind (query::queryable_type_eraser q, std::optional< query::order_by > order_by=std::nullopt, std::optional< int > limit=std::nullopt) const
 Searches documents by query.
 
db_collectionindex (std::string_view column_name, std::string_view query, bool unique=false)
 Indexes the document based on the specified column and query.
 
db_collectionindex (std::string name, std::vector< std::pair< std::string, std::string > > const &columns, bool unique)
 Indexes the document based on the specified columns and query.
 

Detailed Description

Represents a collection of documents in the database.

Definition at line 744 of file docudb.hpp.

Constructor & Destructor Documentation

◆ db_collection() [1/4]

docudb::db_collection::db_collection ( )
default

Constructs an empty db_collection object.

◆ db_collection() [2/4]

docudb::db_collection::db_collection ( db_collection const & )
delete

◆ db_collection() [3/4]

docudb::db_collection::db_collection ( db_collection && )
default

◆ db_collection() [4/4]

docudb::db_collection::db_collection ( std::string_view name,
sqlite3 * db_handle )

Constructs a new db_collection object.

Parameters
nameThe name of the collection.
db_handleThe SQLite database handle.

Member Function Documentation

◆ count() [1/2]

std::size_t docudb::db_collection::count ( ) const

Gets the number of documents in the collection.

Returns
std::size_t The number of documents in the collection.

◆ count() [2/2]

std::size_t docudb::db_collection::count ( query::queryable_type_eraser q) const

Gets the number of documents that matches the given query.

Parameters
qThe query object.
Returns
std::size_t The number of matching documents.

◆ create()

db_document docudb::db_collection::create ( std::string_view doc_id)

Creates a new document with the given ID.

Returns
db_document The new document object.

◆ doc() [1/2]

db_document docudb::db_collection::doc ( )

Creates a new document with a generated UUID.

Returns
db_document The new document object.

◆ doc() [2/2]

db_document docudb::db_collection::doc ( std::string_view doc_id) const

Gets a document by ID.

Parameters
doc_idThe document ID.
Returns
db_document The document object.

◆ docs()

std::vector< db_document_ref > docudb::db_collection::docs ( ) const

Gets all documents in the collection.

Returns
std::vector<db_document_ref> The list of document references.

◆ find()

std::vector< db_document_ref > docudb::db_collection::find ( query::queryable_type_eraser q,
std::optional< query::order_by > order_by = std::nullopt,
std::optional< int > limit = std::nullopt ) const

Searches documents by query.

Parameters
qThe query object.
order_byThe order by object (optional)
limitThe maximum number of documents to return (optional).
Returns
std::vector<db_document_ref> The list of document references.

◆ index() [1/2]

db_collection & docudb::db_collection::index ( std::string name,
std::vector< std::pair< std::string, std::string > > const & columns,
bool unique )

Indexes the document based on the specified columns and query.

This function creates a new virtual column representing the given json query and add an index to that column.

Parameters
nameThe index name
columnsA vector of pairs [column_name, query]
uniqueThe index should be unique
Returns
A reference to the document.

◆ index() [2/2]

db_collection & docudb::db_collection::index ( std::string_view column_name,
std::string_view query,
bool unique = false )

Indexes the document based on the specified column and query.

This function creates a new virtual column representing the given json query and add an index to that column.

Parameters
column_nameThe name of the column to be created.
queryThe json query string in SQLite format representing the field to be indexed
uniqueThe index should be unique
Returns
A reference to the document.

◆ name()

std::string docudb::db_collection::name ( ) const
noexcept

Gets the collection name.

Returns
std::string The collection name.

◆ operator=() [1/2]

db_collection & docudb::db_collection::operator= ( db_collection && )
default

◆ operator=() [2/2]

db_collection & docudb::db_collection::operator= ( db_collection const & )
delete

◆ remove()

void docudb::db_collection::remove ( std::string_view doc_id)

Removes a document by ID.

Parameters
doc_idThe document ID.

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