hyperdb-wasm 0.0.27099-dev.wasm.g0a1be56f → 0.0.27099-dev.wasm.g3764e520
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api.d.ts +11 -7
- package/dist/browser.js +39 -14
- package/dist/index.d.ts +1 -1
- package/dist/index.node.d.ts +1 -1
- package/dist/node.js +39 -14
- package/examples/browser-attached-databases.html +12 -13
- package/examples/browser.html +1 -1
- package/examples/node-attached-databases.mjs +14 -14
- package/examples/node.mjs +6 -6
- package/package.json +1 -1
package/dist/api.d.ts
CHANGED
|
@@ -72,10 +72,13 @@ export interface QueryInfo {
|
|
|
72
72
|
readonly preExecutionMetrics: QueryMetrics | null;
|
|
73
73
|
readonly executionMetrics: QueryMetrics | null;
|
|
74
74
|
}
|
|
75
|
-
export interface
|
|
76
|
-
readonly result: Result;
|
|
75
|
+
export interface QueryOperation {
|
|
77
76
|
readonly info: Promise<QueryInfo>;
|
|
78
77
|
}
|
|
78
|
+
export interface QueryPromise<Result> extends Promise<Result>, QueryOperation {
|
|
79
|
+
}
|
|
80
|
+
export interface QueryStreamIPC extends AsyncIterable<Uint8Array>, QueryOperation {
|
|
81
|
+
}
|
|
79
82
|
export declare class HyperDBError extends Error {
|
|
80
83
|
readonly sqlState: string;
|
|
81
84
|
readonly errorSource: HyperDBErrorSource;
|
|
@@ -110,14 +113,15 @@ export declare class HyperDBConnection {
|
|
|
110
113
|
private closing;
|
|
111
114
|
constructor(client: HyperDBClient, connection: number, onClose?: () => void);
|
|
112
115
|
close(): Promise<void>;
|
|
113
|
-
|
|
114
|
-
queryIPC(sql: string):
|
|
115
|
-
|
|
116
|
+
queryStreamIPC(sql: string): QueryStreamIPC;
|
|
117
|
+
queryIPC(sql: string): QueryPromise<Uint8Array>;
|
|
118
|
+
queryStream<T extends TypeMap = {
|
|
116
119
|
[key: string]: DataType;
|
|
117
|
-
}>(sql: string):
|
|
120
|
+
}>(sql: string): QueryPromise<AsyncRecordBatchStreamReader<T>>;
|
|
118
121
|
query<T extends TypeMap = {
|
|
119
122
|
[key: string]: DataType;
|
|
120
|
-
}>(sql: string):
|
|
123
|
+
}>(sql: string): QueryPromise<Table<T>>;
|
|
124
|
+
execute(sql: string): QueryPromise<bigint | null>;
|
|
121
125
|
insertArrowTable(table: Table, options: ArrowInsertOptions): Promise<void>;
|
|
122
126
|
insertArrowIPCFromPath(path: string, options: ArrowInsertOptions): Promise<void>;
|
|
123
127
|
private insertArrowIPCFromPathInternal;
|
package/dist/browser.js
CHANGED
|
@@ -12156,8 +12156,24 @@ function deferred() {
|
|
|
12156
12156
|
void promise.catch(() => void 0);
|
|
12157
12157
|
return { promise, resolve, reject };
|
|
12158
12158
|
}
|
|
12159
|
-
function
|
|
12160
|
-
return
|
|
12159
|
+
function queryPromise(result, info) {
|
|
12160
|
+
return Object.assign(result, { info });
|
|
12161
|
+
}
|
|
12162
|
+
function queryIPCStream(result, info) {
|
|
12163
|
+
return Object.assign(result, { info });
|
|
12164
|
+
}
|
|
12165
|
+
function affectedRowCount(info) {
|
|
12166
|
+
switch (info.statementKind) {
|
|
12167
|
+
case "COPY":
|
|
12168
|
+
case "DELETE":
|
|
12169
|
+
case "FETCH":
|
|
12170
|
+
case "INSERT":
|
|
12171
|
+
case "MERGE":
|
|
12172
|
+
case "UPDATE":
|
|
12173
|
+
return info.rowCount;
|
|
12174
|
+
default:
|
|
12175
|
+
return null;
|
|
12176
|
+
}
|
|
12161
12177
|
}
|
|
12162
12178
|
function isRecord2(value) {
|
|
12163
12179
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
@@ -12407,7 +12423,7 @@ var HyperDBConnection = class {
|
|
|
12407
12423
|
}
|
|
12408
12424
|
await this.closing;
|
|
12409
12425
|
}
|
|
12410
|
-
|
|
12426
|
+
queryStreamIPC(sql) {
|
|
12411
12427
|
const connection = this;
|
|
12412
12428
|
const queryInfo = deferred();
|
|
12413
12429
|
const result = (async function* () {
|
|
@@ -12475,14 +12491,14 @@ var HyperDBConnection = class {
|
|
|
12475
12491
|
}
|
|
12476
12492
|
}
|
|
12477
12493
|
})();
|
|
12478
|
-
return
|
|
12494
|
+
return queryIPCStream(result, queryInfo.promise);
|
|
12479
12495
|
}
|
|
12480
12496
|
queryIPC(sql) {
|
|
12481
|
-
const stream = this.
|
|
12497
|
+
const stream = this.queryStreamIPC(sql);
|
|
12482
12498
|
const result = (async () => {
|
|
12483
12499
|
const chunks = [];
|
|
12484
12500
|
let length = 0;
|
|
12485
|
-
for await (const chunk of stream
|
|
12501
|
+
for await (const chunk of stream) {
|
|
12486
12502
|
chunks.push(chunk);
|
|
12487
12503
|
length += chunk.byteLength;
|
|
12488
12504
|
}
|
|
@@ -12494,28 +12510,37 @@ var HyperDBConnection = class {
|
|
|
12494
12510
|
}
|
|
12495
12511
|
return bytes;
|
|
12496
12512
|
})();
|
|
12497
|
-
return
|
|
12513
|
+
return queryPromise(result, stream.info);
|
|
12498
12514
|
}
|
|
12499
|
-
|
|
12500
|
-
const stream = this.
|
|
12515
|
+
queryStream(sql) {
|
|
12516
|
+
const stream = this.queryStreamIPC(sql);
|
|
12501
12517
|
const result = (async () => {
|
|
12502
|
-
const reader = await RecordBatchReader.from(stream
|
|
12518
|
+
const reader = await RecordBatchReader.from(stream);
|
|
12503
12519
|
if (!reader.isAsync() || !reader.isStream()) throw new Error("query did not produce an Arrow async stream");
|
|
12504
12520
|
await reader.open();
|
|
12505
12521
|
if (!reader.schema) throw new Error("query did not produce an Arrow schema");
|
|
12506
12522
|
return reader;
|
|
12507
12523
|
})();
|
|
12508
|
-
return
|
|
12524
|
+
return queryPromise(result, stream.info);
|
|
12509
12525
|
}
|
|
12510
12526
|
query(sql) {
|
|
12511
|
-
const stream = this.
|
|
12527
|
+
const stream = this.queryStream(sql);
|
|
12512
12528
|
const result = (async () => {
|
|
12513
|
-
const reader = await stream
|
|
12529
|
+
const reader = await stream;
|
|
12514
12530
|
const batches = [];
|
|
12515
12531
|
for await (const batch of reader) batches.push(batch);
|
|
12516
12532
|
return new Table(reader.schema, batches);
|
|
12517
12533
|
})();
|
|
12518
|
-
return
|
|
12534
|
+
return queryPromise(result, stream.info);
|
|
12535
|
+
}
|
|
12536
|
+
execute(sql) {
|
|
12537
|
+
const stream = this.queryStreamIPC(sql);
|
|
12538
|
+
const result = (async () => {
|
|
12539
|
+
for await (const _chunk of stream) {
|
|
12540
|
+
}
|
|
12541
|
+
return affectedRowCount(await stream.info);
|
|
12542
|
+
})();
|
|
12543
|
+
return queryPromise(result, stream.info);
|
|
12519
12544
|
}
|
|
12520
12545
|
async insertArrowTable(table, options) {
|
|
12521
12546
|
this.ensureAvailable();
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { HyperDB as BaseHyperDB } from './api.js';
|
|
2
2
|
import type { BrowserCreateOptions, MountAccessMode, MountedResource, MountOptions } from './api.js';
|
|
3
3
|
export { HyperDBConnection, HyperDBError } from './api.js';
|
|
4
|
-
export type { ArrowInsertOptions, BrowserCreateOptions, HyperDBSettingValue, HyperDBSettings, MountAccessMode, MountedResource, MountOptions, QueryInfo, QueryMetrics, QueryMetricValue,
|
|
4
|
+
export type { ArrowInsertOptions, BrowserCreateOptions, HyperDBSettingValue, HyperDBSettings, MountAccessMode, MountedResource, MountOptions, QueryInfo, QueryMetrics, QueryMetricValue, QueryOperation, QueryPromise, QueryStreamIPC, QueryTimings } from './api.js';
|
|
5
5
|
export type { SetupProgress } from './protocol.js';
|
|
6
6
|
export type { HyperDBErrorSource } from './protocol.js';
|
|
7
7
|
export interface FileSystemDirectoryHandleLike {
|
package/dist/index.node.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { HyperDB as BaseHyperDB } from './api.js';
|
|
|
2
2
|
import type { HyperDBCreateOptions, MountedResource, MountOptions } from './api.js';
|
|
3
3
|
import type { NodeClientOptions } from './node.js';
|
|
4
4
|
export { HyperDBConnection, HyperDBError } from './api.js';
|
|
5
|
-
export type { ArrowInsertOptions, HyperDBSettingValue, HyperDBSettings, MountAccessMode, MountedResource, MountOptions, QueryInfo, QueryMetrics, QueryMetricValue,
|
|
5
|
+
export type { ArrowInsertOptions, HyperDBSettingValue, HyperDBSettings, MountAccessMode, MountedResource, MountOptions, QueryInfo, QueryMetrics, QueryMetricValue, QueryOperation, QueryPromise, QueryStreamIPC, QueryTimings } from './api.js';
|
|
6
6
|
export type { HyperDBErrorSource } from './protocol.js';
|
|
7
7
|
export type NodeCreateOptions = NodeClientOptions & HyperDBCreateOptions;
|
|
8
8
|
export declare class HyperDB extends BaseHyperDB {
|
package/dist/node.js
CHANGED
|
@@ -12325,8 +12325,24 @@ function deferred() {
|
|
|
12325
12325
|
void promise.catch(() => void 0);
|
|
12326
12326
|
return { promise, resolve, reject };
|
|
12327
12327
|
}
|
|
12328
|
-
function
|
|
12329
|
-
return
|
|
12328
|
+
function queryPromise(result, info) {
|
|
12329
|
+
return Object.assign(result, { info });
|
|
12330
|
+
}
|
|
12331
|
+
function queryIPCStream(result, info) {
|
|
12332
|
+
return Object.assign(result, { info });
|
|
12333
|
+
}
|
|
12334
|
+
function affectedRowCount(info) {
|
|
12335
|
+
switch (info.statementKind) {
|
|
12336
|
+
case "COPY":
|
|
12337
|
+
case "DELETE":
|
|
12338
|
+
case "FETCH":
|
|
12339
|
+
case "INSERT":
|
|
12340
|
+
case "MERGE":
|
|
12341
|
+
case "UPDATE":
|
|
12342
|
+
return info.rowCount;
|
|
12343
|
+
default:
|
|
12344
|
+
return null;
|
|
12345
|
+
}
|
|
12330
12346
|
}
|
|
12331
12347
|
function isRecord2(value) {
|
|
12332
12348
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
@@ -12576,7 +12592,7 @@ var HyperDBConnection = class {
|
|
|
12576
12592
|
}
|
|
12577
12593
|
await this.closing;
|
|
12578
12594
|
}
|
|
12579
|
-
|
|
12595
|
+
queryStreamIPC(sql) {
|
|
12580
12596
|
const connection = this;
|
|
12581
12597
|
const queryInfo = deferred();
|
|
12582
12598
|
const result = (async function* () {
|
|
@@ -12644,14 +12660,14 @@ var HyperDBConnection = class {
|
|
|
12644
12660
|
}
|
|
12645
12661
|
}
|
|
12646
12662
|
})();
|
|
12647
|
-
return
|
|
12663
|
+
return queryIPCStream(result, queryInfo.promise);
|
|
12648
12664
|
}
|
|
12649
12665
|
queryIPC(sql) {
|
|
12650
|
-
const stream = this.
|
|
12666
|
+
const stream = this.queryStreamIPC(sql);
|
|
12651
12667
|
const result = (async () => {
|
|
12652
12668
|
const chunks = [];
|
|
12653
12669
|
let length = 0;
|
|
12654
|
-
for await (const chunk of stream
|
|
12670
|
+
for await (const chunk of stream) {
|
|
12655
12671
|
chunks.push(chunk);
|
|
12656
12672
|
length += chunk.byteLength;
|
|
12657
12673
|
}
|
|
@@ -12663,28 +12679,37 @@ var HyperDBConnection = class {
|
|
|
12663
12679
|
}
|
|
12664
12680
|
return bytes;
|
|
12665
12681
|
})();
|
|
12666
|
-
return
|
|
12682
|
+
return queryPromise(result, stream.info);
|
|
12667
12683
|
}
|
|
12668
|
-
|
|
12669
|
-
const stream = this.
|
|
12684
|
+
queryStream(sql) {
|
|
12685
|
+
const stream = this.queryStreamIPC(sql);
|
|
12670
12686
|
const result = (async () => {
|
|
12671
|
-
const reader = await RecordBatchReader.from(stream
|
|
12687
|
+
const reader = await RecordBatchReader.from(stream);
|
|
12672
12688
|
if (!reader.isAsync() || !reader.isStream()) throw new Error("query did not produce an Arrow async stream");
|
|
12673
12689
|
await reader.open();
|
|
12674
12690
|
if (!reader.schema) throw new Error("query did not produce an Arrow schema");
|
|
12675
12691
|
return reader;
|
|
12676
12692
|
})();
|
|
12677
|
-
return
|
|
12693
|
+
return queryPromise(result, stream.info);
|
|
12678
12694
|
}
|
|
12679
12695
|
query(sql) {
|
|
12680
|
-
const stream = this.
|
|
12696
|
+
const stream = this.queryStream(sql);
|
|
12681
12697
|
const result = (async () => {
|
|
12682
|
-
const reader = await stream
|
|
12698
|
+
const reader = await stream;
|
|
12683
12699
|
const batches = [];
|
|
12684
12700
|
for await (const batch of reader) batches.push(batch);
|
|
12685
12701
|
return new Table(reader.schema, batches);
|
|
12686
12702
|
})();
|
|
12687
|
-
return
|
|
12703
|
+
return queryPromise(result, stream.info);
|
|
12704
|
+
}
|
|
12705
|
+
execute(sql) {
|
|
12706
|
+
const stream = this.queryStreamIPC(sql);
|
|
12707
|
+
const result = (async () => {
|
|
12708
|
+
for await (const _chunk of stream) {
|
|
12709
|
+
}
|
|
12710
|
+
return affectedRowCount(await stream.info);
|
|
12711
|
+
})();
|
|
12712
|
+
return queryPromise(result, stream.info);
|
|
12688
12713
|
}
|
|
12689
12714
|
async insertArrowTable(table, options) {
|
|
12690
12715
|
this.ensureAvailable();
|
|
@@ -26,22 +26,22 @@
|
|
|
26
26
|
const connection = await database.connect();
|
|
27
27
|
|
|
28
28
|
try {
|
|
29
|
-
await
|
|
30
|
-
await
|
|
31
|
-
await connection.
|
|
32
|
-
await connection.
|
|
29
|
+
await connection.execute('create database "readings.hyper"');
|
|
30
|
+
await connection.execute(`create database "${persistentName}.hyper"`);
|
|
31
|
+
await connection.execute('attach database "readings.hyper" as readings');
|
|
32
|
+
await connection.execute(`attach database "${persistentName}.hyper" as sensors`);
|
|
33
33
|
|
|
34
|
-
await connection.
|
|
35
|
-
await connection.
|
|
36
|
-
await connection.
|
|
37
|
-
await connection.
|
|
34
|
+
await connection.execute('create table readings.public.values_table(sensor_id integer, reading integer)');
|
|
35
|
+
await connection.execute('insert into readings.public.values_table values (101, 18), (202, 22)');
|
|
36
|
+
await connection.execute('create table sensors.public.locations(sensor_id integer, location text)');
|
|
37
|
+
await connection.execute("insert into sensors.public.locations values (101, 'office'), (202, 'lab')");
|
|
38
38
|
|
|
39
39
|
const table = await connection.query(`
|
|
40
40
|
select locations.location, values_table.reading
|
|
41
41
|
from readings.public.values_table
|
|
42
42
|
join sensors.public.locations using (sensor_id)
|
|
43
43
|
order by locations.location
|
|
44
|
-
`)
|
|
44
|
+
`);
|
|
45
45
|
const names = table.schema.fields.map(({ name }) => name);
|
|
46
46
|
const tableElement = document.createElement('table');
|
|
47
47
|
const header = tableElement.createTHead().insertRow();
|
|
@@ -59,11 +59,10 @@
|
|
|
59
59
|
result.append(tableElement);
|
|
60
60
|
status.textContent = 'Joined a memory database with a persistent database';
|
|
61
61
|
} finally {
|
|
62
|
-
await connection.
|
|
63
|
-
await connection.
|
|
62
|
+
await connection.execute('detach database readings, sensors');
|
|
63
|
+
await connection.execute('drop database "readings.hyper"');
|
|
64
|
+
await connection.execute(`drop database "${persistentName}.hyper"`);
|
|
64
65
|
await connection.close();
|
|
65
|
-
await database.dropDatabase('readings');
|
|
66
|
-
await database.dropDatabase(persistentName);
|
|
67
66
|
await database.terminate();
|
|
68
67
|
}
|
|
69
68
|
</script>
|
package/examples/browser.html
CHANGED
|
@@ -65,7 +65,7 @@ order by sensor_id</textarea>
|
|
|
65
65
|
run.disabled = true;
|
|
66
66
|
status.textContent = 'Running...';
|
|
67
67
|
try {
|
|
68
|
-
const table = await connection.query(sql.value)
|
|
68
|
+
const table = await connection.query(sql.value);
|
|
69
69
|
render(table);
|
|
70
70
|
status.textContent = `${table.numRows} row(s)`;
|
|
71
71
|
} catch (error) {
|
|
@@ -8,30 +8,30 @@ const database = await HyperDB.create({ storagePath });
|
|
|
8
8
|
const connection = await database.connect();
|
|
9
9
|
|
|
10
10
|
try {
|
|
11
|
-
await connection.
|
|
12
|
-
await connection.
|
|
13
|
-
await connection.
|
|
14
|
-
await connection.
|
|
11
|
+
await connection.execute('create database "readings.hyper"');
|
|
12
|
+
await connection.execute('create database "sensors.hyper"');
|
|
13
|
+
await connection.execute('attach database "readings.hyper" as readings');
|
|
14
|
+
await connection.execute('attach database "sensors.hyper" as sensors');
|
|
15
15
|
|
|
16
|
-
await connection.
|
|
17
|
-
await connection.
|
|
18
|
-
await connection.
|
|
19
|
-
await connection.
|
|
20
|
-
await connection.
|
|
16
|
+
await connection.execute('create table readings.public.values_table(sensor_id integer, reading integer)');
|
|
17
|
+
await connection.execute('create table sensors.public.locations(sensor_id integer, location text)');
|
|
18
|
+
await connection.execute('begin');
|
|
19
|
+
await connection.execute('insert into readings.public.values_table values (101, 18), (202, 22)');
|
|
20
|
+
await connection.execute("insert into sensors.public.locations values (101, 'office'), (202, 'lab')");
|
|
21
21
|
|
|
22
22
|
const result = await connection.query(`
|
|
23
23
|
select locations.location, values_table.reading
|
|
24
24
|
from readings.public.values_table
|
|
25
25
|
join sensors.public.locations using (sensor_id)
|
|
26
26
|
order by locations.location
|
|
27
|
-
`)
|
|
27
|
+
`);
|
|
28
28
|
console.table(result.toArray().map((row) => row.toJSON()));
|
|
29
29
|
} finally {
|
|
30
|
-
await connection.
|
|
31
|
-
await connection.
|
|
30
|
+
await connection.execute('commit');
|
|
31
|
+
await connection.execute('detach database readings, sensors');
|
|
32
|
+
await connection.execute('drop database "readings.hyper"');
|
|
33
|
+
await connection.execute('drop database "sensors.hyper"');
|
|
32
34
|
await connection.close();
|
|
33
|
-
await connection.queryIPC('drop database "readings.hyper"').result;
|
|
34
|
-
await connection.queryIPC('drop database "sensors.hyper"').result;
|
|
35
35
|
await database.terminate();
|
|
36
36
|
await rm(storagePath, { recursive: true, force: true });
|
|
37
37
|
}
|
package/examples/node.mjs
CHANGED
|
@@ -20,7 +20,7 @@ try {
|
|
|
20
20
|
select
|
|
21
21
|
6 * 7 as answer,
|
|
22
22
|
upper('query Hyper from Node.js') as message
|
|
23
|
-
`)
|
|
23
|
+
`);
|
|
24
24
|
console.table(rows(expressions));
|
|
25
25
|
|
|
26
26
|
const grouped = await connection.query(`
|
|
@@ -32,14 +32,14 @@ try {
|
|
|
32
32
|
) as readings(sensor_id, reading)
|
|
33
33
|
group by sensor_id
|
|
34
34
|
order by sensor_id
|
|
35
|
-
`)
|
|
35
|
+
`);
|
|
36
36
|
console.table(rows(grouped));
|
|
37
37
|
|
|
38
|
-
const reader = await connection.
|
|
38
|
+
const reader = await connection.queryStream(`
|
|
39
39
|
select value, value * value as square
|
|
40
40
|
from generate_series(1, 5) as numbers(value)
|
|
41
41
|
order by value
|
|
42
|
-
`)
|
|
42
|
+
`);
|
|
43
43
|
for await (const batch of reader) {
|
|
44
44
|
console.log(`streamed Arrow batch with ${batch.numRows} rows`);
|
|
45
45
|
}
|
|
@@ -59,9 +59,9 @@ try {
|
|
|
59
59
|
await connection.insertArrowIPCFromPath(readingsPath, { name: 'temporary_readings' });
|
|
60
60
|
|
|
61
61
|
console.log('Arrow IPC staged in the in-memory WasmFS:');
|
|
62
|
-
console.table(rows(await connection.query('select * from memory_readings order by sensor_id')
|
|
62
|
+
console.table(rows(await connection.query('select * from memory_readings order by sensor_id')));
|
|
63
63
|
console.log(`Arrow IPC read from the Node temporary file ${readingsPath}:`);
|
|
64
|
-
console.table(rows(await connection.query('select * from temporary_readings order by sensor_id')
|
|
64
|
+
console.table(rows(await connection.query('select * from temporary_readings order by sensor_id')));
|
|
65
65
|
} finally {
|
|
66
66
|
await connection.close();
|
|
67
67
|
await database.terminate();
|