@hakodb/client 0.7.2 → 0.7.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +28 -0
- package/package.json +1 -1
- package/src/client.ts +28 -0
- package/src/native.ts +6 -0
package/README.md
CHANGED
|
@@ -25,3 +25,31 @@ Works against the corresponding core release; each release pairs with a matching
|
|
|
25
25
|
```
|
|
26
26
|
|
|
27
27
|
Binaries under `native/` are git-ignored.
|
|
28
|
+
|
|
29
|
+
## API guidance: query and write paths
|
|
30
|
+
|
|
31
|
+
Consumers should not have to guess which execution or write entry point to use. The core exposes one canonical executor plus advisory-deprecated wrappers and several materialization lanes with different costs.
|
|
32
|
+
|
|
33
|
+
### Execution lanes
|
|
34
|
+
|
|
35
|
+
| Lane | Returns | Use when |
|
|
36
|
+
|---|---|---|
|
|
37
|
+
| canonical executor (`hk_query_execute_ex` / SDK default) | JSON documents for an application | ordinary API calls |
|
|
38
|
+
| JSON egress (`hk_query_execute_json`) | JSON from pinned bytes, no owned document | wire/egress output |
|
|
39
|
+
| handles (`hk_query_execute_to_handles`) | borrowed document handles | engine throughput, caller reads selected fields |
|
|
40
|
+
| raw (`hk_query_execute_raw`) | pinned storage bytes | index-satisfied scans, zero decode |
|
|
41
|
+
| aggregation / explain | aggregate values or plan report | tuning and aggregate-only queries |
|
|
42
|
+
|
|
43
|
+
Do not compare a JSON-document lane with an engine-only lane and call it the same benchmark. Mark lanes without an equivalent in another engine as not applicable.
|
|
44
|
+
|
|
45
|
+
### In this repository
|
|
46
|
+
|
|
47
|
+
- Query.get({ mode: "docs" | "json" | "handles" | "raw" }) is the single entry point; getJson() is a deprecated alias
|
|
48
|
+
- queryExecuteEx is canonical; queryExecute/queryExecuteWithCancel are legacy wrappers
|
|
49
|
+
- insertJSON for one document, batch().setJSON() for bulk writes
|
|
50
|
+
- HakoConfig durability and awaitQuiescent before measuring or paging
|
|
51
|
+
|
|
52
|
+
### Further reading
|
|
53
|
+
|
|
54
|
+
- Core decision table: https://github.com/hakodb/hakodb/blob/main/docs/ffi-query-lanes.md
|
|
55
|
+
- Manual C ABI chapter: https://hakodb.github.io/manual/sdk-c-abi.html
|
package/package.json
CHANGED
package/src/client.ts
CHANGED
|
@@ -713,6 +713,29 @@ export class HakoClient {
|
|
|
713
713
|
return id;
|
|
714
714
|
}
|
|
715
715
|
|
|
716
|
+
/**
|
|
717
|
+
* Declare multiple secondary and composite indexes in one pass. Returns the
|
|
718
|
+
* composite ids in order. Use this instead of N createIndex calls when a
|
|
719
|
+
* collection is populated before its indexes are declared.
|
|
720
|
+
*/
|
|
721
|
+
async createIndexes(
|
|
722
|
+
collection: string,
|
|
723
|
+
fields: string[],
|
|
724
|
+
composites: { field: string; desc?: boolean }[][],
|
|
725
|
+
): Promise<number[]> {
|
|
726
|
+
this.assertOpen();
|
|
727
|
+
const json = this.native.engineCreateIndexes(
|
|
728
|
+
this.engine,
|
|
729
|
+
collection,
|
|
730
|
+
JSON.stringify(fields),
|
|
731
|
+
JSON.stringify(composites.map(group =>
|
|
732
|
+
group.map(f => ({ field: f.field, dir: f.desc ? 'desc' : 'asc' })),
|
|
733
|
+
)),
|
|
734
|
+
);
|
|
735
|
+
if (!json) throw new Error(`engineCreateIndexes failed: ${this.native.lastError()}`);
|
|
736
|
+
return JSON.parse(json) as number[];
|
|
737
|
+
}
|
|
738
|
+
|
|
716
739
|
async runTransaction<T>(fn: (tx: Transaction) => Promise<T>): Promise<T> {
|
|
717
740
|
this.assertOpen();
|
|
718
741
|
const tx = new Transaction(this.native, this.engine);
|
|
@@ -1110,6 +1133,11 @@ export class CollectionReference {
|
|
|
1110
1133
|
return this.client.createCompositeIndex(this.name, fields);
|
|
1111
1134
|
}
|
|
1112
1135
|
|
|
1136
|
+
/** One-pass equivalent of multiple createIndex/createCompositeIndex calls. */
|
|
1137
|
+
async createIndexes(fields: string[], composites: { field: string; desc?: boolean }[][]): Promise<number[]> {
|
|
1138
|
+
return this.client.createIndexes(this.name, fields, composites);
|
|
1139
|
+
}
|
|
1140
|
+
|
|
1113
1141
|
/** Drop indexes (v0.19.6 parity). Composite drops by the id createCompositeIndex returned. */
|
|
1114
1142
|
async dropIndex(field: string): Promise<void> {
|
|
1115
1143
|
ensureOk(this.client.nativeBindings().dropSimpleIndex(this.client.engineHandle(), this.name, field), this.client.nativeBindings(), 'dropIndex');
|
package/src/native.ts
CHANGED
|
@@ -78,6 +78,8 @@ export interface NativeBindings {
|
|
|
78
78
|
engineInsertSubDoc(engine: Handle, col: string, id: string, subCol: string, subId: string, doc: Handle): number;
|
|
79
79
|
engineGetByRef(engine: Handle, doc: Handle, fieldKey: string): Handle;
|
|
80
80
|
engineCreateIndex(engine: Handle, collection: string, fieldsJson: string): number;
|
|
81
|
+
/** One-pass declaration; returns a JSON array of composite ids or null. */
|
|
82
|
+
engineCreateIndexes(engine: Handle, collection: string, fieldsJson: string, compositesJson: string): string | null;
|
|
81
83
|
|
|
82
84
|
// Atomic Batch
|
|
83
85
|
batchNew(): Handle;
|
|
@@ -432,6 +434,7 @@ async function createBunBindings(libPath: string): Promise<NativeBindings> {
|
|
|
432
434
|
hk_engine_insert_subdoc: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring, FFIType.cstring, FFIType.cstring, FFIType.ptr], returns: FFIType.i32 },
|
|
433
435
|
hk_engine_get_by_ref: { args: [FFIType.ptr, FFIType.ptr, FFIType.cstring], returns: FFIType.ptr },
|
|
434
436
|
hk_engine_create_index: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring], returns: FFIType.u32 },
|
|
437
|
+
hk_engine_create_indexes: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring, FFIType.cstring], returns: FFIType.ptr },
|
|
435
438
|
hk_engine_create_vector_index: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring, FFIType.u32, FFIType.u32], returns: FFIType.i32 },
|
|
436
439
|
hk_engine_find_near: { args: [FFIType.ptr, FFIType.cstring, FFIType.cstring, FFIType.ptr, FFIType.usize, FFIType.usize], returns: FFIType.ptr },
|
|
437
440
|
hk_engine_create_traverse_index: { args: [FFIType.ptr, FFIType.cstring], returns: FFIType.i32 },
|
|
@@ -741,6 +744,7 @@ async function createBunBindings(libPath: string): Promise<NativeBindings> {
|
|
|
741
744
|
engineInsertSubDoc: (engine, col, id, subCol, subId, doc) => symbols.hk_engine_insert_subdoc(engine, toC(col), toC(id), toC(subCol), toC(subId), doc),
|
|
742
745
|
engineGetByRef: (engine, doc, fieldKey) => symbols.hk_engine_get_by_ref(engine, doc, toC(fieldKey)),
|
|
743
746
|
engineCreateIndex: (engine, collection, fieldsJson) => symbols.hk_engine_create_index(engine, toC(collection), toC(fieldsJson)),
|
|
747
|
+
engineCreateIndexes: (engine, collection, fieldsJson, compositesJson) => ptrToStringAndFree(symbols.hk_engine_create_indexes(engine, toC(collection), toC(fieldsJson), toC(compositesJson))),
|
|
744
748
|
|
|
745
749
|
batchNew: () => symbols.hk_batch_new(),
|
|
746
750
|
batchFree: (batch) => symbols.hk_batch_free(batch),
|
|
@@ -1110,6 +1114,7 @@ async function createNodeBindings(libPath: string): Promise<NativeBindings> {
|
|
|
1110
1114
|
hk_engine_insert_subdoc: lib.func('int hk_engine_insert_subdoc(HK_Engine* engine, const char* col, const char* id, const char* sub_col, const char* sub_id, const HK_Doc* doc)'),
|
|
1111
1115
|
hk_engine_get_by_ref: lib.func('HK_Doc* hk_engine_get_by_ref(HK_Engine* engine, const HK_Doc* doc, const char* field_key)'),
|
|
1112
1116
|
hk_engine_create_index: lib.func('uint32_t hk_engine_create_index(HK_Engine* engine, const char* collection, const char* fields_json)'),
|
|
1117
|
+
hk_engine_create_indexes: lib.func('HeapStr hk_engine_create_indexes(HK_Engine* engine, const char* collection, const char* fields_json, const char* composites_json)'),
|
|
1113
1118
|
hk_engine_create_vector_index: lib.func('int hk_engine_create_vector_index(HK_Engine* engine, const char* collection, const char* field, uint32_t dim, uint32_t metric)'),
|
|
1114
1119
|
hk_engine_find_near: lib.func('HeapStr hk_engine_find_near(HK_Engine* engine, const char* collection, const char* field, const float* vec, size_t len, size_t k)'),
|
|
1115
1120
|
hk_engine_create_traverse_index: lib.func('int hk_engine_create_traverse_index(HK_Engine* engine, const char* collection)'),
|
|
@@ -1404,6 +1409,7 @@ async function createNodeBindings(libPath: string): Promise<NativeBindings> {
|
|
|
1404
1409
|
engineInsertSubDoc: (engine, col, id, subCol, subId, doc) => fn.hk_engine_insert_subdoc(engine, col, id, subCol, subId, doc),
|
|
1405
1410
|
engineGetByRef: (engine, doc, fieldKey) => fn.hk_engine_get_by_ref(engine, doc, fieldKey),
|
|
1406
1411
|
engineCreateIndex: (engine, collection, fieldsJson) => fn.hk_engine_create_index(engine, collection, fieldsJson),
|
|
1412
|
+
engineCreateIndexes: (engine, collection, fieldsJson, compositesJson) => ptrToStringAndFree(fn.hk_engine_create_indexes(engine, collection, fieldsJson, compositesJson)),
|
|
1407
1413
|
|
|
1408
1414
|
batchNew: () => fn.hk_batch_new(),
|
|
1409
1415
|
batchFree: (batch) => fn.hk_batch_free(batch),
|