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
@@ -0,0 +1,155 @@
1
+ import koffi from "koffi";
2
+ import { Database } from "./database.js";
3
+ import { check } from "./errors.js";
4
+ import { allocNativeFloat64, allocNativeInt64, allocNativePtrTable, allocNativeString, allocNativeStringArray, allocPtrOut, allocUint64Out, decodeFloat64Array, decodeInt64Array, decodePtrArray, decodeStringArray, readPtrOut, readUint64Out, } from "./ffi-helpers.js";
5
+ import { getSymbols } from "./loader.js";
6
+ const DATA_TYPE_INTEGER = 0;
7
+ const DATA_TYPE_FLOAT = 1;
8
+ const DATA_TYPE_STRING = 2;
9
+ const DATA_TYPE_DATE_TIME = 3;
10
+ Database.prototype.readTimeSeriesGroup = function (collection, group, id) {
11
+ const lib = getSymbols();
12
+ const outNames = allocPtrOut();
13
+ const outTypes = allocPtrOut();
14
+ const outData = allocPtrOut();
15
+ const outColCount = allocUint64Out();
16
+ const outRowCount = allocUint64Out();
17
+ check(lib.quiver_database_read_time_series_group(this._handle, collection, group, id, outNames, outTypes, outData, outColCount, outRowCount));
18
+ const colCount = readUint64Out(outColCount);
19
+ const rowCount = readUint64Out(outRowCount);
20
+ if (colCount === 0)
21
+ return {};
22
+ const namesPtr = readPtrOut(outNames);
23
+ const typesPtr = readPtrOut(outTypes);
24
+ const dataPtr = readPtrOut(outData);
25
+ const colNames = decodeStringArray(namesPtr, colCount);
26
+ const types = koffi.decode(typesPtr, koffi.array("int", colCount));
27
+ const dataPtrs = decodePtrArray(dataPtr, colCount);
28
+ const result = {};
29
+ for (let c = 0; c < colCount; c++) {
30
+ const colName = colNames[c];
31
+ switch (types[c]) {
32
+ case DATA_TYPE_INTEGER:
33
+ result[colName] = decodeInt64Array(dataPtrs[c], rowCount);
34
+ break;
35
+ case DATA_TYPE_FLOAT:
36
+ result[colName] = decodeFloat64Array(dataPtrs[c], rowCount);
37
+ break;
38
+ case DATA_TYPE_STRING:
39
+ case DATA_TYPE_DATE_TIME:
40
+ result[colName] = decodeStringArray(dataPtrs[c], rowCount);
41
+ break;
42
+ }
43
+ }
44
+ lib.quiver_database_free_time_series_data(namesPtr, typesPtr, dataPtr, colCount, rowCount);
45
+ return result;
46
+ };
47
+ Database.prototype.updateTimeSeriesGroup = function (collection, group, id, data) {
48
+ const lib = getSymbols();
49
+ const entries = Object.entries(data);
50
+ if (entries.length === 0) {
51
+ check(lib.quiver_database_update_time_series_group(this._handle, collection, group, id, null, null, null, 0, 0));
52
+ return;
53
+ }
54
+ const columnCount = entries.length;
55
+ const rowCount = entries[0][1].length;
56
+ const keepalive = [];
57
+ // Build column names as native string array
58
+ const colNames = entries.map(([name]) => name);
59
+ const { table: namesTable, keepalive: namesPtrs } = allocNativeStringArray(colNames);
60
+ keepalive.push(namesTable, ...namesPtrs);
61
+ // Build column types and data
62
+ const typesArr = new Int32Array(columnCount);
63
+ const dataPtrs = [];
64
+ for (let c = 0; c < columnCount; c++) {
65
+ const values = entries[c][1];
66
+ if (values.length === 0) {
67
+ typesArr[c] = DATA_TYPE_STRING;
68
+ dataPtrs.push(null);
69
+ }
70
+ else if (typeof values[0] === "string") {
71
+ typesArr[c] = DATA_TYPE_STRING;
72
+ const { table, keepalive: strPtrs } = allocNativeStringArray(values);
73
+ keepalive.push(table, ...strPtrs);
74
+ dataPtrs.push(table);
75
+ }
76
+ else if (typeof values[0] === "number") {
77
+ const allIntegers = values.every((v) => Number.isInteger(v));
78
+ if (allIntegers) {
79
+ typesArr[c] = DATA_TYPE_INTEGER;
80
+ const p = allocNativeInt64(values);
81
+ keepalive.push(p);
82
+ dataPtrs.push(p);
83
+ }
84
+ else {
85
+ typesArr[c] = DATA_TYPE_FLOAT;
86
+ const p = allocNativeFloat64(values);
87
+ keepalive.push(p);
88
+ dataPtrs.push(p);
89
+ }
90
+ }
91
+ }
92
+ const dataTable = allocNativePtrTable(dataPtrs);
93
+ keepalive.push(dataTable);
94
+ check(lib.quiver_database_update_time_series_group(this._handle, collection, group, id, namesTable, typesArr, dataTable, columnCount, rowCount));
95
+ };
96
+ Database.prototype.hasTimeSeriesFiles = function (collection) {
97
+ const lib = getSymbols();
98
+ const outResult = new Int32Array(1);
99
+ check(lib.quiver_database_has_time_series_files(this._handle, collection, outResult));
100
+ return outResult[0] !== 0;
101
+ };
102
+ Database.prototype.listTimeSeriesFilesColumns = function (collection) {
103
+ const lib = getSymbols();
104
+ const outColumns = allocPtrOut();
105
+ const outCount = allocUint64Out();
106
+ check(lib.quiver_database_list_time_series_files_columns(this._handle, collection, outColumns, outCount));
107
+ const count = readUint64Out(outCount);
108
+ if (count === 0)
109
+ return [];
110
+ const ptr = readPtrOut(outColumns);
111
+ const result = decodeStringArray(ptr, count);
112
+ lib.quiver_database_free_string_array(ptr, count);
113
+ return result;
114
+ };
115
+ Database.prototype.readTimeSeriesFiles = function (collection) {
116
+ const lib = getSymbols();
117
+ const outColumns = allocPtrOut();
118
+ const outPaths = allocPtrOut();
119
+ const outCount = allocUint64Out();
120
+ check(lib.quiver_database_read_time_series_files(this._handle, collection, outColumns, outPaths, outCount));
121
+ const count = readUint64Out(outCount);
122
+ if (count === 0)
123
+ return {};
124
+ const colsPtr = readPtrOut(outColumns);
125
+ const pathsPtr = readPtrOut(outPaths);
126
+ const colNames = decodeStringArray(colsPtr, count);
127
+ const paths = koffi.decode(pathsPtr, koffi.array("str", count));
128
+ const result = {};
129
+ for (let i = 0; i < count; i++) {
130
+ result[colNames[i]] = paths[i];
131
+ }
132
+ lib.quiver_database_free_time_series_files(colsPtr, pathsPtr, count);
133
+ return result;
134
+ };
135
+ Database.prototype.updateTimeSeriesFiles = function (collection, data) {
136
+ const lib = getSymbols();
137
+ const entries = Object.entries(data);
138
+ if (entries.length === 0)
139
+ return;
140
+ const keepalive = [];
141
+ const colNames = entries.map(([name]) => name);
142
+ const { table: colsTable, keepalive: colPtrs } = allocNativeStringArray(colNames);
143
+ keepalive.push(colsTable, ...colPtrs);
144
+ const pathPtrs = entries.map(([, value]) => {
145
+ if (value === null)
146
+ return null;
147
+ const p = allocNativeString(value);
148
+ keepalive.push(p);
149
+ return p;
150
+ });
151
+ const pathsTable = allocNativePtrTable(pathPtrs);
152
+ keepalive.push(pathsTable);
153
+ check(lib.quiver_database_update_time_series_files(this._handle, collection, colsTable, pathsTable, entries.length));
154
+ };
155
+ //# sourceMappingURL=time-series.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"time-series.js","sourceRoot":"","sources":["../src/time-series.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EACL,kBAAkB,EAClB,gBAAgB,EAChB,mBAAmB,EACnB,iBAAiB,EACjB,sBAAsB,EACtB,WAAW,EACX,cA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EtC,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC;IAC/C,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,OAAO,EAAE,GAAG,sBAAsB,CAAC,QAAQ,CAAC,CAAC;IAClF,SAAS,CAAC,IAAI,CAAC,SAAS,EAAE,GAAG,OAAO,CAAC,CAAC;IAEtC,MAAM,QAAQ,GAAoB,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,EAAE;QAC1D,IAAI,KAAK,KAAK,IAAI;YAAE,OAAO,IAAI,CAAC;QAChC,MAAM,CAAC,GAAG,iBAAiB,CAAC,KAAK,CAAC,CAAC;QACnC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,OAAO,CAAC,CAAC;IACX,CAAC,CAAC,CAAC;IAEH,MAAM,UAAU,GAAG,mBAAmB,CAAC,QAAQ,CAAC,CAAC;IACjD,SAAS,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IAE3B,KAAK,CAAC,GAAG,CAAC,wCAAwC,CAAC,IAAI,CAAC,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,UAAU,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC;AACvH,CAAC,CAAC"}
@@ -0,0 +1,10 @@
1
+ declare module "./database.js" {
2
+ interface Database {
3
+ beginTransaction(): void;
4
+ commit(): void;
5
+ rollback(): void;
6
+ inTransaction(): boolean;
7
+ }
8
+ }
9
+ export {};
10
+ //# sourceMappingURL=transaction.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transaction.d.ts","sourceRoot":"","sources":["../src/transaction.ts"],"names":[],"mappings":"AAIA,OAAO,QAAQ,eAAe,CAAC;IAC7B,UAAU,QAAQ;QAChB,gBAAgB,IAAI,IAAI,CAAC;QACzB,MAAM,IAAI,IAAI,CAAC;QACf,QAAQ,IAAI,IAAI,CAAC;QACjB,aAAa,IAAI,OAAO,CAAC;KAC1B;CACF"}
@@ -0,0 +1,22 @@
1
+ import { Database } from "./database.js";
2
+ import { check } from "./errors.js";
3
+ import { getSymbols } from "./loader.js";
4
+ Database.prototype.beginTransaction = function () {
5
+ const lib = getSymbols();
6
+ check(lib.quiver_database_begin_transaction(this._handle));
7
+ };
8
+ Database.prototype.commit = function () {
9
+ const lib = getSymbols();
10
+ check(lib.quiver_database_commit(this._handle));
11
+ };
12
+ Database.prototype.rollback = function () {
13
+ const lib = getSymbols();
14
+ check(lib.quiver_database_rollback(this._handle));
15
+ };
16
+ Database.prototype.inTransaction = function () {
17
+ const lib = getSymbols();
18
+ const outActive = new Int32Array(1);
19
+ check(lib.quiver_database_in_transaction(this._handle, outActive));
20
+ return outActive[0] !== 0;
21
+ };
22
+ //# sourceMappingURL=transaction.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transaction.js","sourceRoot":"","sources":["../src/transaction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAWzC,QAAQ,CAAC,SAAS,CAAC,gBAAgB,GAAG;IACpC,MAAM,GAAG,GAAG,UAAU,EAAE,CAAC;IACzB,KAAK,CAAC,GAAG,CAAC,iCAAiC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;AAC7D,CAAC,CAAC;AAEF,QAAQ,CAAC,SAAS,CAAC,MAAM,GAAG;IAC1B,MAAM,GAAG,GAAG,UAAU,EAAE,CAAC;IACzB,KAAK,CAAC,GAAG,CAAC,sBAAsB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;AAClD,CAAC,CAAC;AAEF,QAAQ,CAAC,SAAS,CAAC,QAAQ,GAAG;IAC5B,MAAM,GAAG,GAAG,UAAU,EAAE,CAAC;IACzB,KAAK,CAAC,GAAG,CAAC,wBAAwB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;AACpD,CAAC,CAAC;AAEF,QAAQ,CAAC,SAAS,CAAC,aAAa,GAAG;IACjC,MAAM,GAAG,GAAG,UAAU,EAAE,CAAC;IACzB,MAAM,SAAS,GAAG,IAAI,UAAU,CAAC,CAAC,CAAC,CAAC;IACpC,KAAK,CAAC,GAAG,CAAC,8BAA8B,CAAC,IAAI,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC,CAAC;IACnE,OAAO,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;AAC5B,CAAC,CAAC"}
@@ -3,3 +3,4 @@ export type ArrayValue = number[] | bigint[] | string[];
3
3
  export type Value = ScalarValue | ArrayValue;
