Things to watch for include:
If the named database does not exist in the specified, or default, location then a new one is created
Best Practice is to always specify the path to the database explicitly.
Typically, the default location for C is the application sandbox or current working directory .
See also Finding a Database File.
// NOTE: No error handling, for brevity (see getting started) CBLError err; CBLDatabase* db = CBLDatabase_Open(FLSTR("my-database"), NULL, &err);
You are advised to incorporate the closing of all open databases into your application workflow.
Closing a database soon after starting a replication involving it can cause an exception as the asynchronous
// NOTE: No error handling, for brevity (see getting started) CBLError err; CBLDatabase_Close(db, &err);
|This is an Enterprise Edition feature.|
Couchbase Lite on C includes the ability to encrypt Couchbase Lite databases. This allows mobile applications to secure the data at rest, when it is being stored on the device. The algorithm used to encrypt the database is 256-bit AES.
// NOTE: No error handling, for brevity (see getting started) CBLDatabaseConfiguration config = CBLDatabaseConfiguration_Default(); // This returns a boolean, so check it in production code CBLEncryptionKey_FromPassword(&config.encryptionKey, FLSTR("password")); CBLError err; CBLDatabase* db = CBLDatabase_Open(FLSTR("seekrit"), &config, &err); // Change the encryption key (or add encryption if the DB is unencrypted) CBLEncryptionKey betterKey; CBLEncryptionKey_FromPassword(&betterKey, FLSTR("betterpassw0rd")); CBLDatabase_ChangeEncryptionKey(db, &betterKey, &err); // Remove encryption CBLDatabase_ChangeEncryptionKey(db, NULL, &err);
An encrypted database can only be opened with the same language SDK that was used to encrypt it in the first place. So a database encrypted using the C SDK, and then exported, is readable only by the C SDK.
To change an existing encryption key, open the database using its existing encryption-key and use CBLDatabase_ChangeEncryptionKey() to set the required new encryption-key value.
To remove encryption, open the database using its existing encryption-key and use CBLDatabase_ChangeEncryptionKey() with a null value as the encryption key.
To upgrade an encrypted database see: Upgrade 1.x databases
When the application is running on the iOS simulator, you can locate the application’s sandbox directory using the SimPholders utility.
From time to time it may be necessary to perform certain maintenance activities on your database, for example to compact the database file, removing unused documents and blobs no longer referenced by any documents.
This is a resource intensive operation and is not performed automatically. It should be run on-demand using the API. If in doubt, consult Couchbase support.