Couchbase Lite C
Couchbase Lite C API
CBLDatabase.h
Go to the documentation of this file.
1//
2// CBLDatabase.h
3//
4// Copyright (c) 2018 Couchbase, Inc All rights reserved.
5//
6// Licensed under the Apache License, Version 2.0 (the "License");
7// you may not use this file except in compliance with the License.
8// You may obtain a copy of the License at
9//
10// http://www.apache.org/licenses/LICENSE-2.0
11//
12// Unless required by applicable law or agreed to in writing, software
13// distributed under the License is distributed on an "AS IS" BASIS,
14// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15// See the License for the specific language governing permissions and
16// limitations under the License.
17//
18
19#pragma once
20#include "CBLBase.h"
21#include "CBLQueryIndexTypes.h"
22
24
30#ifdef COUCHBASE_ENTERPRISE
31
32#ifdef __APPLE__
33#pragma mark - Database Extension
34#endif
35
48
51#endif
52
53#ifdef __APPLE__
54#pragma mark - CONFIGURATION
55#endif
56
60#ifdef COUCHBASE_ENTERPRISE
62typedef CBL_ENUM(uint32_t, CBLEncryptionAlgorithm) {
65};
66
68typedef CBL_ENUM(uint64_t, CBLEncryptionKeySize) {
70};
71
73typedef struct {
75 uint8_t bytes[32];
77#endif
78
80typedef struct {
82#ifdef COUCHBASE_ENTERPRISE
84#endif
95
103
106
107#ifdef COUCHBASE_ENTERPRISE
115
123#endif
124
128#ifdef __APPLE__
129#pragma mark - FILE OPERATIONS
130#endif
141
150 FLString toName,
152 CBLError* _cbl_nullable outError) CBLAPI;
153
162 FLString inDirectory,
163 CBLError* _cbl_nullable outError) CBLAPI;
164
168#ifdef __APPLE__
169#pragma mark - LIFECYCLE
170#endif
187 CBLError* _cbl_nullable outError) CBLAPI;
188
191 CBLError* _cbl_nullable outError) CBLAPI;
192
194
198 CBLError* _cbl_nullable outError) CBLAPI;
199
207 CBLError* _cbl_nullable outError) CBLAPI;
208
211 bool commit,
212 CBLError* _cbl_nullable outError) CBLAPI;
213
214#ifdef COUCHBASE_ENTERPRISE
221 const CBLEncryptionKey* _cbl_nullable newKey,
222 CBLError* outError) CBLAPI;
223#endif
224
226typedef CBL_ENUM(uint32_t, CBLMaintenanceType) {
229
232
235
239
245
249 CBLError* _cbl_nullable outError) CBLAPI;
250
253#ifdef __APPLE__
254#pragma mark - ACCESSORS
255#endif
263
267
271
274
288 FLString name,
290 CBLError* _cbl_nullable outError) CBLAPI;
291
298 FLString name,
300 CBLError* _cbl_nullable outError) CBLAPI;
301
305 FLString name,
306 CBLError* _cbl_nullable outError) CBLAPI;
307
313
314
317#ifdef __APPLE__
318#pragma mark - LISTENERS
319#endif
337typedef void (*CBLDatabaseChangeListener)(void* _cbl_nullable context,
338 const CBLDatabase* db,
339 unsigned numDocs,
340 FLString docIDs[_cbl_nonnull]);
341
352 void* _cbl_nullable context) CBLAPI;
353 // end of outer \defgroup
356
357
358#ifdef __APPLE__
359#pragma mark - NOTIFICATION SCHEDULING
360#endif
384typedef void (*CBLNotificationsReadyCallback)(void* _cbl_nullable context,
385 CBLDatabase* db);
386
395 void* _cbl_nullable context) CBLAPI;
396
400 // end of outer \defgroup
403
#define CBLAPI
Definition: CBL_Compat.h:104
#define _cbl_nullable
Definition: CBL_Compat.h:92
#define CBL_CAPI_BEGIN
Definition: CBL_Compat.h:105
#define CBL_CAPI_END
Definition: CBL_Compat.h:106
#define CBL_ENUM(_type, _name)
Definition: CBL_Compat.h:62
#define _cbl_warn_unused
Definition: CBL_Compat.h:40
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 t...
_cbl_warn_unused FLArray CBLDatabase_GetIndexNames(CBLDatabase *db)
Returns the names of the indexes on this database, as a Fleece array of strings.
bool CBLDatabase_EndTransaction(CBLDatabase *, bool commit, CBLError *_cbl_nullable outError)
Ends a transaction, either committing or aborting.
struct CBLDatabase CBLDatabase
A connection to an open database.
Definition: CBLBase.h:182
bool CBLEncryptionKey_FromPassword(CBLEncryptionKey *key, FLString password)
Derives an encryption key from a password.
bool CBLDatabase_Delete(CBLDatabase *, CBLError *_cbl_nullable outError)
Closes and deletes a database.
bool CBLDatabase_Close(CBLDatabase *, CBLError *_cbl_nullable outError)
Closes an open database.
bool CBL_DatabaseExists(FLString name, FLString inDirectory)
Returns true if a database with the given name exists in the given directory.
bool CBLDatabase_ChangeEncryptionKey(CBLDatabase *, const CBLEncryptionKey *_cbl_nullable newKey, CBLError *outError)
Encrypts or decrypts a database, or changes its encryption key.
_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.
bool CBLDatabase_CreateFullTextIndex(CBLDatabase *db, FLString name, CBLFullTextIndexConfiguration config, CBLError *_cbl_nullable outError)
Creates a full-text index.
bool CBL_DeleteDatabase(FLString name, FLString inDirectory, CBLError *_cbl_nullable outError)
Deletes a database file.
const CBLDatabaseConfiguration CBLDatabase_Config(const CBLDatabase *)
Returns the database's configuration, as given when it was opened.
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 col...
Definition: CBLDatabase.h:337
_cbl_warn_unused CBLListenerToken * CBLDatabase_AddChangeListener(const CBLDatabase *db, CBLDatabaseChangeListener listener, void *_cbl_nullable context)
Registers a default collection change listener callback.
CBLEncryptionAlgorithm
Database encryption algorithms (available only in the Enterprise Edition).
Definition: CBLDatabase.h:62
bool CBLDatabase_PerformMaintenance(CBLDatabase *db, CBLMaintenanceType type, CBLError *_cbl_nullable outError)
Performs database maintenance.
_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.
CBLDatabaseConfiguration CBLDatabaseConfiguration_Default(void)
Returns the default database configuration.
CBLMaintenanceType
Maintenance Type used when performing database maintenance.
Definition: CBLDatabase.h:226
bool CBLDatabase_BeginTransaction(CBLDatabase *, CBLError *_cbl_nullable outError)
Begins a transaction.
uint64_t CBLDatabase_Count(const CBLDatabase *)
Returns the number of documents in the database, or zero if the database is closed or deleted.
bool CBL_EnableVectorSearch(FLString path, CBLError *_cbl_nullable outError)
ENTERPRISE EDITION ONLY.
bool CBLEncryptionKey_FromPasswordOld(CBLEncryptionKey *key, FLString password)
VOLATILE API: Derives an encryption key from a password in a way that is compatible with certain vari...
bool CBLDatabase_DeleteIndex(CBLDatabase *db, FLString name, CBLError *_cbl_nullable outError)
Deletes an index given its name.
bool CBLDatabase_CreateValueIndex(CBLDatabase *db, FLString name, CBLValueIndexConfiguration config, CBLError *_cbl_nullable outError)
Creates a value index.
CBLEncryptionKeySize
Encryption key sizes (in bytes).
Definition: CBLDatabase.h:68
FLString CBLDatabase_Name(const CBLDatabase *)
Returns the database's name.
@ kCBLEncryptionNone
No encryption (default)
Definition: CBLDatabase.h:63
@ kCBLEncryptionAES256
AES with 256-bit key.
Definition: CBLDatabase.h:64
@ kCBLMaintenanceTypeIntegrityCheck
Check for the database’s corruption. If found, an error will be returned.
Definition: CBLDatabase.h:234
@ kCBLMaintenanceTypeCompact
Compact the database file and delete unused attachments.
Definition: CBLDatabase.h:228
@ kCBLMaintenanceTypeOptimize
Partially scan indexes to gather database statistics that help optimize queries.
Definition: CBLDatabase.h:238
@ kCBLMaintenanceTypeReindex
Rebuild the entire database's indexes.
Definition: CBLDatabase.h:231
@ kCBLMaintenanceTypeFullOptimize
Fully scans all indexes to gather database statistics that help optimize queries.
Definition: CBLDatabase.h:243
@ kCBLEncryptionKeySizeAES256
Key size for kCBLEncryptionAES256.
Definition: CBLDatabase.h:69
void(* CBLNotificationsReadyCallback)(void *_cbl_nullable context, CBLDatabase *db)
Callback indicating that the database (or an object belonging to it) is ready to call one or more lis...
Definition: CBLDatabase.h:384
void CBLDatabase_SendNotifications(CBLDatabase *db)
Immediately issues all pending notifications for this database, by calling their listener callbacks.
void CBLDatabase_BufferNotifications(CBLDatabase *db, CBLNotificationsReadyCallback _cbl_nullable callback, void *_cbl_nullable context)
Switches the database to buffered-notification mode.
struct CBLListenerToken CBLListenerToken
An opaque 'cookie' representing a registered listener callback.
Definition: CBLBase.h:281
#define CBL_REFCOUNTED(TYPE, NAME)
Definition: CBLBase.h:170
const struct _FLArray * FLArray
A reference to an array value.
Definition: FLBase.h:36
Database configuration options.
Definition: CBLDatabase.h:80
bool fullSync
As Couchbase Lite normally configures its databases, There is a very small (though non-zero) chance t...
Definition: CBLDatabase.h:94
bool mmapDisabled
Disable memory-mapped I/O.
Definition: CBLDatabase.h:101
FLString directory
The parent directory of the database.
Definition: CBLDatabase.h:81
CBLEncryptionKey encryptionKey
The database's encryption key (if any)
Definition: CBLDatabase.h:83
Encryption key specified in a CBLDatabaseConfiguration.
Definition: CBLDatabase.h:73
CBLEncryptionAlgorithm algorithm
Encryption algorithm.
Definition: CBLDatabase.h:74
A struct holding information about an error.
Definition: CBLBase.h:104
Full-Text Index Configuration.
Definition: CBLQueryIndexTypes.h:42
Value Index Configuration.
Definition: CBLQueryIndexTypes.h:32
A simple reference to a block of memory.
Definition: FLSlice.h:45
A heap-allocated block of memory returned from an API call.
Definition: FLSlice.h:63