@sqlrooms/motherduck 0.21.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.
package/LICENSE.md ADDED
@@ -0,0 +1,9 @@
1
+ MIT License
2
+
3
+ Copyright 2025 Ilya Boyandin
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,8 @@
1
+ [MotherDuck](https://motherduck.com/) is a managed DuckDB-in-the-cloud service that enables you to run DuckDB queries both in your browser and in the cloud.
2
+
3
+ This package exposes a `createWasmMotherDuckDbConnector` function, which allows SQLRooms to connect to MotherDuck.
4
+ The connector is implemented using the [`@motherduck/wasm-client`](https://motherduck.com/docs/sql-reference/wasm-client/) library which is a customized version of [`@duckdb/duckdb-wasm`](https://github.com/duckdb/duckdb-wasm/tree/main/packages/duckdb-wasm) capable of querying MotherDuck datasets in the cloud from the browser.
5
+
6
+ ## Example
7
+
8
+ See [`MotherDuck Cloud Query Editor`](/examples#motherduck-cloud-query-editor) for a usage example.
@@ -0,0 +1,16 @@
1
+ import { MDConnection, MDConnectionParams } from '@motherduck/wasm-client';
2
+ import { DuckDbConnector } from '@sqlrooms/duckdb';
3
+ export type MotherDuckDbConnectorType = 'wasm-motherduck';
4
+ export type MotherDuckDbConnectorOptions = {
5
+ type: MotherDuckDbConnectorType;
6
+ } & WasmMotherDuckDbConnectorOptions;
7
+ export declare function isWasmMotherDuckDbConnector(connector: DuckDbConnector): connector is WasmMotherDuckDbConnector;
8
+ export interface WasmMotherDuckDbConnectorOptions extends MDConnectionParams {
9
+ initializationQuery?: string;
10
+ }
11
+ export interface WasmMotherDuckDbConnector extends DuckDbConnector {
12
+ getConnection(): MDConnection;
13
+ readonly type: 'wasm-motherduck';
14
+ }
15
+ export declare function createWasmMotherDuckDbConnector(options: WasmMotherDuckDbConnectorOptions): WasmMotherDuckDbConnector;
16
+ //# sourceMappingURL=WasmMotherDuckDbConnector.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"WasmMotherDuckDbConnector.d.ts","sourceRoot":"","sources":["../src/WasmMotherDuckDbConnector.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAE,kBAAkB,EAAC,MAAM,yBAAyB,CAAC;AACzE,OAAO,EAGL,eAAe,EAChB,MAAM,kBAAkB,CAAC;AAI1B,MAAM,MAAM,yBAAyB,GAAG,iBAAiB,CAAC;AAE1D,MAAM,MAAM,4BAA4B,GAAG;IACzC,IAAI,EAAE,yBAAyB,CAAC;CACjC,GAAG,gCAAgC,CAAC;AAErC,wBAAgB,2BAA2B,CACzC,SAAS,EAAE,eAAe,GACzB,SAAS,IAAI,yBAAyB,CAExC;AAED,MAAM,WAAW,gCAAiC,SAAQ,kBAAkB;IAC1E,mBAAmB,CAAC,EAAE,MAAM,CAAC;CAC9B;AAED,MAAM,WAAW,yBAA0B,SAAQ,eAAe;IAChE,aAAa,IAAI,YAAY,CAAC;IAC9B,QAAQ,CAAC,IAAI,EAAE,iBAAiB,CAAC;CAClC;AAED,wBAAgB,+BAA+B,CAC7C,OAAO,EAAE,gCAAgC,GACxC,yBAAyB,CAsE3B"}
@@ -0,0 +1,64 @@
1
+ import { MDConnection } from '@motherduck/wasm-client';
2
+ import { createBaseDuckDbConnector, } from '@sqlrooms/duckdb';
3
+ import * as arrow from 'apache-arrow';
4
+ export function isWasmMotherDuckDbConnector(connector) {
5
+ return connector.type === 'wasm-motherduck';
6
+ }
7
+ export function createWasmMotherDuckDbConnector(options) {
8
+ const { initializationQuery = '', ...params } = options;
9
+ let connection = null;
10
+ const impl = {
11
+ async initializeInternal() {
12
+ connection = MDConnection.create(params);
13
+ await connection.isInitialized();
14
+ if (initializationQuery) {
15
+ await connection.evaluateQuery(initializationQuery);
16
+ }
17
+ },
18
+ async destroyInternal() {
19
+ if (connection) {
20
+ await connection.close();
21
+ connection = null;
22
+ }
23
+ },
24
+ async executeQueryInternal(query, signal, id) {
25
+ if (!connection) {
26
+ throw new Error('MotherDuck connection not initialized');
27
+ }
28
+ // Check if already cancelled before starting
29
+ if (signal.aborted) {
30
+ throw new DOMException('Query was cancelled', 'AbortError');
31
+ }
32
+ // Not using evaluateQueuedQuery which supports cancellation
33
+ // because it doesn't provide arrow results
34
+ const result = await connection.evaluateStreamingQuery(query);
35
+ const batches = new Array();
36
+ for await (const batch of result.arrowStream) {
37
+ // Check for cancellation before processing each batch
38
+ if (signal.aborted) {
39
+ throw new DOMException('Query was cancelled', 'AbortError');
40
+ }
41
+ batches.push(batch);
42
+ }
43
+ return new arrow.Table(batches);
44
+ },
45
+ async cancelQueryInternal(queryId) {
46
+ // Cancellation is handled by checking AbortSignal in the stream reading loop
47
+ // No server-side cancellation is performed since evaluateStreamingQuery doesn't provide queryId
48
+ },
49
+ };
50
+ const base = createBaseDuckDbConnector({ initializationQuery }, impl);
51
+ return {
52
+ ...base,
53
+ getConnection() {
54
+ if (!connection) {
55
+ throw new Error('MotherDuck connection not initialized');
56
+ }
57
+ return connection;
58
+ },
59
+ get type() {
60
+ return 'wasm-motherduck';
61
+ },
62
+ };
63
+ }
64
+ //# sourceMappingURL=WasmMotherDuckDbConnector.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"WasmMotherDuckDbConnector.js","sourceRoot":"","sources":["../src/WasmMotherDuckDbConnector.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAqB,MAAM,yBAAyB,CAAC;AACzE,OAAO,EAEL,yBAAyB,GAE1B,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AAStC,MAAM,UAAU,2BAA2B,CACzC,SAA0B;IAE1B,OAAQ,SAAiB,CAAC,IAAI,KAAK,iBAAiB,CAAC;AACvD,CAAC;AAWD,MAAM,UAAU,+BAA+B,CAC7C,OAAyC;IAEzC,MAAM,EAAC,mBAAmB,GAAG,EAAE,EAAE,GAAG,MAAM,EAAC,GAAG,OAAO,CAAC;IACtD,IAAI,UAAU,GAAwB,IAAI,CAAC;IAE3C,MAAM,IAAI,GAA4B;QACpC,KAAK,CAAC,kBAAkB;YACtB,UAAU,GAAG,YAAY,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;YACzC,MAAM,UAAU,CAAC,aAAa,EAAE,CAAC;YACjC,IAAI,mBAAmB,EAAE,CAAC;gBACxB,MAAM,UAAU,CAAC,aAAa,CAAC,mBAAmB,CAAC,CAAC;YACtD,CAAC;QACH,CAAC;QAED,KAAK,CAAC,eAAe;YACnB,IAAI,UAAU,EAAE,CAAC;gBACf,MAAM,UAAU,CAAC,KAAK,EAAE,CAAC;gBACzB,UAAU,GAAG,IAAI,CAAC;YACpB,CAAC;QACH,CAAC;QAED,KAAK,CAAC,oBAAoB,CACxB,KAAa,EACb,MAAmB,EACnB,EAAU;YAEV,IAAI,CAAC,UAAU,EAAE,CAAC;gBAChB,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAC;YAC3D,CAAC;YAED,6CAA6C;YAC7C,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;gBACnB,MAAM,IAAI,YAAY,CAAC,qBAAqB,EAAE,YAAY,CAAC,CAAC;YAC9D,CAAC;YAED,4DAA4D;YAC5D,2CAA2C;YAC3C,MAAM,MAAM,GAAG,MAAM,UAAU,CAAC,sBAAsB,CAAC,KAAK,CAAC,CAAC;YAC9D,MAAM,OAAO,GAAG,IAAI,KAAK,EAAoB,CAAC;YAE9C,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,MAAM,CAAC,WAAW,EAAE,CAAC;gBAC7C,sDAAsD;gBACtD,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;oBACnB,MAAM,IAAI,YAAY,CAAC,qBAAqB,EAAE,YAAY,CAAC,CAAC;gBAC9D,CAAC;gBACD,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACtB,CAAC;YAED,OAAO,IAAI,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QAClC,CAAC;QAED,KAAK,CAAC,mBAAmB,CAAC,OAAe;YACvC,6EAA6E;YAC7E,gGAAgG;QAClG,CAAC;KACF,CAAC;IAEF,MAAM,IAAI,GAAG,yBAAyB,CAAC,EAAC,mBAAmB,EAAC,EAAE,IAAI,CAAC,CAAC;IAEpE,OAAO;QACL,GAAG,IAAI;QACP,aAAa;YACX,IAAI,CAAC,UAAU,EAAE,CAAC;gBAChB,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAC;YAC3D,CAAC;YACD,OAAO,UAAU,CAAC;QACpB,CAAC;QACD,IAAI,IAAI;YACN,OAAO,iBAA0B,CAAC;QACpC,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import {MDConnection, MDConnectionParams} from '@motherduck/wasm-client';\nimport {\n BaseDuckDbConnectorImpl,\n createBaseDuckDbConnector,\n DuckDbConnector,\n} from '@sqlrooms/duckdb';\nimport * as arrow from 'apache-arrow';\nimport {RecordBatch} from 'apache-arrow';\n\nexport type MotherDuckDbConnectorType = 'wasm-motherduck';\n\nexport type MotherDuckDbConnectorOptions = {\n type: MotherDuckDbConnectorType;\n} & WasmMotherDuckDbConnectorOptions;\n\nexport function isWasmMotherDuckDbConnector(\n connector: DuckDbConnector,\n): connector is WasmMotherDuckDbConnector {\n return (connector as any).type === 'wasm-motherduck';\n}\n\nexport interface WasmMotherDuckDbConnectorOptions extends MDConnectionParams {\n initializationQuery?: string;\n}\n\nexport interface WasmMotherDuckDbConnector extends DuckDbConnector {\n getConnection(): MDConnection;\n readonly type: 'wasm-motherduck';\n}\n\nexport function createWasmMotherDuckDbConnector(\n options: WasmMotherDuckDbConnectorOptions,\n): WasmMotherDuckDbConnector {\n const {initializationQuery = '', ...params} = options;\n let connection: MDConnection | null = null;\n\n const impl: BaseDuckDbConnectorImpl = {\n async initializeInternal() {\n connection = MDConnection.create(params);\n await connection.isInitialized();\n if (initializationQuery) {\n await connection.evaluateQuery(initializationQuery);\n }\n },\n\n async destroyInternal() {\n if (connection) {\n await connection.close();\n connection = null;\n }\n },\n\n async executeQueryInternal(\n query: string,\n signal: AbortSignal,\n id: string,\n ): Promise<arrow.Table> {\n if (!connection) {\n throw new Error('MotherDuck connection not initialized');\n }\n\n // Check if already cancelled before starting\n if (signal.aborted) {\n throw new DOMException('Query was cancelled', 'AbortError');\n }\n\n // Not using evaluateQueuedQuery which supports cancellation\n // because it doesn't provide arrow results\n const result = await connection.evaluateStreamingQuery(query);\n const batches = new Array<RecordBatch<any>>();\n\n for await (const batch of result.arrowStream) {\n // Check for cancellation before processing each batch\n if (signal.aborted) {\n throw new DOMException('Query was cancelled', 'AbortError');\n }\n batches.push(batch);\n }\n\n return new arrow.Table(batches);\n },\n\n async cancelQueryInternal(queryId: string) {\n // Cancellation is handled by checking AbortSignal in the stream reading loop\n // No server-side cancellation is performed since evaluateStreamingQuery doesn't provide queryId\n },\n };\n\n const base = createBaseDuckDbConnector({initializationQuery}, impl);\n\n return {\n ...base,\n getConnection() {\n if (!connection) {\n throw new Error('MotherDuck connection not initialized');\n }\n return connection;\n },\n get type() {\n return 'wasm-motherduck' as const;\n },\n };\n}\n"]}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * {@include ../README.md}
3
+ * @packageDocumentation
4
+ */
5
+ export { createWasmMotherDuckDbConnector, isWasmMotherDuckDbConnector, type WasmMotherDuckDbConnector, type WasmMotherDuckDbConnectorOptions, } from './WasmMotherDuckDbConnector';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACL,+BAA+B,EAC/B,2BAA2B,EAC3B,KAAK,yBAAyB,EAC9B,KAAK,gCAAgC,GACtC,MAAM,6BAA6B,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,6 @@
1
+ /**
2
+ * {@include ../README.md}
3
+ * @packageDocumentation
4
+ */
5
+ export { createWasmMotherDuckDbConnector, isWasmMotherDuckDbConnector, } from './WasmMotherDuckDbConnector';
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACL,+BAA+B,EAC/B,2BAA2B,GAG5B,MAAM,6BAA6B,CAAC","sourcesContent":["/**\n * {@include ../README.md}\n * @packageDocumentation\n */\n\nexport {\n createWasmMotherDuckDbConnector,\n isWasmMotherDuckDbConnector,\n type WasmMotherDuckDbConnector,\n type WasmMotherDuckDbConnectorOptions,\n} from './WasmMotherDuckDbConnector';\n"]}
package/package.json ADDED
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "@sqlrooms/motherduck",
3
+ "version": "0.21.0",
4
+ "main": "dist/index.js",
5
+ "types": "dist/index.d.ts",
6
+ "module": "dist/index.js",
7
+ "type": "module",
8
+ "author": "Ilya Boyandin <ilya@boyandin.me>",
9
+ "license": "MIT",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/sqlrooms/sqlrooms.git"
13
+ },
14
+ "files": [
15
+ "dist"
16
+ ],
17
+ "publishConfig": {
18
+ "access": "public"
19
+ },
20
+ "dependencies": {
21
+ "@motherduck/wasm-client": "^0.6.6",
22
+ "@sqlrooms/duckdb": "0.21.0",
23
+ "apache-arrow": "^17.0.0"
24
+ },
25
+ "scripts": {
26
+ "dev": "tsc -w",
27
+ "build": "tsc",
28
+ "lint": "eslint .",
29
+ "typecheck": "tsc --noEmit",
30
+ "typedoc": "typedoc"
31
+ },
32
+ "gitHead": "8411bc915049f20dbcd48a60493907ddda8b7b38"
33
+ }