@minnowdb/core 0.6.2 → 0.6.3
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/engine/client.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type CompactionJobRecord, type GarbageCollectionJobRecord, type StorageIntegrityMode, type StorageIntegrityReport, type StorageStats, type InterruptedSnapshotImport, type InterruptedSnapshotImportAbortResult } from "../storage/types.js";
|
|
2
2
|
import { type BatchRow, type InsertBatchInput } from "./batch.js";
|
|
3
3
|
import type { Catalog } from "./catalog.js";
|
|
4
|
-
import type { BatchValue, BufferPoolStats, StagedWriteResult, BufferedFlushResult, BufferedWriterOptions, CancelCompactionJobResult, CollectGarbageOptions, CollectGarbageStepOptions, CompactTableOptions, CompactTableResult, CompactTableStepOptions, CompactionJobProgress, CreateTableInput, DatabaseRow, MigrateOptions, DeleteBatchInput, DeleteBatchResult, ExecuteResult, GarbageCollectionProgress, GarbageCollectionResult, MaintenanceStatus, InsertBatchResult, QueryOptions, QueryExecutionStats, QueryCursorOptions, QuerySpillCleanupOptions, QuerySpillCleanupResult, ReadTableOptions, RunStatementOptions, SnapshotExportOptions, SnapshotImportOptions, TableDefinition, UpdateBatchInput, UpdateBatchResult, UpsertBatchResult, UpsertOptions, VisibleSegmentPage, VisibleSegmentPageOptions } from "./database.js";
|
|
4
|
+
import type { BatchValue, BufferPoolStats, StagedWriteResult, BufferedFlushResult, BufferedWriterOptions, CancelCompactionJobResult, CollectGarbageOptions, CollectGarbageStepOptions, CompactTableOptions, CompactTableResult, CompactTableStepOptions, CompactionJobProgress, CreateTableInput, DatabaseRow, MigrateOptions, DeleteBatchInput, DeleteBatchResult, ExecuteOptions, ExecuteResult, GarbageCollectionProgress, GarbageCollectionResult, MaintenanceStatus, InsertBatchResult, QueryOptions, QueryExecutionStats, QueryCursorOptions, QuerySpillCleanupOptions, QuerySpillCleanupResult, ReadTableOptions, RunStatementOptions, SnapshotExportOptions, SnapshotImportOptions, TableDefinition, UpdateBatchInput, UpdateBatchResult, UpsertBatchResult, UpsertOptions, VisibleSegmentPage, VisibleSegmentPageOptions } from "./database.js";
|
|
5
5
|
import type { LiveQueryInput, LiveQueryInvalidation, LiveQueryObserveOptions, LiveQueryStats, LiveQuerySubscribeOptions } from "./live.js";
|
|
6
6
|
import type { CompiledQuery, CompiledStatement, QueryResult, QueryValue } from "./query.js";
|
|
7
7
|
import type { AnyTable, SchemaDefinition } from "./schema.js";
|
|
@@ -127,7 +127,7 @@ export declare class MinnowDatabaseClient {
|
|
|
127
127
|
__row?: TRow;
|
|
128
128
|
}): Promise<TRow[]>;
|
|
129
129
|
explain(sql: string): Promise<string>;
|
|
130
|
-
execute(sql: string, params?: readonly QueryValue[]): Promise<ExecuteResult>;
|
|
130
|
+
execute(sql: string, params?: readonly QueryValue[], options?: ExecuteOptions): Promise<ExecuteResult>;
|
|
131
131
|
/** Executes a compiled statement from the typed mutation builders in the worker. */
|
|
132
132
|
runStatement(statement: CompiledStatement, options?: RunStatementOptions): Promise<ExecuteResult>;
|
|
133
133
|
/**
|
package/dist/engine/client.js
CHANGED
|
@@ -279,8 +279,12 @@ export class MinnowDatabaseClient {
|
|
|
279
279
|
async explain(sql) {
|
|
280
280
|
return (await this.#call("explain", [sql]));
|
|
281
281
|
}
|
|
282
|
-
async execute(sql, params) {
|
|
283
|
-
|
|
282
|
+
async execute(sql, params, options = {}) {
|
|
283
|
+
const { signal, onStats, ...wireOptions } = options;
|
|
284
|
+
return (await this.#call("execute", [sql, params, wireOptions, onStats !== undefined], {
|
|
285
|
+
signal,
|
|
286
|
+
onStats,
|
|
287
|
+
}));
|
|
284
288
|
}
|
|
285
289
|
/** Executes a compiled statement from the typed mutation builders in the worker. */
|
|
286
290
|
async runStatement(statement, options) {
|
|
@@ -270,6 +270,13 @@ export interface QueryOptions {
|
|
|
270
270
|
/** Maximum rows encoded in each merged spill page. */
|
|
271
271
|
readonly spillPageRows?: number;
|
|
272
272
|
}
|
|
273
|
+
/**
|
|
274
|
+
* Engine controls honored by `execute()`. A SELECT runs through the query pipeline with all of
|
|
275
|
+
* them; every other statement checks `signal` before it starts running, so an already-aborted
|
|
276
|
+
* execute never mutates anything. Mutations are not stopped mid-statement — a write either
|
|
277
|
+
* publishes completely or fails — and only SELECT executions report stats.
|
|
278
|
+
*/
|
|
279
|
+
export type ExecuteOptions = Pick<QueryOptions, "signal" | "onStats" | "memoize" | "executionMemoryBudgetBytes">;
|
|
273
280
|
export interface QueryCursorOptions extends QueryOptions {
|
|
274
281
|
/** Maximum rows in one yielded result batch. Defaults to the vector scan batch size. */
|
|
275
282
|
readonly batchRows?: number;
|
|
@@ -823,8 +830,11 @@ export declare class MinnowDatabase {
|
|
|
823
830
|
* read the matching keys at one snapshot and then apply the keyed mutation. The read and the
|
|
824
831
|
* mutation are two steps, not one serializable transaction: a key changed by a competing writer
|
|
825
832
|
* in between fails the statement explicitly rather than silently mutating other rows.
|
|
833
|
+
*
|
|
834
|
+
* `options` carries the engine controls a query takes: a SELECT honors all of them, and every
|
|
835
|
+
* other statement checks `signal` once before running (see `ExecuteOptions`).
|
|
826
836
|
*/
|
|
827
|
-
execute(sql: string, params?: readonly QueryValue[]): Promise<ExecuteResult>;
|
|
837
|
+
execute(sql: string, params?: readonly QueryValue[], options?: ExecuteOptions): Promise<ExecuteResult>;
|
|
828
838
|
/**
|
|
829
839
|
* Executes an already-compiled statement — the typed mutation builders call this directly with
|
|
830
840
|
* the same statement structures SQL parses into, sharing every validation and conflict rule.
|
package/dist/engine/database.js
CHANGED
|
@@ -6140,8 +6140,12 @@ export class MinnowDatabase {
|
|
|
6140
6140
|
* read the matching keys at one snapshot and then apply the keyed mutation. The read and the
|
|
6141
6141
|
* mutation are two steps, not one serializable transaction: a key changed by a competing writer
|
|
6142
6142
|
* in between fails the statement explicitly rather than silently mutating other rows.
|
|
6143
|
+
*
|
|
6144
|
+
* `options` carries the engine controls a query takes: a SELECT honors all of them, and every
|
|
6145
|
+
* other statement checks `signal` once before running (see `ExecuteOptions`).
|
|
6143
6146
|
*/
|
|
6144
|
-
async execute(sql, params) {
|
|
6147
|
+
async execute(sql, params, options = {}) {
|
|
6148
|
+
throwIfAborted(options.signal);
|
|
6145
6149
|
await this.#settleExpiredStatementTransaction();
|
|
6146
6150
|
const statement = this.#compileStatementCached(sql);
|
|
6147
6151
|
if (statement.kind === "transaction") {
|
|
@@ -6150,7 +6154,10 @@ export class MinnowDatabase {
|
|
|
6150
6154
|
if (statement.kind === "select") {
|
|
6151
6155
|
return {
|
|
6152
6156
|
kind: "rows",
|
|
6153
|
-
result: await this.query(statement.sql,
|
|
6157
|
+
result: await this.query(statement.sql, {
|
|
6158
|
+
...options,
|
|
6159
|
+
...(params === undefined ? {} : { params }),
|
|
6160
|
+
}),
|
|
6154
6161
|
};
|
|
6155
6162
|
}
|
|
6156
6163
|
const open = this.#openTransaction;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Catalog } from "./catalog.js";
|
|
2
|
-
import type { ExecuteResult, QueryCursorOptions, QueryOptions } from "./database.js";
|
|
2
|
+
import type { ExecuteOptions, ExecuteResult, QueryCursorOptions, QueryOptions } from "./database.js";
|
|
3
3
|
import type { QueryResult, QueryValue } from "./query.js";
|
|
4
4
|
/**
|
|
5
5
|
* The stable SQL boundary used by clients and third-party adapters.
|
|
@@ -7,11 +7,16 @@ import type { QueryResult, QueryValue } from "./query.js";
|
|
|
7
7
|
* It is structural: both `MinnowDatabase` and `MinnowDatabaseClient` implement it without a
|
|
8
8
|
* wrapper. Adapters should emit PostgreSQL-style SQL and keep engine-specific APIs outside
|
|
9
9
|
* this small contract.
|
|
10
|
+
*
|
|
11
|
+
* `execute` takes the same engine controls a `query` does — `signal`, `onStats`, `memoize`,
|
|
12
|
+
* `executionMemoryBudgetBytes` — as a trailing optional argument, so an adapter can cancel a
|
|
13
|
+
* buffered statement or observe its cost without reaching around the boundary. A driver written
|
|
14
|
+
* against the two-argument form remains a valid implementation; it simply ignores the controls.
|
|
10
15
|
*/
|
|
11
16
|
export interface MinnowSqlExecutor {
|
|
12
17
|
query(sql: string, options?: QueryOptions): Promise<QueryResult>;
|
|
13
18
|
queryCursor(sql: string, options?: QueryCursorOptions): AsyncIterableIterator<QueryResult>;
|
|
14
|
-
execute(sql: string, params?: readonly QueryValue[]): Promise<ExecuteResult>;
|
|
19
|
+
execute(sql: string, params?: readonly QueryValue[], options?: ExecuteOptions): Promise<ExecuteResult>;
|
|
15
20
|
}
|
|
16
21
|
/** SQL execution plus the catalog surface schema-aware adapters need. */
|
|
17
22
|
export interface MinnowSqlDriver extends MinnowSqlExecutor {
|
|
@@ -38,7 +38,6 @@ const directRootMethods = [
|
|
|
38
38
|
"delete",
|
|
39
39
|
"runStatement",
|
|
40
40
|
"explain",
|
|
41
|
-
"execute",
|
|
42
41
|
"listVisibleSegmentPage",
|
|
43
42
|
"cleanupQuerySpill",
|
|
44
43
|
"compactTable",
|
|
@@ -223,7 +222,9 @@ class DatabaseRpcServer {
|
|
|
223
222
|
}
|
|
224
223
|
if (!bypassLimit)
|
|
225
224
|
this.#inFlightRpcCount += 1;
|
|
226
|
-
const abort = request.method === "query"
|
|
225
|
+
const abort = request.method === "query" || request.method === "execute"
|
|
226
|
+
? new AbortController()
|
|
227
|
+
: undefined;
|
|
227
228
|
if (abort !== undefined)
|
|
228
229
|
this.#requestAborts.set(request.requestId, abort);
|
|
229
230
|
const context = {
|
|
@@ -295,6 +296,20 @@ class DatabaseRpcServer {
|
|
|
295
296
|
: {}),
|
|
296
297
|
})));
|
|
297
298
|
}
|
|
299
|
+
case "execute": {
|
|
300
|
+
const [sql, params, options, reportStats = false] = args;
|
|
301
|
+
return this.database.execute(sql, params, {
|
|
302
|
+
...options,
|
|
303
|
+
signal: context.signal,
|
|
304
|
+
...(reportStats
|
|
305
|
+
? {
|
|
306
|
+
onStats: (stats) => {
|
|
307
|
+
this.scope.postMessage(rpcEvent(context.requestId, "stats", stats));
|
|
308
|
+
},
|
|
309
|
+
}
|
|
310
|
+
: {}),
|
|
311
|
+
});
|
|
312
|
+
}
|
|
298
313
|
case "queryCursorOpen": {
|
|
299
314
|
const handleId = this.#claimHandleId(args[0]);
|
|
300
315
|
const [sql, options, reportStats = false] = args.slice(1);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@minnowdb/core",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.3",
|
|
4
4
|
"description": "A columnar SQL database for the browser: PostgreSQL-style SQL over durable IndexedDB or OPFS data, with no server or WebAssembly module.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Eric Wilhite",
|