Skip to content

Commit 1568aef

Browse files
committed
chore: update couchbase-lite-c to 3.2.0
1 parent 96d0a06 commit 1568aef

File tree

124 files changed

+57518
-1384
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

124 files changed

+57518
-1384
lines changed

.DS_Store

0 Bytes
Binary file not shown.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "couchbase_lite"
3-
version = "3.1.7-0"
3+
version = "3.2.0-1"
44
# The first three numbers correspond to the Couchbase Lite C release, the fourth number corresponds to the Doctolib release
55

66
[dependencies]

libcblite-3.0.3/.DS_Store

2 KB
Binary file not shown.

libcblite-3.0.3/LICENSE.txt

Lines changed: 677 additions & 619 deletions
Large diffs are not rendered by default.

libcblite-3.0.3/include/cbl++/Base.hh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ namespace cbl {
9191

9292
CBLRefCounted* _cbl_nullable _ref;
9393

94+
friend class Extension;
9495
friend class Transaction;
9596
};
9697

libcblite-3.0.3/include/cbl++/Collection.hh

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#pragma once
2020
#include "cbl++/Base.hh"
21+
#include "cbl++/Database.hh"
2122
#include "cbl/CBLCollection.h"
2223
#include "cbl/CBLScope.h"
2324
#include "fleece/Mutable.hh"
@@ -35,6 +36,8 @@ namespace cbl {
3536
class MutableDocument;
3637
class CollectionChange;
3738
class DocumentChange;
39+
class QueryIndex;
40+
class VectorIndexConfiguration;
3841

3942
/** Conflict handler used when saving a document. */
4043
using CollectionConflictHandler = std::function<bool(MutableDocument documentBeingSaved,
@@ -61,19 +64,25 @@ namespace cbl {
6164
public:
6265
// Accessors:
6366

64-
/** The collection name. */
65-
std::string name() const {return asString(CBLCollection_Name(ref()));}
67+
/** The collection's name. */
68+
std::string name() const {return asString(CBLCollection_Name(ref()));}
6669

67-
/** The scope name. */
70+
/** The collection's fully qualified name in the '<scope-name>.<collection-name>' format. */
71+
std::string fullName() const {return asString(CBLCollection_FullName(ref()));}
72+
73+
/** The scope's name. */
6874
std::string scopeName() const {
6975
auto scope = CBLCollection_Scope(ref());
7076
auto scopeName = asString(CBLScope_Name(scope));
7177
CBLScope_Release(scope);
7278
return scopeName;
7379
}
7480

81+
/** The collection's database. */
82+
Database database() const {return Database(CBLCollection_Database(ref()));}
83+
7584
/** The number of documents in the collection. */
76-
uint64_t count() const {return CBLCollection_Count(ref());}
85+
uint64_t count() const {return CBLCollection_Count(ref());}
7786

7887
// Documents:
7988

@@ -190,6 +199,17 @@ namespace cbl {
190199
CBLError error;
191200
check(CBLCollection_CreateFullTextIndex(ref(), name, config, &error), error);
192201
}
202+
203+
#ifdef COUCHBASE_ENTERPRISE
204+
/** ENTERPRISE EDITION ONLY
205+
206+
Creatres a vector index in the collection.
207+
If an identical index with that name already exists, nothing happens (and no error is returned.)
208+
If a non-identical index with that name already exists, it is deleted and re-created.
209+
@param name The index name.
210+
@param config The vector index config. */
211+
inline void createVectorIndex(slice name, const VectorIndexConfiguration &config);
212+
#endif
193213

194214
/** Deletes an index given its name from the collection. */
195215
void deleteIndex(slice name) {
@@ -207,6 +227,9 @@ namespace cbl {
207227
return names;
208228
}
209229

230+
/** Get an index by name. If the index doesn't exist, the NULL QueryIndex object will be returned. */
231+
inline QueryIndex getIndex(slice name);
232+
210233
// Listeners:
211234

212235
/** Collection Change Listener Token */
@@ -250,6 +273,7 @@ namespace cbl {
250273

251274
friend class Database;
252275
friend class Document;
276+
friend class QueryIndex;
253277

254278
CBL_REFCOUNTED_BOILERPLATE(Collection, RefCounted, CBLCollection);
255279

@@ -311,6 +335,23 @@ namespace cbl {
311335
Collection _collection;
312336
slice _docID;
313337
};
338+
339+
// Database method bodies:
340+
341+
inline Collection Database::getCollection(slice collectionName, slice scopeName) const {
342+
CBLError error {};
343+
return Collection::adopt(CBLDatabase_Collection(ref(), collectionName, scopeName, &error), &error) ;
344+
}
345+
346+
inline Collection Database::createCollection(slice collectionName, slice scopeName) {
347+
CBLError error {};
348+
return Collection::adopt(CBLDatabase_CreateCollection(ref(), collectionName, scopeName, &error), &error) ;
349+
}
350+
351+
inline Collection Database::getDefaultCollection() const {
352+
CBLError error {};
353+
return Collection::adopt(CBLDatabase_DefaultCollection(ref(), &error), &error) ;
354+
}
314355
}
315356

316357
/** Hash function for Collection. */

libcblite-3.0.3/include/cbl++/CouchbaseLite.hh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,8 @@
2424
#include "Collection.hh"
2525
#include "Database.hh"
2626
#include "Document.hh"
27+
#include "Prediction.hh"
2728
#include "Query.hh"
29+
#include "QueryIndex.hh"
2830
#include "Replicator.hh"
31+
#include "VectorIndex.hh"

libcblite-3.0.3/include/cbl++/Database.hh

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,24 @@ namespace cbl {
4545
using ConflictHandler = std::function<bool(MutableDocument documentBeingSaved,
4646
Document conflictingDocument)>;
4747

48+
49+
#ifdef COUCHBASE_ENTERPRISE
50+
/** ENTERPRISE EDITION ONLY
51+
52+
Couchbase Lite Extension. */
53+
class Extension {
54+
public:
55+
/** Enables Vector Search extension by specifying the extension path to search for the Vector Search extension library.
56+
This function must be called before opening a database that intends to use the vector search extension.
57+
@param path The file system path of the directory that contains the Vector Search extension library.
58+
@note Must be called before opening a database that intends to use the vector search extension. */
59+
static void enableVectorSearch(slice path) {
60+
CBLError error {};
61+
RefCounted::check(CBL_EnableVectorSearch(path, &error), error);
62+
}
63+
};
64+
#endif
65+
4866
/** Couchbase Lite Database. */
4967
class Database : private RefCounted {
5068
public:
@@ -159,7 +177,7 @@ namespace cbl {
159177

160178
/** Returns the names of all existing scopes in the database.
161179
The scope exists when there is at least one collection created under the scope.
162-
The default scope is exceptional in that it will always exists even there are no collections under it.
180+
@note The default scope will always exist, containing at least the default collection.
163181
@return The names of all existing scopes in the database, or throws if an error occurred. */
164182
fleece::MutableArray getScopeNames() const {
165183
CBLError error {};
@@ -186,10 +204,7 @@ namespace cbl {
186204
@param collectionName The name of the collection.
187205
@param scopeName The name of the scope.
188206
@return A \ref Collection instance, or NULL if the collection doesn't exist, or throws if an error occurred. */
189-
inline Collection getCollection(slice collectionName, slice scopeName =kCBLDefaultScopeName) const {
190-
CBLError error {};
191-
return Collection::adopt(CBLDatabase_Collection(ref(), collectionName, scopeName, &error), &error) ;
192-
}
207+
inline Collection getCollection(slice collectionName, slice scopeName =kCBLDefaultScopeName) const;
193208

194209
/** Create a new collection.
195210
The naming rules of the collections and scopes are as follows:
@@ -201,27 +216,19 @@ namespace cbl {
201216
@param collectionName The name of the collection.
202217
@param scopeName The name of the scope.
203218
@return A \ref Collection instance, or throws if an error occurred. */
204-
inline Collection createCollection(slice collectionName, slice scopeName =kCBLDefaultScopeName) {
205-
CBLError error {};
206-
return Collection::adopt(CBLDatabase_CreateCollection(ref(), collectionName, scopeName, &error), &error) ;
207-
}
219+
inline Collection createCollection(slice collectionName, slice scopeName =kCBLDefaultScopeName);
208220

209221
/** Delete an existing collection.
222+
@note The default collection cannot be deleted.
210223
@param collectionName The name of the collection.
211224
@param scopeName The name of the scope. */
212225
inline void deleteCollection(slice collectionName, slice scopeName =kCBLDefaultScopeName) {
213226
CBLError error {};
214227
check(CBLDatabase_DeleteCollection(ref(), collectionName, scopeName, &error), error);
215228
}
216229

217-
/** Returns the default collection.
218-
@note The default collection may not exist if it was deleted.
219-
Also, the default collection cannot be recreated after being deleted.
220-
@return A \ref Collection instance, or NULL if the default collection doesn't exist, or throws if an error occurred. */
221-
inline Collection getDefaultCollection() const {
222-
CBLError error {};
223-
return Collection::adopt(CBLDatabase_DefaultCollection(ref(), &error), &error) ;
224-
}
230+
/** Returns the default collection. */
231+
inline Collection getDefaultCollection() const;
225232

226233
// Documents:
227234

@@ -448,6 +455,12 @@ namespace cbl {
448455
~Database() {
449456
clear();
450457
}
458+
459+
protected:
460+
friend class Collection;
461+
friend class Scope;
462+
463+
CBL_REFCOUNTED_WITHOUT_COPY_MOVE_BOILERPLATE(Database, RefCounted, CBLDatabase)
451464

452465
private:
453466
void open(slice& name, const CBLDatabaseConfiguration* _cbl_nullable config) {
@@ -494,8 +507,6 @@ namespace cbl {
494507

495508
std::shared_ptr<NotificationsReadyCallbackAccess> _notificationReadyCallbackAccess;
496509

497-
CBL_REFCOUNTED_WITHOUT_COPY_MOVE_BOILERPLATE(Database, RefCounted, CBLDatabase)
498-
499510
public:
500511
Database(const Database &other) noexcept
501512
:RefCounted(other)
@@ -575,7 +586,6 @@ namespace cbl {
575586

576587
CBLDatabase* _cbl_nullable _db = nullptr;
577588
};
578-
579589
}
580590

581591
CBL_ASSUME_NONNULL_END

libcblite-3.0.3/include/cbl++/Document.hh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ namespace cbl {
7171
inline MutableDocument mutableCopy() const;
7272

7373
protected:
74+
friend class Collection;
75+
friend class Database;
76+
friend class Replicator;
77+
7478
Document(CBLRefCounted* r) :RefCounted(r) { }
7579

7680
static Document adopt(const CBLDocument* _cbl_nullable d, CBLError *error) {
@@ -89,11 +93,7 @@ namespace cbl {
8993
else
9094
throw error;
9195
}
92-
93-
friend class Collection;
94-
friend class Database;
95-
friend class Replicator;
96-
96+
9797
CBL_REFCOUNTED_BOILERPLATE(Document, RefCounted, const CBLDocument)
9898
};
9999

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
//
2+
// Prediction.hh
3+
//
4+
// Copyright (c) 2024 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+
// VOLATILE API: Couchbase Lite C++ API is not finalized, and may change in
20+
// future releases.
21+
22+
#ifdef COUCHBASE_ENTERPRISE
23+
24+
#pragma once
25+
#include "cbl++/Base.hh"
26+
#include "cbl/CBLPrediction.h"
27+
#include <memory>
28+
#include <unordered_map>
29+
30+
// VOLATILE API: Couchbase Lite C++ API is not finalized, and may change in
31+
// future releases.
32+
33+
CBL_ASSUME_NONNULL_BEGIN
34+
35+
namespace cbl {
36+
/** ENTERPRISE EDITION ONLY
37+
38+
The PredictiveModel that allows to integrate machine learning model
39+
into queries via invoking query's PREDICTION() function.
40+
41+
@note The predictive index feature is not supported by Couchbase Lite for C.
42+
The Predictive Model is currently for creating vector indexes using the PREDICTION() function,
43+
which will call the specified predictive model for computing the vectors. */
44+
class PredictiveModel {
45+
public:
46+
/** Predicts and returns a mutable dictionary based on the input dictionary.
47+
Override this function for the implementation.
48+
@param input The input dictionary corresponding to the input dictionary expression given in the query's PREDICTION() function
49+
@return The output dictionary.
50+
- To create a new dictionary for returning, use fleece::MutableDict::newDict().
51+
- To create a null result to evaluate as MISSING, use fleece::MutableDict(). */
52+
virtual fleece::MutableDict prediction(fleece::Dict input) noexcept = 0;
53+
54+
virtual ~PredictiveModel() = default;
55+
};
56+
57+
static std::unordered_map<slice, std::unique_ptr<PredictiveModel>> _sPredictiveModels;
58+
59+
/** Predictive Model Registation
60+
This class provides static methods to register and unregister predictive models. */
61+
class Prediction {
62+
public:
63+
/** Registers a predictive model with the given name. */
64+
static void registerModel(slice name, std::unique_ptr<PredictiveModel> model) {
65+
auto prediction = [](void* context, FLDict input) {
66+
auto m = (PredictiveModel*)context;
67+
return FLMutableDict_Retain((FLMutableDict) m->prediction(input));
68+
};
69+
70+
CBLPredictiveModel config { };
71+
config.context = model.get();
72+
config.prediction = prediction;
73+
CBL_RegisterPredictiveModel(name, config);
74+
75+
_sPredictiveModels[name] = std::move(model);
76+
}
77+
78+
/** Unregisters the predictive model with the given name. */
79+
static void unregisterModel(slice name) {
80+
CBL_UnregisterPredictiveModel(name);
81+
_sPredictiveModels.erase(name);
82+
}
83+
};
84+
}
85+
86+
CBL_ASSUME_NONNULL_END
87+
88+
#endif

0 commit comments

Comments
 (0)