quiverdb 0.5.0 → 0.6.1

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.
Files changed (76) hide show
  1. package/README.md +108 -108
  2. package/dist/composites.d.ts +9 -0
  3. package/dist/composites.d.ts.map +1 -0
  4. package/dist/composites.js +69 -0
  5. package/dist/composites.js.map +1 -0
  6. package/dist/create.d.ts +9 -0
  7. package/dist/create.d.ts.map +1 -0
  8. package/dist/create.js +104 -0
  9. package/dist/create.js.map +1 -0
  10. package/dist/csv.d.ts +11 -0
  11. package/dist/csv.d.ts.map +1 -0
  12. package/dist/csv.js +67 -0
  13. package/dist/csv.js.map +1 -0
  14. package/dist/database.d.ts +13 -0
  15. package/dist/database.d.ts.map +1 -0
  16. package/dist/database.js +42 -0
  17. package/dist/database.js.map +1 -0
  18. package/dist/errors.d.ts +5 -0
  19. package/dist/errors.d.ts.map +1 -0
  20. package/dist/errors.js +18 -0
  21. package/dist/errors.js.map +1 -0
  22. package/dist/ffi-helpers.d.ts +57 -0
  23. package/dist/ffi-helpers.d.ts.map +1 -0
  24. package/dist/ffi-helpers.js +136 -0
  25. package/dist/ffi-helpers.js.map +1 -0
  26. package/dist/index.d.ts +17 -0
  27. package/dist/index.d.ts.map +1 -0
  28. package/dist/index.js +13 -0
  29. package/dist/index.js.map +1 -0
  30. package/dist/introspection.d.ts +10 -0
  31. package/dist/introspection.d.ts.map +1 -0
  32. package/dist/introspection.js +27 -0
  33. package/dist/introspection.js.map +1 -0
  34. package/dist/loader.d.ts +7 -0
  35. package/dist/loader.d.ts.map +1 -0
  36. package/dist/loader.js +165 -0
  37. package/dist/loader.js.map +1 -0
  38. package/dist/lua-runner.d.ts +11 -0
  39. package/dist/lua-runner.d.ts.map +1 -0
  40. package/dist/lua-runner.js +43 -0
  41. package/dist/lua-runner.js.map +1 -0
  42. package/dist/metadata.d.ts +28 -0
  43. package/dist/metadata.d.ts.map +1 -0
  44. package/dist/metadata.js +100 -0
  45. package/dist/metadata.js.map +1 -0
  46. package/dist/query.d.ts +9 -0
  47. package/dist/query.d.ts.map +1 -0
  48. package/dist/query.js +90 -0
  49. package/dist/query.js.map +1 -0
  50. package/dist/read.d.ts +25 -0
  51. package/dist/read.d.ts.map +1 -0
  52. package/dist/read.js +220 -0
  53. package/dist/read.js.map +1 -0
  54. package/dist/time-series.d.ts +12 -0
  55. package/dist/time-series.d.ts.map +1 -0
  56. package/dist/time-series.js +155 -0
  57. package/dist/time-series.js.map +1 -0
  58. package/dist/transaction.d.ts +10 -0
  59. package/dist/transaction.d.ts.map +1 -0
  60. package/dist/transaction.js +22 -0
  61. package/dist/transaction.js.map +1 -0
  62. package/{src/types.ts → dist/types.d.ts} +1 -0
  63. package/dist/types.d.ts.map +1 -0
  64. package/dist/types.js +2 -0
  65. package/dist/types.js.map +1 -0
  66. package/package.json +24 -16
  67. package/src/create.ts +0 -128
  68. package/src/database.ts +0 -68
  69. package/src/errors.ts +0 -24
  70. package/src/ffi-helpers.ts +0 -48
  71. package/src/index.ts +0 -8
  72. package/src/loader.ts +0 -286
  73. package/src/query.ts +0 -164
  74. package/src/read.ts +0 -231
  75. package/src/transaction.ts +0 -35
  76. package/tsconfig.json +0 -13
