Skip to content

Commit ecce13a

Browse files
committed
include
1 parent 37dfd28 commit ecce13a

Some content is hidden

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

43 files changed

+1344
-275
lines changed

libcblite-3.0.3/.DS_Store

0 Bytes
Binary file not shown.

libcblite-3.0.3/include/.DS_Store

0 Bytes
Binary file not shown.

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: 56 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,28 @@ namespace cbl {
190199
CBLError error;
191200
check(CBLCollection_CreateFullTextIndex(ref(), name, config, &error), error);
192201
}
202+
203+
/** Creates an array index for use with UNNEST queries in the collection.
204+
Indexes are persistent.
205+
If an identical index with that name already exists, nothing happens (and no error is returned.)
206+
If a non-identical index with that name already exists, it is deleted and re-created.
207+
@param name The index name.
208+
@param config The array index config. */
209+
void createArrayIndex(slice name, CBLArrayIndexConfiguration config) {
210+
CBLError error;
211+
check(CBLCollection_CreateArrayIndex(ref(), name, config, &error), error);
212+
}
213+
214+
#ifdef COUCHBASE_ENTERPRISE
215+
/** ENTERPRISE EDITION ONLY
216+
217+
Creatres a vector index in the collection.
218+
If an identical index with that name already exists, nothing happens (and no error is returned.)
219+
If a non-identical index with that name already exists, it is deleted and re-created.
220+
@param name The index name.
221+
@param config The vector index config. */
222+
inline void createVectorIndex(slice name, const VectorIndexConfiguration &config);
223+
#endif
193224

194225
/** Deletes an index given its name from the collection. */
195226
void deleteIndex(slice name) {
@@ -207,6 +238,9 @@ namespace cbl {
207238
return names;
208239
}
209240

241+
/** Get an index by name. If the index doesn't exist, the NULL QueryIndex object will be returned. */
242+
inline QueryIndex getIndex(slice name);
243+
210244
// Listeners:
211245

212246
/** Collection Change Listener Token */
@@ -250,6 +284,7 @@ namespace cbl {
250284

251285
friend class Database;
252286
friend class Document;
287+
friend class QueryIndex;
253288

254289
CBL_REFCOUNTED_BOILERPLATE(Collection, RefCounted, CBLCollection);
255290

@@ -311,6 +346,23 @@ namespace cbl {
311346
Collection _collection;
312347
slice _docID;
313348
};
349+
350+
// Database method bodies:
351+
352+
inline Collection Database::getCollection(slice collectionName, slice scopeName) const {
353+
CBLError error {};
354+
return Collection::adopt(CBLDatabase_Collection(ref(), collectionName, scopeName, &error), &error) ;
355+
}
356+
357+
inline Collection Database::createCollection(slice collectionName, slice scopeName) {
358+
CBLError error {};
359+
return Collection::adopt(CBLDatabase_CreateCollection(ref(), collectionName, scopeName, &error), &error) ;
360+
}
361+
362+
inline Collection Database::getDefaultCollection() const {
363+
CBLError error {};
364+
return Collection::adopt(CBLDatabase_DefaultCollection(ref(), &error), &error) ;
365+
}
314366
}
315367

316368
/** 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: 27 additions & 15 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:
@@ -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,10 +216,7 @@ 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.
210222
@note The default collection cannot be deleted.
@@ -216,10 +228,7 @@ namespace cbl {
216228
}
217229

218230
/** Returns the default collection. */
219-
inline Collection getDefaultCollection() const {
220-
CBLError error {};
221-
return Collection::adopt(CBLDatabase_DefaultCollection(ref(), &error), &error) ;
222-
}
231+
inline Collection getDefaultCollection() const;
223232

224233
// Documents:
225234

@@ -446,6 +455,12 @@ namespace cbl {
446455
~Database() {
447456
clear();
448457
}
458+
459+
protected:
460+
friend class Collection;
461+
friend class Scope;
462+
463+
CBL_REFCOUNTED_WITHOUT_COPY_MOVE_BOILERPLATE(Database, RefCounted, CBLDatabase)
449464

450465
private:
451466
void open(slice& name, const CBLDatabaseConfiguration* _cbl_nullable config) {
@@ -492,8 +507,6 @@ namespace cbl {
492507

493508
std::shared_ptr<NotificationsReadyCallbackAccess> _notificationReadyCallbackAccess;
494509

495-
CBL_REFCOUNTED_WITHOUT_COPY_MOVE_BOILERPLATE(Database, RefCounted, CBLDatabase)
496-
497510
public:
498511
Database(const Database &other) noexcept
499512
:RefCounted(other)
@@ -573,7 +586,6 @@ namespace cbl {
573586

574587
CBLDatabase* _cbl_nullable _db = nullptr;
575588
};
576-
577589
}
578590

579591
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)