quiverdb 0.5.0 → 0.6.0

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 +10 -10
  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 +19 -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/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
- };
package/tsconfig.json DELETED
@@ -1,13 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "strict": true,
4
- "target": "ESNext",
5
- "module": "ESNext",
6
- "moduleResolution": "bundler",
7
- "esModuleInterop": true,
8
- "skipLibCheck": true,
9
- "noEmit": true,
10
- "types": ["@types/bun"]
11
- },
12
- "include": ["src/**/*.ts", "test/**/*.ts"]
13
- }