package/src/loader.ts DELETED
@@ -1,286 +0,0 @@
1
- import { dlopen, FFIType, suffix } from "bun:ffi";
2
- import { existsSync } from "node:fs";
3
- import { dirname, join } from "node:path";
4
- import { QuiverError } from "./errors";
5
-
6
- const CORE_LIB = `libquiver.${suffix}`;
7
- const C_API_LIB = `libquiver_c.${suffix}`;
8
-
9
- /**
10
- * Pre-load a DLL on Windows using kernel32 LoadLibraryA.
11
- * bun:ffi dlopen() requires at least one symbol, so it cannot be used
12
- * for dependency-only pre-loading (libquiver.dll has no C API symbols).
13
- * This is the equivalent of Python's os.add_dll_directory() approach.
14
- */
15
- function preloadWindows(dllPath: string): void {
16
- const kernel32 = dlopen("kernel32.dll", {
17
- LoadLibraryA: { args: [FFIType.ptr], returns: FFIType.ptr },
18
- });
19
- kernel32.symbols.LoadLibraryA(Buffer.from(`${dllPath}\0`));
20
- }
21
-
22
- const symbols = {
23
- quiver_version: {
24
- args: [],
25
- returns: FFIType.cstring,
26
- },
27
- quiver_get_last_error: {
28
- args: [],
29
- returns: FFIType.ptr,
30
- },
31
- quiver_clear_last_error: {
32
- args: [],
33
- returns: FFIType.void,
34
- },
35
- quiver_database_from_schema: {
36
- args: [FFIType.ptr, FFIType.ptr, FFIType.ptr, FFIType.ptr],
37
- returns: FFIType.i32,
38
- },
39
- quiver_database_from_migrations: {
40
- args: [FFIType.ptr, FFIType.ptr, FFIType.ptr, FFIType.ptr],
41
- returns: FFIType.i32,
42
- },
43
- quiver_database_close: {
44
- args: [FFIType.ptr],
45
- returns: FFIType.i32,
46
- },
47
-
48
- // Element lifecycle
49
- quiver_element_create: {
50
- args: [FFIType.ptr],
51
- returns: FFIType.i32,
52
- },
53
- quiver_element_destroy: {
54
- args: [FFIType.ptr],
55
- returns: FFIType.i32,
56
- },
57
-
58
- // Element scalar setters
59
- quiver_element_set_integer: {
60
- args: [FFIType.ptr, FFIType.ptr, FFIType.i64],
61
- returns: FFIType.i32,
62
- },
63
- quiver_element_set_float: {
64
- args: [FFIType.ptr, FFIType.ptr, FFIType.f64],
65
- returns: FFIType.i32,
66
- },
67
- quiver_element_set_string: {
68
- args: [FFIType.ptr, FFIType.ptr, FFIType.ptr],
69
- returns: FFIType.i32,
70
- },
71
- quiver_element_set_null: {
72
- args: [FFIType.ptr, FFIType.ptr],
73
- returns: FFIType.i32,
74
- },
75
-
76
- // Element array setters
77
- quiver_element_set_array_integer: {
78
- args: [FFIType.ptr, FFIType.ptr, FFIType.ptr, FFIType.i32],
79
- returns: FFIType.i32,
80
- },
81
- quiver_element_set_array_float: {
82
- args: [FFIType.ptr, FFIType.ptr, FFIType.ptr, FFIType.i32],
83
- returns: FFIType.i32,
84
- },
85
- quiver_element_set_array_string: {
86
- args: [FFIType.ptr, FFIType.ptr, FFIType.ptr, FFIType.i32],
87
- returns: FFIType.i32,
88
- },
89
-
90
- // Database CRUD
91
- quiver_database_create_element: {
92
- args: [FFIType.ptr, FFIType.ptr, FFIType.ptr, FFIType.ptr],
93
- returns: FFIType.i32,
94
- },
95
- quiver_database_delete_element: {
96
- args: [FFIType.ptr, FFIType.ptr, FFIType.i64],
97
- returns: FFIType.i32,
98
- },
99
-
100
- // Read scalar arrays
101
- quiver_database_read_scalar_integers: {
102
- args: [FFIType.ptr, FFIType.ptr, FFIType.ptr, FFIType.ptr, FFIType.ptr],
103
- returns: FFIType.i32,
104
- },
105
- quiver_database_read_scalar_floats: {
106
- args: [FFIType.ptr, FFIType.ptr, FFIType.ptr, FFIType.ptr, FFIType.ptr],
107
- returns: FFIType.i32,
108
- },
109
- quiver_database_read_scalar_strings: {
110
- args: [FFIType.ptr, FFIType.ptr, FFIType.ptr, FFIType.ptr, FFIType.ptr],
111
- returns: FFIType.i32,
112
- },
113
-
114
- // Read scalar by ID
115
- quiver_database_read_scalar_integer_by_id: {
116
- args: [FFIType.ptr, FFIType.ptr, FFIType.ptr, FFIType.i64, FFIType.ptr, FFIType.ptr],
117
- returns: FFIType.i32,
118
- },
119
- quiver_database_read_scalar_float_by_id: {
120
- args: [FFIType.ptr, FFIType.ptr, FFIType.ptr, FFIType.i64, FFIType.ptr, FFIType.ptr],
121
- returns: FFIType.i32,
122
- },
123
- quiver_database_read_scalar_string_by_id: {
124
- args: [FFIType.ptr, FFIType.ptr, FFIType.ptr, FFIType.i64, FFIType.ptr, FFIType.ptr],
125
- returns: FFIType.i32,
126
- },
127
-
128
- // Read element IDs
129
- quiver_database_read_element_ids: {
130
- args: [FFIType.ptr, FFIType.ptr, FFIType.ptr, FFIType.ptr],
131
- returns: FFIType.i32,
132
- },
133
-
134
- // Free functions
135
- quiver_database_free_integer_array: {
136
- args: [FFIType.ptr],
137
- returns: FFIType.i32,
138
- },
139
- quiver_database_free_float_array: {
140
- args: [FFIType.ptr],
141
- returns: FFIType.i32,
142
- },
143
- quiver_database_free_string_array: {
144
- args: [FFIType.ptr, FFIType.u64],
145
- returns: FFIType.i32,
146
- },
147
- quiver_database_free_string: {
148
- args: [FFIType.ptr],
149
- returns: FFIType.i32,
150
- },
151
-
152
- // Query operations (plain)
153
- quiver_database_query_string: {
154
- args: [FFIType.ptr, FFIType.ptr, FFIType.ptr, FFIType.ptr],
155
- returns: FFIType.i32,
156
- },
157
- quiver_database_query_integer: {
158
- args: [FFIType.ptr, FFIType.ptr, FFIType.ptr, FFIType.ptr],
159
- returns: FFIType.i32,
160
- },
161
- quiver_database_query_float: {
162
- args: [FFIType.ptr, FFIType.ptr, FFIType.ptr, FFIType.ptr],
163
- returns: FFIType.i32,
164
- },
165
-
166
- // Query operations (parameterized)
167
- quiver_database_query_string_params: {
168
- args: [
169
- FFIType.ptr,
170
- FFIType.ptr,
171
- FFIType.ptr,
172
- FFIType.ptr,
173
- FFIType.u64,
174
- FFIType.ptr,
175
- FFIType.ptr,
176
- ],
177
- returns: FFIType.i32,
178
- },
179
- quiver_database_query_integer_params: {
180
- args: [
181
- FFIType.ptr,
182
- FFIType.ptr,
183
- FFIType.ptr,
184
- FFIType.ptr,
185
- FFIType.u64,
186
- FFIType.ptr,
187
- FFIType.ptr,
188
- ],
189
- returns: FFIType.i32,
190
- },
191
- quiver_database_query_float_params: {
192
- args: [
193
- FFIType.ptr,
194
- FFIType.ptr,
195
- FFIType.ptr,
196
- FFIType.ptr,
197
- FFIType.u64,
198
- FFIType.ptr,
199
- FFIType.ptr,
200
- ],
201
- returns: FFIType.i32,
202
- },
203
-
204
- // Transaction control
205
- quiver_database_begin_transaction: {
206
- args: [FFIType.ptr],
207
- returns: FFIType.i32,
208
- },
209
- quiver_database_commit: {
210
- args: [FFIType.ptr],
211
- returns: FFIType.i32,
212
- },
213
- quiver_database_rollback: {
214
- args: [FFIType.ptr],
215
- returns: FFIType.i32,
216
- },
217
- quiver_database_in_transaction: {
218
- args: [FFIType.ptr, FFIType.ptr],
219
- returns: FFIType.i32,
220
- },
221
- } as const;
222
-
223
- type Library = ReturnType<typeof dlopen<typeof symbols>>;
224
-
225
- let _library: Library | null = null;
226
-
227
- function getSearchPaths(): string[] {
228
- const paths: string[] = [];
229
-
230
- // Walk up from import.meta.dir (bindings/js/src/) looking for build/bin/
231
- let dir = import.meta.dir;
232
- for (let i = 0; i < 5; i++) {
233
- const candidate = join(dir, "build", "bin");
234
- if (existsSync(join(candidate, C_API_LIB))) {
235
- paths.push(candidate);
236
- }
237
- dir = dirname(dir);
238
- }
239
-
240
- return paths;
241
- }
242
-
243
- export function loadLibrary(): Library {
244
- if (_library) return _library;
245
-
246
- const searchPaths = getSearchPaths();
247
-
248
- for (const dir of searchPaths) {
249
- const corePath = join(dir, CORE_LIB);
250
- const cApiPath = join(dir, C_API_LIB);
251
- if (!existsSync(cApiPath)) continue;
252
-
253
- try {
254
- // Windows: pre-load core library (dependency chain)
255
- if (suffix === "dll" && existsSync(corePath)) {
256
- preloadWindows(corePath);
257
- }
258
- _library = dlopen(cApiPath, symbols);
259
- return _library;
260
- } catch {}
261
- }
262
-
263
- // Fallback: try system PATH (bare library name)
264
- try {
265
- if (suffix === "dll") {
266
- try {
267
- preloadWindows(CORE_LIB);
268
- } catch {
269
- // Core lib may already be loaded or not needed on this platform
270
- }
271
- }
272
- _library = dlopen(C_API_LIB, symbols);
273
- return _library;
274
- } catch {
275
- // Fall through to error
276
- }
277
-
278
- const searched =
279
- searchPaths.length > 0 ? `${searchPaths.join(", ")}, system PATH` : "system PATH";
280
-
281
- throw new QuiverError(`Cannot load native library '${C_API_LIB}'. Searched: ${searched}`);
282
- }
283
-
284
- export function getSymbols(): Library["symbols"] {
285
- return loadLibrary().symbols;
286
- }
package/src/query.ts DELETED
@@ -1,164 +0,0 @@
1
- import { CString, ptr } from "bun:ffi";
2
- import { Database } from "./database";
3
- import { check } from "./errors";
4
- import { allocPointerOut, readPointerOut, toCString } from "./ffi-helpers";
5
- import { getSymbols } from "./loader";
6
- import type { QueryParam } from "./types";
7
-
8
- declare module "./database" {
9
- interface Database {
10
- queryString(sql: string, params?: QueryParam[]): string | null;
11
- queryInteger(sql: string, params?: QueryParam[]): number | null;
12
- queryFloat(sql: string, params?: QueryParam[]): number | null;
13
- }
14
- }
15
-
16
- // C API data type enum values (from include/quiver/c/database.h)
17
- const DATA_TYPE_INTEGER = 0;
18
- const DATA_TYPE_FLOAT = 1;
19
- const DATA_TYPE_STRING = 2;
20
- const DATA_TYPE_NULL = 4;
21
-
22
- interface MarshaledParams {
23
- types: Int32Array;
24
- values: BigInt64Array;
25
- _keepalive: unknown[];
26
- }
27
-
28
- function marshalParams(params: QueryParam[]): MarshaledParams {
29
- const n = params.length;
30
- const types = new Int32Array(n);
31
- const values = new BigInt64Array(n);
32
- const keepalive: unknown[] = [];
33
-
34
- for (let i = 0; i < n; i++) {
35
- const p = params[i];
36
- if (p === null) {
37
- types[i] = DATA_TYPE_NULL;
38
- values[i] = 0n;
39
- } else if (typeof p === "number") {
40
- if (Number.isInteger(p)) {
41
- types[i] = DATA_TYPE_INTEGER;
42
- const buf = new BigInt64Array([BigInt(p)]);
43
- keepalive.push(buf);
44
- values[i] = BigInt(ptr(buf));
45
- } else {
46
- types[i] = DATA_TYPE_FLOAT;
47
- const buf = new Float64Array([p]);
48
- keepalive.push(buf);
49
- values[i] = BigInt(ptr(buf));
50
- }
51
- } else if (typeof p === "string") {
52
- types[i] = DATA_TYPE_STRING;
53
- const buf = toCString(p);
54
- keepalive.push(buf);
55
- values[i] = BigInt(ptr(buf));
56
- }
57
- }
58
-
59
- return { types, values, _keepalive: keepalive };
60
- }
61
-
62
- Database.prototype.queryString = function (
63
- this: Database,
64
- sql: string,
65
- params?: QueryParam[],
66
- ): string | null {
67
- const lib = getSymbols();
68
- const handle = this._handle;
69
-
70
- const outValue = allocPointerOut();
71
- const outHasValue = new Int32Array(1);
72
-
73
- if (params && params.length > 0) {
74
- const marshaled = marshalParams(params);
75
- check(
76
- lib.quiver_database_query_string_params(
77
- handle,
78
- toCString(sql),
79
- ptr(marshaled.types),
80
- ptr(marshaled.values),
81
- params.length,
82
- ptr(outValue),
83
- ptr(outHasValue),
84
- ),
85
- );
86
- } else {
87
- check(
88
- lib.quiver_database_query_string(handle, toCString(sql), ptr(outValue), ptr(outHasValue)),
89
- );
90
- }
91
-
92
- if (outHasValue[0] === 0) return null;
93
-
94
- const strPtr = readPointerOut(outValue);
95
- const result = new CString(strPtr).toString();
96
- lib.quiver_database_free_string(strPtr);
97
- return result;
98
- };
99
-
100
- Database.prototype.queryInteger = function (
101
- this: Database,
102
- sql: string,
103
- params?: QueryParam[],
104
- ): number | null {
105
- const lib = getSymbols();
106
- const handle = this._handle;
107
-
108
- const outValue = new BigInt64Array(1);
109
- const outHasValue = new Int32Array(1);
110
-
111
- if (params && params.length > 0) {
112
- const marshaled = marshalParams(params);
113
- check(
114
- lib.quiver_database_query_integer_params(
115
- handle,
116
- toCString(sql),
117
- ptr(marshaled.types),
118
- ptr(marshaled.values),
119
- params.length,
120
- ptr(outValue),
121
- ptr(outHasValue),
122
- ),
123
- );
124
- } else {
125
- check(
126
- lib.quiver_database_query_integer(handle, toCString(sql), ptr(outValue), ptr(outHasValue)),
127
- );
128
- }
129
-
130
- if (outHasValue[0] === 0) return null;
131
- return Number(outValue[0]);
132
- };
133
-
134
- Database.prototype.queryFloat = function (
135
- this: Database,
136
- sql: string,
137
- params?: QueryParam[],
138
- ): number | null {
139
- const lib = getSymbols();
140
- const handle = this._handle;
141
-
142
- const outValue = new Float64Array(1);
143
- const outHasValue = new Int32Array(1);
144
-
145
- if (params && params.length > 0) {
146
- const marshaled = marshalParams(params);
147
- check(
148
- lib.quiver_database_query_float_params(
149
- handle,
150
- toCString(sql),
151
- ptr(marshaled.types),
152
- ptr(marshaled.values),
153
- params.length,
154
- ptr(outValue),
155
- ptr(outHasValue),
156
- ),
157
- );
158
- } else {
159
- check(lib.quiver_database_query_float(handle, toCString(sql), ptr(outValue), ptr(outHasValue)));
160
- }
161
-
162
- if (outHasValue[0] === 0) return null;
163
- return outValue[0];
164
- };
package/src/read.ts DELETED
@@ -1,231 +0,0 @@
1
- import { CString, ptr, toArrayBuffer } from "bun:ffi";
2
- import { Database } from "./database";
3
- import { check } from "./errors";
4
- import { allocPointerOut, readPointerOut, readPtrAt, toCString } from "./ffi-helpers";
5
- import { getSymbols } from "./loader";
6
-
7
- declare module "./database" {
8
- interface Database {
9
- readScalarIntegers(collection: string, attribute: string): number[];
10
- readScalarFloats(collection: string, attribute: string): number[];
11
- readScalarStrings(collection: string, attribute: string): string[];
12
- readScalarIntegerById(collection: string, attribute: string, id: number): number | null;
13
- readScalarFloatById(collection: string, attribute: string, id: number): number | null;
14
- readScalarStringById(collection: string, attribute: string, id: number): string | null;
15
- readElementIds(collection: string): number[];
16
- }
17
- }
18
-
19
- Database.prototype.readScalarIntegers = function (
20
- this: Database,
21
- collection: string,
22
- attribute: string,
23
- ): number[] {
24
- const lib = getSymbols();
25
- const handle = this._handle;
26
-
27
- const outValues = allocPointerOut();
28
- const outCount = new BigUint64Array(1);
29
-
30
- check(
31
- lib.quiver_database_read_scalar_integers(
32
- handle,
33
- toCString(collection),
34
- toCString(attribute),
35
- ptr(outValues),
36
- ptr(outCount),
37
- ),
38
- );
39
-
40
- const count = Number(outCount[0]);
41
- if (count === 0) return [];
42
-
43
- const valuesPtr = readPointerOut(outValues);
44
- const buffer = toArrayBuffer(valuesPtr, 0, count * 8);
45
- const bigInts = new BigInt64Array(buffer);
46
- const result: number[] = new Array(count);
47
- for (let i = 0; i < count; i++) {
48
- result[i] = Number(bigInts[i]);
49
- }
50
-
51
- lib.quiver_database_free_integer_array(valuesPtr);
52
- return result;
53
- };
54
-
55
- Database.prototype.readScalarFloats = function (
56
- this: Database,
57
- collection: string,
58
- attribute: string,
59
- ): number[] {
60
- const lib = getSymbols();
61
- const handle = this._handle;
62
-
63
- const outValues = allocPointerOut();
64
- const outCount = new BigUint64Array(1);
65
-
66
- check(
67
- lib.quiver_database_read_scalar_floats(
68
- handle,
69
- toCString(collection),
70
- toCString(attribute),
71
- ptr(outValues),
72
- ptr(outCount),
73
- ),
74
- );
75
-
76
- const count = Number(outCount[0]);
77
- if (count === 0) return [];
78
-
79
- const valuesPtr = readPointerOut(outValues);
80
- const buffer = toArrayBuffer(valuesPtr, 0, count * 8);
81
- const result = Array.from(new Float64Array(buffer));
82
-
83
- lib.quiver_database_free_float_array(valuesPtr);
84
- return result;
85
- };
86
-
87
- Database.prototype.readScalarStrings = function (
88
- this: Database,
89
- collection: string,
90
- attribute: string,
91
- ): string[] {
92
- const lib = getSymbols();
93
- const handle = this._handle;
94
-
95
- const outValues = allocPointerOut();
96
- const outCount = new BigUint64Array(1);
97
-
98
- check(
99
- lib.quiver_database_read_scalar_strings(
100
- handle,
101
- toCString(collection),
102
- toCString(attribute),
103
- ptr(outValues),
104
- ptr(outCount),
105
- ),
106
- );
107
-
108
- const count = Number(outCount[0]);
109
- if (count === 0) return [];
110
-
111
- const arrPtr = readPointerOut(outValues);
112
- const result: string[] = new Array(count);
113
- for (let i = 0; i < count; i++) {
114
- const strPtr = readPtrAt(arrPtr, i * 8);
115
- result[i] = new CString(strPtr).toString();
116
- }
117
-
118
- lib.quiver_database_free_string_array(arrPtr, count);
119
- return result;
120
- };
121
-
122
- Database.prototype.readScalarIntegerById = function (
123
- this: Database,
124
- collection: string,
125
- attribute: string,
126
- id: number,
127
- ): number | null {
128
- const lib = getSymbols();
129
- const handle = this._handle;
130
-
131
- const outValue = new BigInt64Array(1);
132
- const outHasValue = new Int32Array(1);
133
-
134
- check(
135
- lib.quiver_database_read_scalar_integer_by_id(
136
- handle,
137
- toCString(collection),
138
- toCString(attribute),
139
- id,
140
- ptr(outValue),
141
- ptr(outHasValue),
142
- ),
143
- );
144
-
145
- if (outHasValue[0] === 0) return null;
146
- return Number(outValue[0]);
147
- };
148
-
149
- Database.prototype.readScalarFloatById = function (
150
- this: Database,
151
- collection: string,
152
- attribute: string,
153
- id: number,
154
- ): number | null {
155
- const lib = getSymbols();
156
- const handle = this._handle;
157
-
158
- const outValue = new Float64Array(1);
159
- const outHasValue = new Int32Array(1);
160
-
161
- check(
162
- lib.quiver_database_read_scalar_float_by_id(
163
- handle,
164
- toCString(collection),
165
- toCString(attribute),
166
- id,
167
- ptr(outValue),
168
- ptr(outHasValue),
169
- ),
170
- );
171
-
172
- if (outHasValue[0] === 0) return null;
173
- return outValue[0];
174
- };
175
-
176
- Database.prototype.readScalarStringById = function (
177
- this: Database,
178
- collection: string,
179
- attribute: string,
180
- id: number,
181
- ): string | null {
182
- const lib = getSymbols();
183
- const handle = this._handle;
184
-
185
- const outValue = allocPointerOut();
186
- const outHasValue = new Int32Array(1);
187
-
188
- check(
189
- lib.quiver_database_read_scalar_string_by_id(
190
- handle,
191
- toCString(collection),
192
- toCString(attribute),
193
- id,
194
- ptr(outValue),
195
- ptr(outHasValue),
196
- ),
197
- );
198
-
199
- if (outHasValue[0] === 0) return null;
200
-
201
- const strPtr = readPointerOut(outValue);
202
- const result = new CString(strPtr).toString();
203
- lib.quiver_database_free_string(strPtr);
204
- return result;
205
- };
206
-
207
- Database.prototype.readElementIds = function (this: Database, collection: string): number[] {
208
- const lib = getSymbols();
209
- const handle = this._handle;
210
-
211
- const outIds = allocPointerOut();
212
- const outCount = new BigUint64Array(1);
213
-
214
- check(
215
- lib.quiver_database_read_element_ids(handle, toCString(collection), ptr(outIds), ptr(outCount)),
216
- );
217
-
218
- const count = Number(outCount[0]);
219
- if (count === 0) return [];
220
-
221
- const idsPtr = readPointerOut(outIds);
222
- const buffer = toArrayBuffer(idsPtr, 0, count * 8);
223
- const bigInts = new BigInt64Array(buffer);
224
- const result: number[] = new Array(count);
225
- for (let i = 0; i < count; i++) {
226
- result[i] = Number(bigInts[i]);
227
- }
228
-
229
- lib.quiver_database_free_integer_array(idsPtr);
230
- return result;
231
- };
@@ -1,35 +0,0 @@
1
- import { ptr } from "bun:ffi";
2
- import { Database } from "./database";
3
- import { check } from "./errors";
4
- import { getSymbols } from "./loader";
5
-
6
- declare module "./database" {
7
- interface Database {
8
- beginTransaction(): void;
9
- commit(): void;
10
- rollback(): void;
11
- inTransaction(): boolean;
12
- }
13
- }
14
-
15
- Database.prototype.beginTransaction = function (this: Database): void {
16
- const lib = getSymbols();
17
- check(lib.quiver_database_begin_transaction(this._handle));
18
- };
19
-
20
- Database.prototype.commit = function (this: Database): void {
21
- const lib = getSymbols();
22
- check(lib.quiver_database_commit(this._handle));
23
- };
24
-
25
- Database.prototype.rollback = function (this: Database): void {
26
- const lib = getSymbols();
27
- check(lib.quiver_database_rollback(this._handle));
28
- };
29
-
30
- Database.prototype.inTransaction = function (this: Database): boolean {
31
- const lib = getSymbols();
32
- const outActive = new Uint8Array(1);
33
- check(lib.quiver_database_in_transaction(this._handle, ptr(outActive)));
34
- return outActive[0] !== 0;
35
- };