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/README.md CHANGED
@@ -1,108 +1,108 @@
1
- # quiverdb
2
-
3
- Bun-native SQLite wrapper binding for Quiver via bun:ffi.
4
-
5
- ## Requirements
6
-
7
- - Bun >= 1.0.0
8
- - `libquiver.dll` and `libquiver_c.dll` in system PATH
9
-
10
- ## Installation
11
-
12
- ```bash
13
- bun add quiverdb
14
- ```
15
-
16
- The native Quiver DLLs must be compiled separately and available in your system PATH. See the Quiver project build instructions for details.
17
-
18
- ## DLL Setup
19
-
20
- This binding loads the Quiver C API library (`libquiver_c.dll`) at runtime via `bun:ffi`. The core library (`libquiver.dll`) is a dependency that must also be loadable.
21
-
22
- Options for making the DLLs available:
23
-
24
- 1. Add the `build/bin/` directory to your system PATH
25
- 2. Copy both DLLs to a directory already in PATH
26
- 3. Place both DLLs alongside your application entry point
27
-
28
- ## Quick Start
29
-
30
- ```typescript
31
- import { Database } from "quiverdb";
32
-
33
- const db = Database.fromSchema("my.db", "schema.sql");
34
- db.createElement("Items", { label: "Item 1", value: 42 });
35
-
36
- const values = db.readScalarIntegers("Items", "value");
37
- console.log(values); // [42]
38
-
39
- db.close();
40
- ```
41
-
42
- ## API Methods
43
-
44
- ### Lifecycle
45
-
46
- - `Database.fromSchema(dbPath, schemaPath)` -- Create database from SQL schema file
47
- - `Database.fromMigrations(dbPath, migrationsPath)` -- Create database from migrations directory
48
- - `close()` -- Close the database connection
49
-
50
- ### Create / Delete
51
-
52
- - `createElement(collection, data)` -- Create element, returns numeric ID
53
- - `deleteElement(collection, id)` -- Delete element by ID
54
-
55
- ### Read (bulk)
56
-
57
- - `readScalarIntegers(collection, attribute)` -- Read all integer scalars
58
- - `readScalarFloats(collection, attribute)` -- Read all float scalars
59
- - `readScalarStrings(collection, attribute)` -- Read all string scalars
60
-
61
- ### Read (by ID)
62
-
63
- - `readScalarIntegerById(collection, attribute, id)` -- Read integer or null
64
- - `readScalarFloatById(collection, attribute, id)` -- Read float or null
65
- - `readScalarStringById(collection, attribute, id)` -- Read string or null
66
-
67
- ### Read (IDs)
68
-
69
- - `readElementIds(collection)` -- Read all element IDs in a collection
70
-
71
- ### Query
72
-
73
- - `queryString(sql, params?)` -- Query returning string or null
74
- - `queryInteger(sql, params?)` -- Query returning integer or null
75
- - `queryFloat(sql, params?)` -- Query returning float or null
76
-
77
- Parameters are passed as an array of `number | string | null`.
78
-
79
- ### Transaction
80
-
81
- - `beginTransaction()` -- Begin explicit transaction
82
- - `commit()` -- Commit current transaction
83
- - `rollback()` -- Rollback current transaction
84
- - `inTransaction()` -- Check if transaction is active
85
-
86
- ## Types
87
-
88
- Exported types available for TypeScript consumers:
89
-
90
- - `ScalarValue` -- `number | bigint | string | null`
91
- - `ArrayValue` -- `number[] | bigint[] | string[]`
92
- - `Value` -- `ScalarValue | ArrayValue`
93
- - `ElementData` -- `Record<string, Value | undefined>`
94
- - `QueryParam` -- `number | string | null`
95
- - `QuiverError` -- Error class for all Quiver operations
96
-
97
- ## Development
98
-
99
- ```bash
100
- bun test # Run all tests
101
- bun run typecheck # TypeScript type checking (tsc --noEmit)
102
- bun run lint # Biome linting
103
- bun run format # Biome formatting (auto-fix)
104
- ```
105
-
106
- ## License
107
-
108
- MIT
1
+ # quiverdb
2
+
3
+ SQLite wrapper binding for Quiver via koffi FFI. Works with Node.js, Deno, and Bun.
4
+
5
+ ## Requirements
6
+
7
+ - Node.js >= 20, Deno >= 2.0, or Bun >= 1.0
8
+ - `libquiver.dll` and `libquiver_c.dll` (or `.so`/`.dylib`) in system PATH
9
+
10
+ ## Installation
11
+
12
+ ```bash
13
+ npm install quiverdb
14
+ ```
15
+
16
+ The native Quiver libraries must be compiled separately and available in your system PATH. See the Quiver project build instructions for details.
17
+
18
+ ## Native Library Setup
19
+
20
+ This binding loads the Quiver C API library (`libquiver_c`) at runtime via koffi. The core library (`libquiver`) is a dependency that must also be loadable.
21
+
22
+ Options for making the libraries available:
23
+
24
+ 1. Add the `build/bin/` directory to your system PATH
25
+ 2. Copy both libraries to a directory already in PATH
26
+ 3. Place both libraries alongside your application entry point
27
+
28
+ ## Quick Start
29
+
30
+ ```typescript
31
+ import { Database } from "quiverdb";
32
+
33
+ const db = Database.fromSchema("my.db", "schema.sql");
34
+ db.createElement("Items", { label: "Item 1", value: 42 });
35
+
36
+ const values = db.readScalarIntegers("Items", "value");
37
+ console.log(values); // [42]
38
+
39
+ db.close();
40
+ ```
41
+
42
+ ## API Methods
43
+
44
+ ### Lifecycle
45
+
46
+ - `Database.fromSchema(dbPath, schemaPath)` -- Create database from SQL schema file
47
+ - `Database.fromMigrations(dbPath, migrationsPath)` -- Create database from migrations directory
48
+ - `close()` -- Close the database connection
49
+
50
+ ### Create / Delete
51
+
52
+ - `createElement(collection, data)` -- Create element, returns numeric ID
53
+ - `deleteElement(collection, id)` -- Delete element by ID
54
+
55
+ ### Read (bulk)
56
+
57
+ - `readScalarIntegers(collection, attribute)` -- Read all integer scalars
58
+ - `readScalarFloats(collection, attribute)` -- Read all float scalars
59
+ - `readScalarStrings(collection, attribute)` -- Read all string scalars
60
+
61
+ ### Read (by ID)
62
+
63
+ - `readScalarIntegerById(collection, attribute, id)` -- Read integer or null
64
+ - `readScalarFloatById(collection, attribute, id)` -- Read float or null
65
+ - `readScalarStringById(collection, attribute, id)` -- Read string or null
66
+
67
+ ### Read (IDs)
68
+
69
+ - `readElementIds(collection)` -- Read all element IDs in a collection
70
+
71
+ ### Query
72
+
73
+ - `queryString(sql, params?)` -- Query returning string or null
74
+ - `queryInteger(sql, params?)` -- Query returning integer or null
75
+ - `queryFloat(sql, params?)` -- Query returning float or null
76
+
77
+ Parameters are passed as an array of `number | string | null`.
78
+
79
+ ### Transaction
80
+
81
+ - `beginTransaction()` -- Begin explicit transaction
82
+ - `commit()` -- Commit current transaction
83
+ - `rollback()` -- Rollback current transaction
84
+ - `inTransaction()` -- Check if transaction is active
85
+
86
+ ## Types
87
+
88
+ Exported types available for TypeScript consumers:
89
+
90
+ - `ScalarValue` -- `number | bigint | string | null`
91
+ - `ArrayValue` -- `number[] | bigint[] | string[]`
92
+ - `Value` -- `ScalarValue | ArrayValue`
93
+ - `ElementData` -- `Record<string, Value | undefined>`
94
+ - `QueryParam` -- `number | string | null`
95
+ - `QuiverError` -- Error class for all Quiver operations
96
+
97
+ ## Development
98
+
99
+ ```bash
100
+ bun test # Run all tests
101
+ bun run typecheck # TypeScript type checking (tsc --noEmit)
102
+ bun run lint # Biome linting
103
+ bun run format # Biome formatting (auto-fix)
104
+ ```
105
+
106
+ ## License
107
+
108
+ MIT
@@ -0,0 +1,9 @@
1
+ declare module "./database.js" {
2
+ interface Database {
3
+ readScalarsById(collection: string, id: number): Record<string, number | string | null>;
4
+ readVectorsById(collection: string, id: number): Record<string, number[] | string[]>;
5
+ readSetsById(collection: string, id: number): Record<string, number[] | string[]>;
6
+ }
7
+ }
8
+ export {};
9
+ //# sourceMappingURL=composites.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"composites.d.ts","sourceRoot":"","sources":["../src/composites.ts"],"names":[],"mappings":"AAEA,OAAO,QAAQ,eAAe,CAAC;IAC7B,UAAU,QAAQ;QAChB,eAAe,CAAC,UAAU,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC,CAAC;QACxF,eAAe,CAAC,UAAU,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,CAAC,CAAC;QACrF,YAAY,CAAC,UAAU,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,CAAC,CAAC;KACnF;CACF"}
@@ -0,0 +1,69 @@
1
+ import { Database } from "./database.js";
2
+ Database.prototype.readScalarsById = function (collection, id) {
3
+ const attributes = this.listScalarAttributes(collection);
4
+ const result = {};
5
+ for (const attr of attributes) {
6
+ switch (attr.dataType) {
7
+ case 0: // INTEGER
8
+ result[attr.name] = this.readScalarIntegerById(collection, attr.name, id);
9
+ break;
10
+ case 1: // FLOAT
11
+ result[attr.name] = this.readScalarFloatById(collection, attr.name, id);
12
+ break;
13
+ case 2: // STRING
14
+ case 3: // DATE_TIME
15
+ result[attr.name] = this.readScalarStringById(collection, attr.name, id);
16
+ break;
17
+ default:
18
+ throw new Error(`Unknown data type ${attr.dataType} for attribute '${attr.name}'`);
19
+ }
20
+ }
21
+ return result;
22
+ };
23
+ Database.prototype.readVectorsById = function (collection, id) {
24
+ const groups = this.listVectorGroups(collection);
25
+ const result = {};
26
+ for (const group of groups) {
27
+ for (const col of group.valueColumns) {
28
+ switch (col.dataType) {
29
+ case 0: // INTEGER
30
+ result[col.name] = this.readVectorIntegersById(collection, col.name, id);
31
+ break;
32
+ case 1: // FLOAT
33
+ result[col.name] = this.readVectorFloatsById(collection, col.name, id);
34
+ break;
35
+ case 2: // STRING
36
+ case 3: // DATE_TIME
37
+ result[col.name] = this.readVectorStringsById(collection, col.name, id);
38
+ break;
39
+ default:
40
+ throw new Error(`Unknown data type ${col.dataType} for column '${col.name}'`);
41
+ }
42
+ }
43
+ }
44
+ return result;
45
+ };
46
+ Database.prototype.readSetsById = function (collection, id) {
47
+ const groups = this.listSetGroups(collection);
48
+ const result = {};
49
+ for (const group of groups) {
50
+ for (const col of group.valueColumns) {
51
+ switch (col.dataType) {
52
+ case 0: // INTEGER
53
+ result[col.name] = this.readSetIntegersById(collection, col.name, id);
54
+ break;
55
+ case 1: // FLOAT
56
+ result[col.name] = this.readSetFloatsById(collection, col.name, id);
57
+ break;
58
+ case 2: // STRING
59
+ case 3: // DATE_TIME
60
+ result[col.name] = this.readSetStringsById(collection, col.name, id);
61
+ break;
62
+ default:
63
+ throw new Error(`Unknown data type ${col.dataType} for column '${col.name}'`);
64
+ }
65
+ }
66
+ }
67
+ return result;
68
+ };
69
+ //# sourceMappingURL=composites.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"composites.js","sourceRoot":"","sources":["../src/composites.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAUzC,QAAQ,CAAC,SAAS,CAAC,eAAe,GAAG,UAEnC,UAAkB,EAClB,EAAU;IAEV,MAAM,UAAU,GAAG,IAAI,CAAC,oBAAoB,CAAC,UAAU,CAAC,CAAC;IACzD,MAAM,MAAM,GAA2C,EAAE,CAAC;IAE1D,KAAK,MAAM,IAAI,IAAI,UAAU,EAAE,CAAC;QAC9B,QAAQ,IAAI,CAAC,QAAQ,EAAE,CAAC;YACtB,KAAK,CAAC,EAAE,UAAU;gBAChB,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,qBAAqB,CAAC,U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C,IAAI,CAAC,GAAG,IAAI,CAAC,kBAAkB,CAAC,UAAU,EAAE,GAAG,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;oBACrE,MAAM;gBACR;oBACE,MAAM,IAAI,KAAK,CAAC,qBAAqB,GAAG,CAAC,QAAQ,gBAAgB,GAAG,CAAC,IAAI,GAAG,CAAC,CAAC;YAClF,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC"}
@@ -0,0 +1,9 @@
1
+ import type { ElementData } from "./types.js";
2
+ declare module "./database.js" {
3
+ interface Database {
4
+ createElement(collection: string, data: ElementData): number;
5
+ updateElement(collection: string, id: number, data: ElementData): void;
6
+ deleteElement(collection: string, id: number): void;
7
+ }
8
+ }
9
+ //# sourceMappingURL=create.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../src/create.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,WAAW,EAAS,MAAM,YAAY,CAAC;AAErD,OAAO,QAAQ,eAAe,CAAC;IAC7B,UAAU,QAAQ;QAChB,aAAa,CAAC,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,GAAG,MAAM,CAAC;QAC7D,aAAa,CAAC,UAAU,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,GAAG,IAAI,CAAC;QACvE,aAAa,CAAC,UAAU,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,IAAI,CAAC;KACrD;CACF"}
package/dist/create.js ADDED
@@ -0,0 +1,104 @@
1
+ import { Database } from "./database.js";
2
+ import { check, QuiverError } from "./errors.js";
3
+ import { allocPtrOut, readPtrOut } from "./ffi-helpers.js";
4
+ import { getSymbols } from "./loader.js";
5
+ function setElementArray(lib, elemPtr, name, values) {
6
+ if (values.length === 0) {
7
+ check(lib.quiver_element_set_array_integer(elemPtr, name, null, 0));
8
+ return;
9
+ }
10
+ const first = values[0];
11
+ if (typeof first === "bigint") {
12
+ const arr = BigInt64Array.from(values, (v) => BigInt(v));
13
+ check(lib.quiver_element_set_array_integer(elemPtr, name, arr, values.length));
14
+ return;
15
+ }
16
+ if (typeof first === "number") {
17
+ const allIntegers = values.every((v) => Number.isInteger(v));
18
+ if (allIntegers) {
19
+ const arr = BigInt64Array.from(values, (v) => BigInt(v));
20
+ check(lib.quiver_element_set_array_integer(elemPtr, name, arr, values.length));
21
+ }
22
+ else {
23
+ const arr = Float64Array.from(values);
24
+ check(lib.quiver_element_set_array_float(elemPtr, name, arr, values.length));
25
+ }
26
+ return;
27
+ }
28
+ if (typeof first === "string") {
29
+ check(lib.quiver_element_set_array_string(elemPtr, name, values, values.length));
30
+ return;
31
+ }
32
+ throw new QuiverError(`Unsupported array element type for '${name}': ${typeof first}`);
33
+ }
34
+ function setElementField(lib, elemPtr, name, value) {
35
+ if (value === null) {
36
+ check(lib.quiver_element_set_null(elemPtr, name));
37
+ return;
38
+ }
39
+ if (typeof value === "bigint") {
40
+ check(lib.quiver_element_set_integer(elemPtr, name, value));
41
+ return;
42
+ }
43
+ if (typeof value === "number") {
44
+ if (Number.isInteger(value)) {
45
+ check(lib.quiver_element_set_integer(elemPtr, name, value));
46
+ }
47
+ else {
48
+ check(lib.quiver_element_set_float(elemPtr, name, value));
49
+ }
50
+ return;
51
+ }
52
+ if (typeof value === "string") {
53
+ check(lib.quiver_element_set_string(elemPtr, name, value));
54
+ return;
55
+ }
56
+ if (Array.isArray(value)) {
57
+ setElementArray(lib, elemPtr, name, value);
58
+ return;
59
+ }
60
+ throw new QuiverError(`Unsupported value type for '${name}': ${typeof value}`);
61
+ }
62
+ Database.prototype.createElement = function (collection, data) {
63
+ const lib = getSymbols();
64
+ const handle = this._handle;
65
+ const outElem = allocPtrOut();
66
+ check(lib.quiver_element_create(outElem));
67
+ const elemPtr = readPtrOut(outElem);
68
+ try {
69
+ for (const [key, value] of Object.entries(data)) {
70
+ if (value === undefined)
71
+ continue;
72
+ setElementField(lib, elemPtr, key, value);
73
+ }
74
+ const outId = new BigInt64Array(1);
75
+ check(lib.quiver_database_create_element(handle, collection, elemPtr, outId));
76
+ return Number(outId[0]);
77
+ }
78
+ finally {
79
+ lib.quiver_element_destroy(elemPtr);
80
+ }
81
+ };
82
+ Database.prototype.updateElement = function (collection, id, data) {
83
+ const lib = getSymbols();
84
+ const handle = this._handle;
85
+ const outElem = allocPtrOut();
86
+ check(lib.quiver_element_create(outElem));
87
+ const elemPtr = readPtrOut(outElem);
88
+ try {
89
+ for (const [key, value] of Object.entries(data)) {
90
+ if (value === undefined)
91
+ continue;
92
+ setElementField(lib, elemPtr, key, value);
93
+ }
94
+ check(lib.quiver_database_update_element(handle, collection, id, elemPtr));
95
+ }
96
+ finally {
97
+ lib.quiver_element_destroy(elemPtr);
98
+ }
99
+ };
100
+ Database.prototype.deleteElement = function (collection, id) {
101
+ const lib = getSymbols();
102
+ check(lib.quiver_database_delete_element(this._handle, collection, id));
103
+ };
104
+ //# sourceMappingURL=create.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create.js","sourceRoot":"","sources":["../src/create.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAazC,SAAS,eAAe,CAAC,GAAY,EAAE,OAAgB,EAAE,IAAY,EAAE,MAAiB;IACtF,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACxB,KAAK,CAAC,GAAG,CAAC,gCAAgC,CAAC,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;QACpE,OAAO;IACT,CAAC;IAED,MAAM,KAAK,GAAG,MAAM,CAAC,CAAC,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CAAC;IAEpC,IAAI,CAAC;QACH,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;YAChD,IAAI,KAAK,KAAK,SAAS;gBAAE,SAAS;YAClC,eAAe,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;QAC5C,CAAC;QACD,KAAK,CAAC,GAAG,CAAC,8BAA8B,CAAC,MAAM,EAAE,UAAU,EAAE,EAAE,EAAE,OAAO,CAAC,CAAC,CAAC;IAC7E,CAAC;YAAS,CAAC;QACT,GAAG,CAAC,sBAAsB,CAAC,OAAO,CAAC,CAAC;IACtC,CAAC;AACH,CAAC,CAAC;AAEF,QAAQ,CAAC,SAAS,CAAC,aAAa,GAAG,UAA0B,UAAkB,EAAE,EAAU;IACzF,MAAM,GAAG,GAAG,UAAU,EAAE,CAAC;IACzB,KAAK,CAAC,GAAG,CAAC,8BAA8B,CAAC,IAAI,CAAC,OAAO,EAAE,UAAU,EAAE,EAAE,CAAC,CAAC,CAAC;AAC1E,CAAC,CAAC"}
package/dist/csv.d.ts ADDED
@@ -0,0 +1,11 @@
1
+ export interface CsvOptions {
2
+ dateTimeFormat?: string;
3
+ enumLabels?: Record<string, Record<string, Record<string, number>>>;
4
+ }
5
+ declare module "./database.js" {
6
+ interface Database {
7
+ exportCsv(collection: string, group: string, filePath: string, options?: CsvOptions): void;
8
+ importCsv(collection: string, group: string, filePath: string, options?: CsvOptions): void;
9
+ }
10
+ }
11
+ //# sourceMappingURL=csv.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"csv.d.ts","sourceRoot":"","sources":["../src/csv.ts"],"names":[],"mappings":"AAOA,MAAM,WAAW,UAAU;IACzB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC;CACrE;AAED,OAAO,QAAQ,eAAe,CAAC;IAC7B,UAAU,QAAQ;QAChB,SAAS,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,UAAU,GAAG,IAAI,CAAC;QAC3F,SAAS,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,UAAU,GAAG,IAAI,CAAC;KAC5F;CACF"}
package/dist/csv.js ADDED
@@ -0,0 +1,67 @@
1
+ import koffi from "koffi";
2
+ import { Database } from "./database.js";
3
+ import { check } from "./errors.js";
4
+ import { allocNativeInt64, allocNativeString, allocNativeStringArray, nativeAddress } from "./ffi-helpers.js";
5
+ import { getSymbols } from "./loader.js";
6
+ /**
7
+ * Build the 56-byte quiver_csv_options_t struct as a Buffer.
8
+ * Returns [structBuffer, keepalive] where keepalive prevents GC of native allocations.
9
+ */
10
+ function buildCsvOptionsBuffer(options) {
11
+ const buf = Buffer.alloc(56);
12
+ const keepalive = [];
13
+ const dtfStr = allocNativeString(options?.dateTimeFormat ?? "");
14
+ keepalive.push(dtfStr);
15
+ buf.writeBigUInt64LE(nativeAddress(dtfStr), 0);
16
+ if (!options?.enumLabels || Object.keys(options.enumLabels).length === 0) {
17
+ return [buf, keepalive];
18
+ }
19
+ const groupAttrNames = [];
20
+ const groupLocaleNames = [];
21
+ const groupEntryCounts = [];
22
+ const allLabels = [];
23
+ const allValues = [];
24
+ for (const [attrName, locales] of Object.entries(options.enumLabels)) {
25
+ for (const [localeName, entries] of Object.entries(locales)) {
26
+ groupAttrNames.push(attrName);
27
+ groupLocaleNames.push(localeName);
28
+ groupEntryCounts.push(Object.keys(entries).length);
29
+ for (const [label, value] of Object.entries(entries)) {
30
+ allLabels.push(label);
31
+ allValues.push(value);
32
+ }
33
+ }
34
+ }
35
+ const groupCount = groupAttrNames.length;
36
+ const { table: attrTable, keepalive: attrPtrs } = allocNativeStringArray(groupAttrNames);
37
+ keepalive.push(attrTable, ...attrPtrs);
38
+ const { table: localeTable, keepalive: localePtrs } = allocNativeStringArray(groupLocaleNames);
39
+ keepalive.push(localeTable, ...localePtrs);
40
+ const entryCounts = koffi.alloc("uint64_t", groupCount);
41
+ for (let i = 0; i < groupCount; i++) {
42
+ koffi.encode(entryCounts, i * 8, "uint64_t", BigInt(groupEntryCounts[i]));
43
+ }
44
+ keepalive.push(entryCounts);
45
+ const { table: labelsTable, keepalive: labelPtrs } = allocNativeStringArray(allLabels);
46
+ keepalive.push(labelsTable, ...labelPtrs);
47
+ const valuesArr = allocNativeInt64(allValues);
48
+ keepalive.push(valuesArr);
49
+ buf.writeBigUInt64LE(nativeAddress(attrTable), 8);
50
+ buf.writeBigUInt64LE(nativeAddress(localeTable), 16);
51
+ buf.writeBigUInt64LE(nativeAddress(entryCounts), 24);
52
+ buf.writeBigUInt64LE(nativeAddress(labelsTable), 32);
53
+ buf.writeBigUInt64LE(nativeAddress(valuesArr), 40);
54
+ buf.writeBigUInt64LE(BigInt(groupCount), 48);
55
+ return [buf, keepalive];
56
+ }
57
+ Database.prototype.exportCsv = function (collection, group, filePath, options) {
58
+ const lib = getSymbols();
59
+ const [optsBuf, _keepalive] = buildCsvOptionsBuffer(options);
60
+ check(lib.quiver_database_export_csv(this._handle, collection, group, filePath, optsBuf));
61
+ };
62
+ Database.prototype.importCsv = function (collection, group, filePath, options) {
63
+ const lib = getSymbols();
64
+ const [optsBuf, _keepalive] = buildCsvOptionsBuffer(options);
65
+ check(lib.quiver_database_import_csv(this._handle, collection, group, filePath, optsBuf));
66
+ };
67
+ //# sourceMappingURL=csv.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"csv.js","sourceRoot":"","sources":["../src/csv.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,QAAQ,EAAE,M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AAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,qBAAqB,CAAC,OAAO,CAAC,CAAC;IAC7D,KAAK,CAAC,GAAG,CAAC,0BAA0B,CAAC,IAAI,CAAC,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAC;AAC5F,CAAC,CAAC"}
@@ -0,0 +1,13 @@
1
+ import type { NativePointer } from "./loader.js";
2
+ export declare class Database {
3
+ private _ptr;
4
+ private _closed;
5
+ private constructor();
6
+ static fromSchema(dbPath: string, schemaPath: string): Database;
7
+ static fromMigrations(dbPath: string, migrationsPath: string): Database;
8
+ close(): void;
9
+ private ensureOpen;
10
+ /** @internal */
11
+ get _handle(): NativePointer;
12
+ }
13
+ //# sourceMappingURL=database.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"database.d.ts","sourceRoot":"","sources":["../src/database.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAKjD,qBAAa,QAAQ;IACnB,OAAO,CAAC,IAAI,CAAgB;IAC5B,OAAO,CAAC,OAAO,CAAS;IAExB,OAAO;IAIP,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,QAAQ;IAU/D,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,GAAG,QAAQ;IAUvE,KAAK,IAAI,IAAI;IAOb,OAAO,CAAC,UAAU;IAMlB,gBAAgB;IAChB,IAAI,OAAO,IAAI,aAAa,CAG3B;CACF"}
@@ -0,0 +1,42 @@
1
+ import { check, QuiverError } from "./errors.js";
2
+ import { allocPtrOut, makeDefaultOptions, readPtrOut } from "./ffi-helpers.js";
3
+ import { getSymbols } from "./loader.js";
4
+ export class Database {
5
+ _ptr;
6
+ _closed = false;
7
+ constructor(nativePtr) {
8
+ this._ptr = nativePtr;
9
+ }
10
+ static fromSchema(dbPath, schemaPath) {
11
+ const lib = getSymbols();
12
+ const options = makeDefaultOptions();
13
+ const outDb = allocPtrOut();
14
+ check(lib.quiver_database_from_schema(dbPath, schemaPath, options, outDb));
15
+ return new Database(readPtrOut(outDb));
16
+ }
17
+ static fromMigrations(dbPath, migrationsPath) {
18
+ const lib = getSymbols();
19
+ const options = makeDefaultOptions();
20
+ const outDb = allocPtrOut();
21
+ check(lib.quiver_database_from_migrations(dbPath, migrationsPath, options, outDb));
22
+ return new Database(readPtrOut(outDb));
23
+ }
24
+ close() {
25
+ if (this._closed)
26
+ return;
27
+ const lib = getSymbols();
28
+ check(lib.quiver_database_close(this._ptr));
29
+ this._closed = true;
30
+ }
31
+ ensureOpen() {
32
+ if (this._closed) {
33
+ throw new QuiverError("Database is closed");
34
+ }
35
+ }
36
+ /** @internal */
37
+ get _handle() {
38
+ this.ensureOpen();
39
+ return this._ptr;
40
+ }
41
+ }
42
+ //# sourceMappingURL=database.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"database.js","sourceRoot":"","sources":["../src/database.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,WAAW,EAAE,kBAAkB,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC/E,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,MAAM,OAAO,QAAQ;IACX,IAAI,CAAgB;IACpB,OAAO,GAAG,KAAK,CAAC;IAExB,YAAoB,SAAwB;QAC1C,IAAI,CAAC,IAAI,GAAG,SAAS,CAAC;IACxB,CAAC;IAED,MAAM,CAAC,UAAU,CAAC,MAAc,EAAE,UAAkB;QAClD,MAAM,GAAG,GAAG,UAAU,EAAE,CAAC;QACzB,MAAM,OAAO,GAAG,kBAAkB,EAAE,CAAC;QACrC,MAAM,KAAK,GAAG,WAAW,EAAE,CAAC;QAE5B,KAAK,CAAC,GAAG,CAAC,2BAA2B,CAAC,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC;QAE3E,OAAO,IAAI,QAAQ,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC;IACzC,CAAC;IAED,MAAM,CAAC,cAAc,CAAC,MAAc,EAAE,cAAsB;QAC1D,MAAM,GAAG,GAAG,UAAU,EAAE,CAAC;QACzB,MAAM,OAAO,GAAG,kBAAkB,EAAE,CAAC;QACrC,MAAM,KAAK,GAAG,WAAW,EAAE,CAAC;QAE5B,KAAK,CAAC,GAAG,CAAC,+BAA+B,CAAC,MAAM,EAAE,cAAc,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC;QAEnF,OAAO,IAAI,QAAQ,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC;IACzC,CAAC;IAED,KAAK;QACH,IAAI,IAAI,CAAC,OAAO;YAAE,OAAO;QACzB,MAAM,GAAG,GAAG,UAAU,EAAE,CAAC;QACzB,KAAK,CAAC,GAAG,CAAC,qBAAqB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QAC5C,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;IACtB,CAAC;IAEO,UAAU;QAChB,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YACjB,MAAM,IAAI,WAAW,CAAC,oBAAoB,CAAC,CAAC;QAC9C,CAAC;IACH,CAAC;IAED,gBAAgB;IAChB,IAAI,OAAO;QACT,IAAI,CAAC,UAAU,EAAE,CAAC;QAClB,OAAO,IAAI,CAAC,IAAI,CAAC;IACnB,CAAC;CACF"}
@@ -0,0 +1,5 @@
1
+ export declare class QuiverError extends Error {
2
+ constructor(message: string);
3
+ }
4
+ export declare function check(err: number): void;
5
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAEA,qBAAa,WAAY,SAAQ,KAAK;gBACxB,OAAO,EAAE,MAAM;CAI5B;AAED,wBAAgB,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CASvC"}
package/dist/errors.js ADDED
@@ -0,0 +1,18 @@
1
+ import { getSymbols } from "./loader.js";
2
+ export class QuiverError extends Error {
3
+ constructor(message) {
4
+ super(message);
5
+ this.name = "QuiverError";
6
+ }
7
+ }
8
+ export function check(err) {
9
+ if (err !== 0) {
10
+ const lib = getSymbols();
11
+ const detail = lib.quiver_get_last_error();
12
+ if (detail) {
13
+ throw new QuiverError(detail);
14
+ }
15
+ throw new QuiverError("Unknown error");
16
+ }
17
+ }
18
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,MAAM,OAAO,WAAY,SAAQ,KAAK;IACpC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,aAAa,CAAC;IAC5B,CAAC;CACF;AAED,MAAM,UAAU,KAAK,CAAC,GAAW;IAC/B,IAAI,GAAG,KAAK,CAAC,EAAE,CAAC;QACd,MAAM,GAAG,GAAG,UAAU,EAAE,CAAC;QACzB,MAAM,MAAM,GAAG,GAAG,CAAC,qBAAqB,EAAE,CAAC;QAC3C,IAAI,MAAM,EAAE,CAAC;YACX,MAAM,IAAI,WAAW,CAAC,MAAM,CAAC,CAAC;QAChC,CAAC;QACD,MAAM,IAAI,WAAW,CAAC,eAAe,CAAC,CAAC;IACzC,CAAC;AACH,CAAC"}