|
Couchbase Lite C
Couchbase Lite C API
|
A CBLDatabase is both a filesystem object and a container for documents. More...
Data Structures | |
| struct | CBLEncryptionKey |
| Encryption key specified in a CBLDatabaseConfiguration. More... | |
| struct | CBLDatabaseConfiguration |
| Database configuration options. More... | |
Typedefs | |
| typedef struct CBLDatabase | CBLDatabase |
| A connection to an open database. | |
Database configuration | |
| enum | CBLEncryptionAlgorithm : uint32_t { kCBLEncryptionNone = 0 , kCBLEncryptionAES256 } |
| enum | CBLEncryptionKeySize : uint64_t { kCBLEncryptionKeySizeAES256 = 32 } |
| CBLDatabaseConfiguration | CBLDatabaseConfiguration_Default (void) |
| Returns the default database configuration. | |
| bool | CBLEncryptionKey_FromPassword (CBLEncryptionKey *key, FLString password) |
| Derives an encryption key from a password. | |
| bool | CBLEncryptionKey_FromPasswordOld (CBLEncryptionKey *key, FLString password) |
| VOLATILE API: Derives an encryption key from a password in a way that is compatible with certain variants of Couchbase Lite in which a slightly different hashing algorithm is used. | |
Database listeners | |
A database change listener lets you detect changes made to all documents in the default collection. (If you only want to observe specific documents, use a CBLDocumentChangeListener instead.)
| |
| typedef void(* | CBLDatabaseChangeListener) (void *_cbl_nullable context, const CBLDatabase *db, unsigned numDocs, FLString docIDs[]) |
| A default collection change listener callback, invoked after one or more documents in the default collection are changed on disk. | |
| _cbl_warn_unused CBLListenerToken * | CBLDatabase_AddChangeListener (const CBLDatabase *db, CBLDatabaseChangeListener listener, void *_cbl_nullable context) |
| Registers a default collection change listener callback. | |
Database Extension | |
| bool | CBL_EnableVectorSearch (FLString path, CBLError *_cbl_nullable outError) |
| ENTERPRISE EDITION ONLY. | |
Database file operations | |
These functions operate on database files without opening them. | |
| bool | CBL_DatabaseExists (FLString name, FLString inDirectory) |
| Returns true if a database with the given name exists in the given directory. | |
| bool | CBL_CopyDatabase (FLString fromPath, FLString toName, const CBLDatabaseConfiguration *_cbl_nullable config, CBLError *_cbl_nullable outError) |
| Copies a database file to a new location, and assigns it a new internal UUID to distinguish it from the original database when replicating. | |
| bool | CBL_DeleteDatabase (FLString name, FLString inDirectory, CBLError *_cbl_nullable outError) |
| Deletes a database file. | |
Database accessors | |
Getting information about a database. | |
| FLString | CBLDatabase_Name (const CBLDatabase *) |
| Returns the database's name. | |
| _cbl_warn_unused FLStringResult | CBLDatabase_Path (const CBLDatabase *) |
| Returns the database's full filesystem path, or null slice if the database is closed or deleted. | |
| uint64_t | CBLDatabase_Count (const CBLDatabase *) |
| Returns the number of documents in the database, or zero if the database is closed or deleted. | |
| const CBLDatabaseConfiguration | CBLDatabase_Config (const CBLDatabase *) |
| Returns the database's configuration, as given when it was opened. | |
Query Indexes | |
Query Index Management | |
| bool | CBLDatabase_CreateValueIndex (CBLDatabase *db, FLString name, CBLValueIndexConfiguration config, CBLError *_cbl_nullable outError) |
| Creates a value index. | |
| bool | CBLDatabase_CreateFullTextIndex (CBLDatabase *db, FLString name, CBLFullTextIndexConfiguration config, CBLError *_cbl_nullable outError) |
| Creates a full-text index. | |
| bool | CBLDatabase_DeleteIndex (CBLDatabase *db, FLString name, CBLError *_cbl_nullable outError) |
| Deletes an index given its name. | |
| _cbl_warn_unused FLArray | CBLDatabase_GetIndexNames (CBLDatabase *db) |
| Returns the names of the indexes on this database, as a Fleece array of strings. | |
A CBLDatabase is both a filesystem object and a container for documents.
| typedef struct CBLDatabase CBLDatabase |
A connection to an open database.
| typedef void(* CBLDatabaseChangeListener) (void *_cbl_nullable context, const CBLDatabase *db, unsigned numDocs, FLString docIDs[]) |
A default collection change listener callback, invoked after one or more documents in the default collection are changed on disk.
| context | An arbitrary value given when the callback was registered. |
| db | The database that changed. |
| numDocs | The number of documents that changed (size of the docIDs array) |
| docIDs | The IDs of the documents that changed, as a C array of numDocs C strings. |
| enum CBLEncryptionAlgorithm : uint32_t |
| enum CBLEncryptionKeySize : uint64_t |
| Enumerator | |
|---|---|
| kCBLEncryptionKeySizeAES256 | Key size for kCBLEncryptionAES256. |
| enum CBLMaintenanceType : uint32_t |
| bool CBL_CopyDatabase | ( | FLString | fromPath, |
| FLString | toName, | ||
| const CBLDatabaseConfiguration *_cbl_nullable | config, | ||
| CBLError *_cbl_nullable | outError ) |
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.) |
| outError | On return, will be set to the error that occurred, if applicable. |
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 NULL, name must be an absolute or relative path to the database. |
| bool CBL_DeleteDatabase | ( | FLString | name, |
| FLString | inDirectory, | ||
| CBLError *_cbl_nullable | outError ) |
Deletes a database file.
If the database file is open, an error is returned.
| name | The database name (without the ".cblite2" extension.) |
| inDirectory | The directory containing the database. If NULL, name must be an absolute or relative path to the database. |
| outError | On return, will be set to the error that occurred, or a 0 code if no error. |
outError.) | bool CBL_EnableVectorSearch | ( | FLString | path, |
| CBLError *_cbl_nullable | outError ) |
ENTERPRISE EDITION ONLY.
Enables Vector Search extension by specifying the extension path to search for the Vector Search extension library. This function must be called before opening a database that intends to use the vector search extension.
| path | The file system path of the directory that contains the Vector Search extension library. |
| outError | On return, will be set to the error that occurred. |
| _cbl_warn_unused CBLListenerToken * CBLDatabase_AddChangeListener | ( | const CBLDatabase * | db, |
| CBLDatabaseChangeListener | listener, | ||
| void *_cbl_nullable | context ) |
Registers a default collection change listener callback.
It will be called after one or more documents are changed on disk.
| db | The database to observe. |
| listener | The callback to be invoked. |
| context | An opaque value that will be passed to the callback. |
| bool CBLDatabase_BeginTransaction | ( | CBLDatabase * | , |
| CBLError *_cbl_nullable | outError ) |
Begins a transaction.
You must later call CBLDatabase_EndTransaction to commit or abort the transaction.
| bool CBLDatabase_ChangeEncryptionKey | ( | CBLDatabase * | , |
| const CBLEncryptionKey *_cbl_nullable | newKey, | ||
| CBLError * | outError ) |
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.
| bool CBLDatabase_Close | ( | CBLDatabase * | , |
| CBLError *_cbl_nullable | outError ) |
Closes an open database.
| const CBLDatabaseConfiguration CBLDatabase_Config | ( | const CBLDatabase * | ) |
Returns the database's configuration, as given when it was opened.
| uint64_t CBLDatabase_Count | ( | const CBLDatabase * | ) |
Returns the number of documents in the database, or zero if the database is closed or deleted.
| bool CBLDatabase_CreateFullTextIndex | ( | CBLDatabase * | db, |
| FLString | name, | ||
| CBLFullTextIndexConfiguration | config, | ||
| CBLError *_cbl_nullable | outError ) |
Creates a full-text index.
Indexes are persistent. If an identical index with that name already exists, nothing happens (and no error is returned.) If a non-identical index with that name already exists, it is deleted and re-created.
| bool CBLDatabase_CreateValueIndex | ( | CBLDatabase * | db, |
| FLString | name, | ||
| CBLValueIndexConfiguration | config, | ||
| CBLError *_cbl_nullable | outError ) |
Creates a value index.
Indexes are persistent. If an identical index with that name already exists, nothing happens (and no error is returned.) If a non-identical index with that name already exists, it is deleted and re-created.
| bool CBLDatabase_Delete | ( | CBLDatabase * | , |
| CBLError *_cbl_nullable | outError ) |
Closes and deletes a database.
If there are any other connections to the database, an error is returned.
| bool CBLDatabase_DeleteIndex | ( | CBLDatabase * | db, |
| FLString | name, | ||
| CBLError *_cbl_nullable | outError ) |
Deletes an index given its name.
| bool CBLDatabase_EndTransaction | ( | CBLDatabase * | , |
| bool | commit, | ||
| CBLError *_cbl_nullable | outError ) |
Ends a transaction, either committing or aborting.
| _cbl_warn_unused FLArray CBLDatabase_GetIndexNames | ( | CBLDatabase * | db | ) |
Returns the names of the indexes on this database, as a Fleece array of strings.
| FLString CBLDatabase_Name | ( | const CBLDatabase * | ) |
Returns the database's name.
| _cbl_warn_unused CBLDatabase *_cbl_nullable CBLDatabase_Open | ( | FLSlice | name, |
| const CBLDatabaseConfiguration *_cbl_nullable | config, | ||
| CBLError *_cbl_nullable | outError ) |
Opens a database, or creates it if it doesn't exist yet, returning a new CBLDatabase instance.
It's OK to open the same database file multiple times. Each CBLDatabase 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.) |
| outError | On failure, the error will be written here. |
| _cbl_warn_unused FLStringResult CBLDatabase_Path | ( | const CBLDatabase * | ) |
Returns the database's full filesystem path, or null slice if the database is closed or deleted.
| bool CBLDatabase_PerformMaintenance | ( | CBLDatabase * | db, |
| CBLMaintenanceType | type, | ||
| CBLError *_cbl_nullable | outError ) |
Performs database maintenance.
|
inlinestatic |
|
inlinestatic |
| CBLDatabaseConfiguration CBLDatabaseConfiguration_Default | ( | void | ) |
Returns the default database configuration.
| bool CBLEncryptionKey_FromPassword | ( | CBLEncryptionKey * | key, |
| FLString | password ) |
Derives an encryption key from a password.
If your UI uses passwords, call this function to create the key used to encrypt the database. It is designed for security, and deliberately runs slowly to make brute-force attacks impractical.
| key | The derived AES key will be stored here. |
| password | The input password, which can be any data. |
| bool CBLEncryptionKey_FromPasswordOld | ( | CBLEncryptionKey * | key, |
| FLString | password ) |
VOLATILE API: Derives an encryption key from a password in a way that is compatible with certain variants of Couchbase Lite in which a slightly different hashing algorithm is used.
The same notes apply as in CBLEncryptionKey_FromPassword
| key | The derived AES key will be stored here. |
| password | The input password, which can be any data. |