|
Couchbase Lite C++
Couchbase Lite C++ API
|
A Couchbase Lite database, which is a container for collections of documents. More...
#include <cbl++/Database.hh>
Public Types | |
| using | NotificationsReadyCallback = std::function<void(Database)> |
Public Member Functions | |
| Database (std::string_view name) | |
| Opens a database, or creates it if it doesn't exist yet, returning a new Database instance. | |
| Database (std::string_view name, const DatabaseConfiguration &config) | |
| Opens a database, or creates it if it doesn't exist yet, returning a new Database instance. | |
| void | close () |
| Closes an open database. | |
| void | deleteDatabase () |
| Closes and deletes a database. | |
| void | performMaintenance (CBLMaintenanceType type) |
| Performs database maintenance. | |
| void | changeEncryptionKey (const EncryptionKey *_Nullable newKey) |
| Encrypts or decrypts a database, or changes its encryption key. | |
| std::string | name () const |
| Returns the database's name. | |
| std::string | path () const |
| Returns the database's full filesystem path, or an empty string if the database is closed or deleted. | |
| DatabaseConfiguration | config () const |
| Returns the database's configuration, as given when it was opened. | |
| Blob | getBlob (fleece::Dict properties) const |
| Get a Blob from the database using the Blob properties. | |
| void | saveBlob (const Blob &blob) |
| Save a new Blob object into the database without associating it with any documents. | |
| fleece::MutableArray | getScopeNames () const |
| Returns the names of all existing scopes in the database. | |
| fleece::MutableArray | getCollectionNames (std::string_view scopeName=(std::string_view) slice(kCBLDefaultScopeName)) const |
| Returns the names of all collections in the scope. | |
| Collection | getCollection (std::string_view collectionName, std::optional< std::string_view > scopeName=std::nullopt) const |
| Returns the existing collection with the given name and scope. | |
| Collection | createCollection (std::string_view collectionName, std::optional< std::string_view > scopeName=std::nullopt) |
| Create a new collection. | |
| void | deleteCollection (std::string_view collectionName, std::optional< std::string_view > scopeName=std::nullopt) |
| Delete an existing collection. | |
| Collection | getDefaultCollection () const |
| Returns the default collection. | |
| Query | createQuery (QueryLanguage language, std::string_view queryString) |
| Creates a new query by compiling the input string. | |
| void | bufferNotifications (NotificationsReadyCallback callback) |
| Switches the database to buffered-notification mode. | |
| void | sendNotifications () |
| Immediately issues all pending notifications for this database, by calling their listener callbacks. | |
| ~Database () | |
| Releases the underlying database handle. | |
| Database () noexcept | |
| Constructs a null reference (one that points to no object). | |
| Database & | operator= (std::nullptr_t) |
| Releases the underlying object and resets this to a null reference. | |
| bool | valid () const |
| Returns true if this references an object, or false if it is a null reference. | |
| operator bool () const | |
| Returns true if this references an object (same as valid). | |
| bool | operator== (const Database &other) const |
| Returns true if both sides reference the same object, or are both null references. | |
| bool | operator!= (const Database &other) const |
| Returns true if the two sides reference different objects. | |
| CBLDatabase *_Nullable | ref () const |
| Returns a pointer to the underlying C object (CBLDatabase), or NULL if this is a null reference. | |
| Database (const Database &other) noexcept | |
| Copy constructor. | |
| Database (Database &&other) noexcept | |
| Move constructor. | |
| Database & | operator= (const Database &other) noexcept |
| Copy assignment. | |
| Database & | operator= (Database &&other) noexcept |
| Move assignment. | |
| void | clear () |
| Releases the underlying C CBLDatabase handle and drops the buffered-notification callback. | |
Static Public Member Functions | |
| static bool | exists (std::string_view name, std::optional< std::string_view > inDirectory=std::nullopt) |
| Returns true if a database with the given name exists in the given directory. | |
| static void | copyDatabase (std::string_view fromPath, std::string_view toName) |
| Copies a database file to a new location, and assigns it a new internal UUID to distinguish it from the original database when replicating. | |
| static void | copyDatabase (std::string_view fromPath, std::string_view toName, const DatabaseConfiguration &config) |
| Copies a database file to a new location, and assigns it a new internal UUID to distinguish it from the original database when replicating. | |
| static void | deleteDatabase (std::string_view name, std::optional< std::string_view > inDirectory=std::nullopt) |
| Deletes a database file. | |
Protected Member Functions | |
| Database (CBLDatabase *_Nullable ref) | |
| (Internal) Constructs a reference wrapping, and retaining, a C object pointer. | |
Friends | |
| class | Collection |
| class | Scope |
A Couchbase Lite database, which is a container for collections of documents.
| using cbl::Database::NotificationsReadyCallback = std::function<void(Database)> |
|
inline |
Opens a database, or creates it if it doesn't exist yet, returning a new Database instance.
It's OK to open the same database file multiple times. Each Database instance is independent of the others (and must be separately closed and released.)
| name | The database name (without the ".cblite2" extension.) |
|
inline |
Opens a database, or creates it if it doesn't exist yet, returning a new Database instance.
It's OK to open the same database file multiple times. Each Database instance is independent of the others (and must be separately closed and released.)
| name | The database name (without the ".cblite2" extension.) |
| config | The database configuration (directory and encryption option.) |
|
inline |
Releases the underlying database handle.
The database remains open if other Database references to it exist.
|
inlinenoexcept |
Constructs a null reference (one that points to no object).
|
inlineexplicitprotected |
(Internal) Constructs a reference wrapping, and retaining, a C object pointer.
|
inlinenoexcept |
Copy constructor.
Both *this and other refer to the same underlying CBLDatabase handle (its refcount is incremented) and share the buffered-notification callback state.
|
inlinenoexcept |
Move constructor.
Takes over other's CBLDatabase handle and buffered-notification callback state, leaving other empty.
|
inline |
Switches the database to buffered-notification mode.
Notifications for objects belonging to this database (documents, queries, replicators, and of course the database) will not be called immediately; your NotificationsReadyCallback will be called instead.
| callback | The function to be called when a notification is available. |
|
inline |
Encrypts or decrypts a database, or changes its encryption key.
If newKey is NULL, or its algorithm is kCBLEncryptionNone, the database will be decrypted. Otherwise the database will be encrypted with that key; if it was already encrypted, it will be re-encrypted with the new key.
|
inline |
Releases the underlying C CBLDatabase handle and drops the buffered-notification callback.
After this call the object is empty (its operator bool returns false).
|
inline |
Closes an open database.
|
inline |
Returns the database's configuration, as given when it was opened.
|
inlinestatic |
Copies a database file to a new location, and assigns it a new internal UUID to distinguish it from the original database when replicating.
| fromPath | The full filesystem path to the original database (including extension). |
| toName | The new database name (without the ".cblite2" extension.) |
|
inlinestatic |
Copies a database file to a new location, and assigns it a new internal UUID to distinguish it from the original database when replicating.
| fromPath | The full filesystem path to the original database (including extension). |
| toName | The new database name (without the ".cblite2" extension.) |
| config | The database configuration (directory and encryption option.) |
|
inline |
Create a new collection.
The naming rules of the collections and scopes are as follows:
| collectionName | The name of the collection. |
| scopeName | The name of the scope (optional). If not supplied, the default scope name will be used. |
|
inline |
Creates a new query by compiling the input string.
This is fast, but not instantaneous. If you need to run the same query many times, keep the Query object around instead of compiling it each time. If you need to run related queries with only some values different, create one query with placeholder parameter(s), and substitute the desired value(s) with Query::setParameters(fleece::Dict parameters) each time you run the query.
|
inline |
Delete an existing collection.
| collectionName | The name of the collection. |
| scopeName | The name of the scope (optional). If not supplied, the default scope name will be used. |
|
inline |
Closes and deletes a database.
|
inlinestatic |
Deletes a database file.
If the database file is open, an error will be thrown.
| name | The database name (without the ".cblite2" extension.) |
| inDirectory | The directory containing the database(optional), If not provided, name must be an absolute or relative path to the database. |
|
inlinestatic |
Returns true if a database with the given name exists in the given directory.
| name | The database name (without the ".cblite2" extension.) |
| inDirectory | The directory containing the database. If not provided, name must be an absolute or relative path to the database. |
|
inline |
Get a Blob from the database using the Blob properties.
The Blob properties is a blob's metadata containing two required fields which are a special marker property "@type":"blob", and property digest whose value is a hex SHA-1 digest of the blob's data. The other optional properties are length and content_type. To obtain the Blob properties from a Blob, call Blob::properties function.
| properties | The properties for getting the Blob object. |
| cbl::Error | On a database error (such as malformed blob properties). Note a non-existent blob is not an error — that returns a falsy Blob rather than throwing. |
|
inline |
Returns the existing collection with the given name and scope.
| collectionName | The name of the collection. |
| scopeName | The name of the scope (optional). If not supplied, the default scope name will be used. |
| cbl::Error | On a database error. Note a non-existent collection is not an error — that returns a falsy Collection rather than throwing. |
|
inline |
Returns the names of all collections in the scope.
| scopeName | The name of the scope. |
|
inline |
Returns the default collection.
|
inline |
Returns the names of all existing scopes in the database.
The scope exists when there is at least one collection created under the scope.
|
inline |
Returns the database's name.
|
inlineexplicit |
Returns true if this references an object (same as valid).
|
inline |
Returns true if the two sides reference different objects.
Copy assignment.
Releases the currently-referenced handle (if any), then makes *this refer to the same CBLDatabase as other (refcount incremented) and share its buffered-notification callback state.
Move assignment.
Releases the currently-referenced handle (if any), then takes over other's CBLDatabase handle and buffered-notification callback state; other is left empty.
|
inline |
Releases the underlying object and resets this to a null reference.
|
inline |
Returns true if both sides reference the same object, or are both null references.
|
inline |
Returns the database's full filesystem path, or an empty string if the database is closed or deleted.
|
inline |
Performs database maintenance.
| type | The database maintenance type. |
|
inline |
Returns a pointer to the underlying C object (CBLDatabase), or NULL if this is a null reference.
|
inline |
Save a new Blob object into the database without associating it with any documents.
The properties of the saved Blob object will include information necessary for referencing the Blob object in the properties of the document to be saved into the database.
Normally you do not need to use this function unless you are in the situation (e.g. developing javascript binding) that you cannot retain the CBLBlob object until the document containing the CBLBlob object is successfully saved into the database.
| blob | The Blob to save. |
|
inline |
Immediately issues all pending notifications for this database, by calling their listener callbacks.
|
inline |
Returns true if this references an object, or false if it is a null reference.
|
friend |
|
friend |