21#include "cbl/CBLCollection.h"
22#include "cbl/CBLDatabase.h"
23#include "cbl/CBLDocument.h"
24#include "cbl/CBLQuery.h"
25#include "cbl/CBLLog.h"
26#include "cbl/CBLScope.h"
27#include "fleece/Fleece.hh"
28#include "fleece/Mutable.hh"
52#ifdef COUCHBASE_ENTERPRISE
100 CBLEncryptionKey::operator=(k);
111 #ifdef COUCHBASE_ENTERPRISE
130#ifdef COUCHBASE_ENTERPRISE
155 static bool exists(std::string_view
name, std::optional<std::string_view> inDirectory=std::nullopt) {
157 if ( inDirectory ) inDir =
slice(*inDirectory);
166 std::string_view toName)
170 nullptr, &error), error );
179 std::string_view toName,
185#ifdef COUCHBASE_ENTERPRISE
191 &cblConfig, &error), error );
198 static void deleteDatabase(std::string_view
name, std::optional<std::string_view> inDirectory =std::nullopt) {
201 if ( inDirectory ) inDir =
slice(*inDirectory);
203 internal::check(
false, error);
226#ifdef COUCHBASE_ENTERPRISE
231 open(
name, &cblConfig);
253#ifdef COUCHBASE_ENTERPRISE
288 inline Blob getBlob(fleece::Dict properties)
const;
313 internal::check(error.
code == 0, error);
314 fleece::MutableArray names(flNames);
325 internal::check(error.
code == 0, error);
326 fleece::MutableArray names(flNames);
337 inline Collection getCollection(std::string_view collectionName, std::optional<std::string_view> scopeName = std::nullopt)
const;
355 void deleteCollection(std::string_view collectionName, std::optional<std::string_view> scopeName =std::nullopt) {
358 if ( scopeName ) sname = *scopeName;
388 _notificationReadyCallbackAccess->setCallback(callback);
390 ((NotificationsReadyCallbackAccess*)context)->call(
Database(db));
391 }, _notificationReadyCallbackAccess.get());
417 internal::check(_ref !=
nullptr, error);
419 _notificationReadyCallbackAccess = std::make_shared<NotificationsReadyCallbackAccess>();
422 class NotificationsReadyCallbackAccess {
425 std::lock_guard<std::mutex> lock(_mutex);
426 _callback = callback;
432 std::lock_guard<std::mutex> lock(_mutex);
433 callback = _callback;
443 std::shared_ptr<NotificationsReadyCallbackAccess> _notificationReadyCallbackAccess;
451 ,_notificationReadyCallbackAccess(other._notificationReadyCallbackAccess)
457 :RefCounted((RefCounted&&)other)
458 ,_notificationReadyCallbackAccess(std::move(other._notificationReadyCallbackAccess))
465 RefCounted::operator=(other);
466 _notificationReadyCallbackAccess = other._notificationReadyCallbackAccess;
474 RefCounted::operator=((RefCounted&&)other);
475 _notificationReadyCallbackAccess = std::move(other._notificationReadyCallbackAccess);
486 _notificationReadyCallbackAccess.reset();
531 if (std::current_exception())
533 "Transaction::end failed, while handling an exception");
535 internal::check(
false, error);
#define CBL_REFCOUNTED_WITHOUT_COPY_MOVE_BOILERPLATE(CLASS, SUPER, C_TYPE)
Definition Base.hh:140
#define CBL_ASSUME_NONNULL_END
#define CBL_ASSUME_NONNULL_BEGIN
A reference to a binary data blob associated with a document.
Definition Blob.hh:39
A Collection is a container for documents within a database.
Definition Collection.hh:131
Database configuration options.
Definition Database.hh:108
std::string directory
The parent directory of the database.
Definition Database.hh:110
EncryptionKey encryptionKey
The database's encryption key (if any)
Definition Database.hh:112
DatabaseConfiguration(const CBLDatabaseConfiguration &cblConfig)
Constructs a configuration from a C CBLDatabaseConfiguration, copying the directory and (in EE) encry...
Definition Database.hh:128
static DatabaseConfiguration defaultConfiguration()
Returns a configuration initialized with the default settings (default directory, no encryption,...
Definition Database.hh:141
DatabaseConfiguration()=default
Default constructor: empty directory, no encryption, full-sync off.
bool fullSync
As Couchbase Lite normally configures its databases, There is a very small (though non-zero) chance t...
Definition Database.hh:123
A Couchbase Lite database, which is a container for collections of documents.
Definition Database.hh:147
void saveBlob(const Blob &blob)
Save a new Blob object into the database without associating it with any documents.
Definition Blob.hh:230
~Database()
Releases the underlying database handle.
Definition Database.hh:403
void sendNotifications()
Immediately issues all pending notifications for this database, by calling their listener callbacks.
Definition Database.hh:395
Blob getBlob(fleece::Dict properties) const
Get a Blob from the database using the Blob properties.
Definition Blob.hh:221
fleece::MutableArray getCollectionNames(std::string_view scopeName=(std::string_view) slice(kCBLDefaultScopeName)) const
Returns the names of all collections in the scope.
Definition Database.hh:322
CBLDatabase *_Nullable ref() const
Returns a pointer to the underlying C object (CBLDatabase), or NULL if this is a null reference.
Definition Database.hh:411
Query createQuery(QueryLanguage language, std::string_view queryString)
Creates a new query by compiling the input string.
Definition Query.hh:313
std::function< void(Database)> NotificationsReadyCallback
Definition Database.hh:381
std::string path() const
Returns the database's full filesystem path, or an empty string if the database is closed or deleted.
Definition Database.hh:271
void clear()
Releases the underlying C CBLDatabase handle and drops the buffered-notification callback.
Definition Database.hh:482
void bufferNotifications(NotificationsReadyCallback callback)
Switches the database to buffered-notification mode.
Definition Database.hh:387
Collection getDefaultCollection() const
Returns the default collection.
Definition Collection.hh:438
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.
Definition Collection.hh:426
std::string name() const
Returns the database's name.
Definition Database.hh:268
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 t...
Definition Database.hh:178
Database(Database &&other) noexcept
Move constructor.
Definition Database.hh:456
Collection createCollection(std::string_view collectionName, std::optional< std::string_view > scopeName=std::nullopt)
Create a new collection.
Definition Collection.hh:432
friend class Collection
Definition Database.hh:408
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.
Definition Database.hh:221
Database & operator=(Database &&other) noexcept
Move assignment.
Definition Database.hh:473
void deleteCollection(std::string_view collectionName, std::optional< std::string_view > scopeName=std::nullopt)
Delete an existing collection.
Definition Database.hh:355
friend class Scope
Definition Database.hh:409
static void deleteDatabase(std::string_view name, std::optional< std::string_view > inDirectory=std::nullopt)
Deletes a database file.
Definition Database.hh:198
Database() noexcept
Constructs a null reference (one that points to no object).
Definition Database.hh:411
void performMaintenance(CBLMaintenanceType type)
Performs database maintenance.
Definition Database.hh:248
void deleteDatabase()
Closes and deletes a database.
Definition Database.hh:241
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 t...
Definition Database.hh:165
fleece::MutableArray getScopeNames() const
Returns the names of all existing scopes in the database.
Definition Database.hh:310
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.
Definition Database.hh:155
void close()
Closes an open database.
Definition Database.hh:235
DatabaseConfiguration config() const
Returns the database's configuration, as given when it was opened.
Definition Database.hh:274
Database & operator=(const Database &other) noexcept
Copy assignment.
Definition Database.hh:464
Database(std::string_view name)
Opens a database, or creates it if it doesn't exist yet, returning a new Database instance.
Definition Database.hh:212
void changeEncryptionKey(const EncryptionKey *_Nullable newKey)
Encrypts or decrypts a database, or changes its encryption key.
Definition Database.hh:259
Database(const Database &other) noexcept
Copy constructor.
Definition Database.hh:449
An immutable, in-memory copy of a document read from a collection.
Definition Document.hh:33
A database encryption key, used in DatabaseConfiguration to open or create an encrypted database.
Definition Database.hh:75
EncryptionKey(const CBLEncryptionKey &k)
Creates a key from an existing C CBLEncryptionKey.
Definition Database.hh:84
EncryptionKey & operator=(const CBLEncryptionKey &k)
Assigns from an existing C CBLEncryptionKey.
Definition Database.hh:99
EncryptionKey(std::string_view password, bool old=false)
Derives an AES-256 key from a password.
Definition Database.hh:93
EncryptionKey()
Creates an empty key (algorithm kCBLEncryptionNone, i.e.
Definition Database.hh:78
Manages Couchbase Lite extensions, such as the Vector Search extension.
Definition Database.hh:55
static void enableVectorSearch(std::string_view path)
Enables Vector Search extension by specifying the extension path to search for the Vector Search exte...
Definition Database.hh:61
A mutable document, whose properties can be modified and saved to a collection.
Definition Document.hh:104
A database query.
Definition Query.hh:36
void commit()
Commits changes and ends the transaction.
Definition Database.hh:513
Transaction(Database db)
Begins a batch operation on the database that will end when the Batch instance goes out of scope.
Definition Database.hh:499
void abort()
Ends the transaction, rolling back changes.
Definition Database.hh:516
Transaction(CBLDatabase *db)
Begins a batch operation on the given C database handle.
Definition Database.hh:506
~Transaction()
Ends the transaction, rolling back any changes that have not been committed.
Definition Database.hh:519
void FLMutableArray_Release(FLMutableArray FL_NULLABLE d)
bool CBLDatabase_DeleteCollection(CBLDatabase *db, FLString collectionName, FLString scopeName, CBLError *_cbl_nullable outError)
FLMutableArray _cbl_nullable CBLDatabase_CollectionNames(const CBLDatabase *db, FLString scopeName, CBLError *_cbl_nullable outError)
FLMutableArray _cbl_nullable CBLDatabase_ScopeNames(const CBLDatabase *db, CBLError *_cbl_nullable outError)
bool CBL_CopyDatabase(FLString fromPath, FLString toName, const CBLDatabaseConfiguration *_cbl_nullable config, CBLError *_cbl_nullable outError)
bool CBLDatabase_EndTransaction(CBLDatabase *, bool commit, CBLError *_cbl_nullable outError)
struct CBLDatabase CBLDatabase
bool CBLEncryptionKey_FromPassword(CBLEncryptionKey *key, FLString password)
bool CBLDatabase_Delete(CBLDatabase *, CBLError *_cbl_nullable outError)
bool CBLDatabase_Close(CBLDatabase *, CBLError *_cbl_nullable outError)
bool CBL_DatabaseExists(FLString name, FLString inDirectory)
bool CBLDatabase_ChangeEncryptionKey(CBLDatabase *, const CBLEncryptionKey *_cbl_nullable newKey, CBLError *outError)
_cbl_warn_unused CBLDatabase *_cbl_nullable CBLDatabase_Open(FLSlice name, const CBLDatabaseConfiguration *_cbl_nullable config, CBLError *_cbl_nullable outError)
bool CBL_DeleteDatabase(FLString name, FLString inDirectory, CBLError *_cbl_nullable outError)
const CBLDatabaseConfiguration CBLDatabase_Config(const CBLDatabase *)
bool CBLDatabase_PerformMaintenance(CBLDatabase *db, CBLMaintenanceType type, CBLError *_cbl_nullable outError)
_cbl_warn_unused FLStringResult CBLDatabase_Path(const CBLDatabase *)
CBLDatabaseConfiguration CBLDatabaseConfiguration_Default(void)
bool CBLDatabase_BeginTransaction(CBLDatabase *, CBLError *_cbl_nullable outError)
bool CBL_EnableVectorSearch(FLString path, CBLError *_cbl_nullable outError)
bool CBLEncryptionKey_FromPasswordOld(CBLEncryptionKey *key, FLString password)
FLString CBLDatabase_Name(const CBLDatabase *)
void CBLDatabase_SendNotifications(CBLDatabase *db)
void CBLDatabase_BufferNotifications(CBLDatabase *db, CBLNotificationsReadyCallback _cbl_nullable callback, void *_cbl_nullable context)
void CBL_Log(CBLLogDomain domain, CBLLogLevel level, const char *format,...) __printflike(3
struct CBLRefCounted CBLRefCounted
CBL_PUBLIC const FLString kCBLDefaultScopeName
struct _FLArray * FLMutableArray
CBLEncryptionKeySize EncryptionKeySize
Alias for the C CBLEncryptionKeySize enum giving the required key size for an algorithm.
Definition Database.hh:70
fleece::slice slice
Convenience alias for fleece::slice, a non-owning view of a byte range.
Definition Base.hh:49
CBLQueryLanguage QueryLanguage
Definition Base.hh:53
CBLEncryptionAlgorithm EncryptionAlgorithm
Alias for the C CBLEncryptionAlgorithm enum identifying an encryption algorithm.
Definition Database.hh:68
std::function< bool(MutableDocument documentBeingSaved, Document conflictingDocument)> ConflictHandler
Conflict handler used when saving a document.
Definition Database.hh:48
CBLEncryptionKey encryptionKey