4
4
  export type ElementData = Record<string, Value | undefined>;
5
5
  export type QueryParam = number | string | null;
6
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;AAC1D,MAAM,MAAM,UAAU,GAAG,MAAM,EAAE,GAAG,MAAM,EAAE,GAAG,MAAM,EAAE,CAAC;AACxD,MAAM,MAAM,KAAK,GAAG,WAAW,GAAG,UAAU,CAAC;AAC7C,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,GAAG,SAAS,CAAC,CAAC;AAC5D,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC"}
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
package/package.json CHANGED
@@ -1,39 +1,47 @@
1
1
  {
2
2
  "name": "quiverdb",
3
- "version": "0.5.0",
4
- "description": "Bun-native SQLite wrapper binding for Quiver via bun:ffi",
3
+ "version": "0.6.1",
4
+ "description": "SQLite wrapper binding for Quiver via koffi FFI",
5
5
  "type": "module",
6
- "main": "src/index.ts",
7
- "types": "src/index.ts",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
8
  "exports": {
9
- ".": "./src/index.ts"
9
+ ".": {
10
+ "import": "./dist/index.js",
11
+ "types": "./dist/index.d.ts"
12
+ }
10
13
  },
11
14
  "files": [
12
- "src/",
13
- "package.json",
14
- "tsconfig.json",
15
- "README.md"
15
+ "dist/"
16
16
  ],
17
- "engines": {
18
- "bun": ">=1.0.0"
19
- },
20
17
  "license": "MIT",
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "https://github.com/psrenergy/quiver",
21
+ "directory": "bindings/js"
22
+ },
21
23
  "keywords": [
22
24
  "sqlite",
23
25
  "database",
24
26
  "ffi",
25
- "bun",
27
+ "node",
28
+ "deno",
26
29
  "quiver"
27
30
  ],
28
31
  "scripts": {
29
- "test": "bun test",
32
+ "build": "tsc",
33
+ "test": "vitest run",
30
34
  "typecheck": "tsc --noEmit",
31
35
  "lint": "biome check",
32
36
  "format": "biome format --write"
33
37
  },
38
+ "dependencies": {
39
+ "koffi": "^2.9.0"
40
+ },
34
41
  "devDependencies": {
35
42
  "@biomejs/biome": "^2.4.6",
36
- "@types/bun": "^1.3.10",
37
- "typescript": "^5.9.3"
43
+ "@types/node": "^22.0.0",
44
+ "typescript": "^5.9.3",
45
+ "vitest": "^3.2.1"
38
46
  }
39
47
  }
package/src/create.ts DELETED
@@ -1,128 +0,0 @@
1
- import { type Pointer, ptr } from "bun:ffi";
2
- import { Database } from "./database";
3
- import { check, QuiverError } from "./errors";
4
- import { allocPointerOut, readPointerOut, toCString } from "./ffi-helpers";
5
- import { getSymbols } from "./loader";
6
- import type { ElementData, Value } from "./types";
7
-
8
- declare module "./database" {
9
- interface Database {
10
- createElement(collection: string, data: ElementData): number;
11
- deleteElement(collection: string, id: number): void;
12
- }
13
- }
14
-
15
- type Symbols = ReturnType<typeof getSymbols>;
16
-
17
- function setElementArray(lib: Symbols, elemPtr: Pointer, name: string, values: unknown[]): void {
18
- const cName = toCString(name);
19
-
20
- if (values.length === 0) {
21
- // Empty array: pass null pointer with count 0
22
- check(lib.quiver_element_set_array_integer(elemPtr, cName, null, 0));
23
- return;
24
- }
25
-
26
- const first = values[0];
27
-
28
- if (typeof first === "bigint") {
29
- const arr = BigInt64Array.from(values as bigint[], (v) => BigInt(v));
30
- check(lib.quiver_element_set_array_integer(elemPtr, cName, ptr(arr), values.length));
31
- return;
32
- }
33
-
34
- if (typeof first === "number") {
35
- const allIntegers = (values as number[]).every((v) => Number.isInteger(v));
36
- if (allIntegers) {
37
- const arr = BigInt64Array.from(values as number[], (v) => BigInt(v));
38
- check(lib.quiver_element_set_array_integer(elemPtr, cName, ptr(arr), values.length));
39
- } else {
40
- const arr = Float64Array.from(values as number[]);
41
- check(lib.quiver_element_set_array_float(elemPtr, cName, ptr(arr), values.length));
42
- }
43
- return;
44
- }
45
-
46
- if (typeof first === "string") {
47
- // Build pointer table: BigInt64Array of pointers to each string buffer
48
- const buffers = (values as string[]).map((s) => toCString(s));
49
- const ptrTable = new BigInt64Array(buffers.length);
50
- for (let i = 0; i < buffers.length; i++) {
51
- ptrTable[i] = BigInt(ptr(buffers[i]));
52
- }
53
- check(lib.quiver_element_set_array_string(elemPtr, cName, ptr(ptrTable), values.length));
54
- return;
55
- }
56
-
57
- throw new QuiverError(`Unsupported array element type for '${name}': ${typeof first}`);
58
- }
59
-
60
- function setElementField(lib: Symbols, elemPtr: Pointer, name: string, value: Value): void {
61
- const cName = toCString(name);
62
-
63
- if (value === null) {
64
- check(lib.quiver_element_set_null(elemPtr, cName));
65
- return;
66
- }
67
-
68
- if (typeof value === "bigint") {
69
- check(lib.quiver_element_set_integer(elemPtr, cName, value));
70
- return;
71
- }
72
-
73
- if (typeof value === "number") {
74
- if (Number.isInteger(value)) {
75
- check(lib.quiver_element_set_integer(elemPtr, cName, value));
76
- } else {
77
- check(lib.quiver_element_set_float(elemPtr, cName, value));
78
- }
79
- return;
80
- }
81
-
82
- if (typeof value === "string") {
83
- check(lib.quiver_element_set_string(elemPtr, cName, toCString(value)));
84
- return;
85
- }
86
-
87
- if (Array.isArray(value)) {
88
- setElementArray(lib, elemPtr, name, value);
89
- return;
90
- }
91
-
92
- throw new QuiverError(`Unsupported value type for '${name}': ${typeof value}`);
93
- }
94
-
95
- Database.prototype.createElement = function (
96
- this: Database,
97
- collection: string,
98
- data: ElementData,
99
- ): number {
100
- const lib = getSymbols();
101
- const handle = this._handle; // triggers ensureOpen
102
-
103
- // Create element handle
104
- const outElem = allocPointerOut();
105
- check(lib.quiver_element_create(ptr(outElem)));
106
- const elemPtr = readPointerOut(outElem);
107
-
108
- try {
109
- // Set fields from data object
110
- for (const [key, value] of Object.entries(data)) {
111
- if (value === undefined) continue;
112
- setElementField(lib, elemPtr, key, value);
113
- }
114
-
115
- // Create element in database
116
- const outId = new BigInt64Array(1);
117
- check(lib.quiver_database_create_element(handle, toCString(collection), elemPtr, ptr(outId)));
118
-
119
- return Number(outId[0]);
120
- } finally {
121
- lib.quiver_element_destroy(elemPtr);
122
- }
123
- };
124
-
125
- Database.prototype.deleteElement = function (this: Database, collection: string, id: number): void {
126
- const lib = getSymbols();
127
- check(lib.quiver_database_delete_element(this._handle, toCString(collection), id));
128
- };
package/src/database.ts DELETED
@@ -1,68 +0,0 @@
1
- import { type Pointer, ptr } from "bun:ffi";
2
- import { check, QuiverError } from "./errors";
3
- import { allocPointerOut, makeDefaultOptions, readPointerOut, toCString } from "./ffi-helpers";
4
- import { getSymbols } from "./loader";
5
-
6
- export class Database {
7
- private _ptr: Pointer;
8
- private _closed = false;
9
-
10
- private constructor(nativePtr: Pointer) {
11
- this._ptr = nativePtr;
12
- }
13
-
14
- static fromSchema(dbPath: string, schemaPath: string): Database {
15
- const lib = getSymbols();
16
- const options = makeDefaultOptions();
17
- const outDb = allocPointerOut();
18
-
19
- check(
20
- lib.quiver_database_from_schema(
21
- toCString(dbPath),
22
- toCString(schemaPath),
23
- ptr(options),
24
- ptr(outDb),
25
- ),
26
- );
27
-
28
- const dbPtr = readPointerOut(outDb);
29
- return new Database(dbPtr);
30
- }
31
-
32
- static fromMigrations(dbPath: string, migrationsPath: string): Database {
33
- const lib = getSymbols();
34
- const options = makeDefaultOptions();
35
- const outDb = allocPointerOut();
36
-
37
- check(
38
- lib.quiver_database_from_migrations(
39
- toCString(dbPath),
40
- toCString(migrationsPath),
41
- ptr(options),
42
- ptr(outDb),
43
- ),
44
- );
45
-
46
- const dbPtr = readPointerOut(outDb);
47
- return new Database(dbPtr);
48
- }
49
-
50
- close(): void {
51
- if (this._closed) return;
52
- const lib = getSymbols();
53
- check(lib.quiver_database_close(this._ptr));
54
- this._closed = true;
55
- }
56
-
57
- private ensureOpen(): void {
58
- if (this._closed) {
59
- throw new QuiverError("Database is closed");
60
- }
61
- }
62
-
63
- /** @internal */
64
- get _handle(): Pointer {
65
- this.ensureOpen();
66
- return this._ptr;
67
- }
68
- }
package/src/errors.ts DELETED
@@ -1,24 +0,0 @@
1
- import { CString } from "bun:ffi";
2
- import { getSymbols } from "./loader";
3
-
4
- export class QuiverError extends Error {
5
- constructor(message: string) {
6
- super(message);
7
- this.name = "QuiverError";
8
- }
9
- }
10
-
11
- export function check(err: number): void {
12
- if (err !== 0) {
13
- const lib = getSymbols();
14
- const errPtr = lib.quiver_get_last_error();
15
- if (errPtr) {
16
- const detail = new CString(errPtr).toString();
17
- if (detail) {
18
- throw new QuiverError(detail);
19
- }
20
- }
21
- console.warn("check: C API returned error but quiver_get_last_error() is empty");
22
- throw new QuiverError("Unknown error");
23
- }
24
- }
@@ -1,48 +0,0 @@
1
- import { type Pointer, ptr, read } from "bun:ffi";
2
-
3
- /**
4
- * Construct the 8-byte quiver_database_options_t struct manually.
5
- * Layout: offset 0 = int32 read_only (default 0), offset 4 = int32 console_level (default 1 = QUIVER_LOG_INFO).
6
- * DO NOT call quiver_database_options_default() -- it returns struct by value which bun:ffi cannot handle.
7
- */
8
- export function makeDefaultOptions(): Uint8Array {
9
- const buf = new ArrayBuffer(8);
10
- const view = new Int32Array(buf);
11
- view[0] = 0; // read_only = false
12
- view[1] = 1; // console_level = QUIVER_LOG_INFO
13
- return new Uint8Array(buf);
14
- }
15
-
16
- /**
17
- * Allocate a 1-element BigInt64Array (8 bytes) to receive a quiver_database_t** out-parameter.
18
- * Caller passes ptr(result) to the FFI function.
19
- */
20
- export function allocPointerOut(): BigInt64Array {
21
- return new BigInt64Array(1);
22
- }
23
-
24
- /**
25
- * Read the pointer value from an out-parameter buffer.
26
- * Dereferences the pointer stored at offset 0 of the typed array.
27
- * Returns a branded Pointer suitable for passing to FFI functions.
28
- * read.ptr() returns number at runtime; the cast to Pointer satisfies bun:ffi type signatures.
29
- */
30
- export function readPointerOut(buf: BigInt64Array): Pointer {
31
- return read.ptr(ptr(buf), 0) as unknown as Pointer;
32
- }
33
-
34
- /**
35
- * Read a pointer at the given byte offset from a base pointer.
36
- * Wraps read.ptr() with a cast to the branded Pointer type.
37
- */
38
- export function readPtrAt(base: Pointer, byteOffset: number): Pointer {
39
- return read.ptr(base, byteOffset) as unknown as Pointer;
40
- }
41
-
42
- /**
43
- * Encode a JS string as null-terminated UTF-8 for the C API.
44
- * Returns a Buffer suitable for passing as FFIType.ptr.
45
- */
46
- export function toCString(str: string): Buffer {
47
- return Buffer.from(`${str}\0`);
48
- }
package/src/index.ts DELETED
@@ -1,8 +0,0 @@
1
- import "./create";
2
- import "./read";
3
- import "./query";
4
- import "./transaction";
5
-
6
- export { Database } from "./database";
7
- export { QuiverError } from "./errors";
8
- export type { ArrayValue, ElementData, QueryParam, ScalarValue, Value } from "./types";