@malloydata/db-duckdb 0.0.3 → 0.0.5
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/duckdb_common.d.ts
CHANGED
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
import { Connection, FetchSchemaAndRunSimultaneously, FetchSchemaAndRunStreamSimultaneously, MalloyQueryData, PersistSQLResults, PooledConnection, RunSQLOptions, SQLBlock, StreamingConnection, StructDef, QueryDataRow } from "@malloydata/malloy";
|
|
2
|
+
export interface DuckDBQueryOptions {
|
|
3
|
+
rowLimit: number;
|
|
4
|
+
}
|
|
5
|
+
export declare type QueryOptionsReader = Partial<DuckDBQueryOptions> | (() => Partial<DuckDBQueryOptions>);
|
|
2
6
|
export declare abstract class DuckDBCommon implements Connection, PersistSQLResults, StreamingConnection {
|
|
7
|
+
private queryOptions?;
|
|
8
|
+
static DEFAULT_QUERY_OPTIONS: DuckDBQueryOptions;
|
|
3
9
|
readonly name: string;
|
|
4
10
|
get dialectName(): string;
|
|
11
|
+
private readQueryOptions;
|
|
12
|
+
constructor(queryOptions?: QueryOptionsReader | undefined);
|
|
5
13
|
isPool(): this is PooledConnection;
|
|
6
14
|
canPersist(): this is PersistSQLResults;
|
|
7
15
|
protected abstract setup(): Promise<void>;
|
package/dist/duckdb_common.js
CHANGED
|
@@ -26,12 +26,27 @@ const duckDBToMalloyTypes = {
|
|
|
26
26
|
INTEGER: "number",
|
|
27
27
|
};
|
|
28
28
|
class DuckDBCommon {
|
|
29
|
-
constructor() {
|
|
29
|
+
constructor(queryOptions) {
|
|
30
|
+
this.queryOptions = queryOptions;
|
|
30
31
|
this.name = "duckdb_common";
|
|
31
32
|
}
|
|
32
33
|
get dialectName() {
|
|
33
34
|
return "duckdb";
|
|
34
35
|
}
|
|
36
|
+
readQueryOptions() {
|
|
37
|
+
const options = DuckDBCommon.DEFAULT_QUERY_OPTIONS;
|
|
38
|
+
if (this.queryOptions) {
|
|
39
|
+
if (this.queryOptions instanceof Function) {
|
|
40
|
+
return { ...options, ...this.queryOptions() };
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
return { ...options, ...this.queryOptions };
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
return options;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
35
50
|
isPool() {
|
|
36
51
|
return false;
|
|
37
52
|
}
|
|
@@ -44,7 +59,8 @@ class DuckDBCommon {
|
|
|
44
59
|
}
|
|
45
60
|
async runSQL(sql, options = {}) {
|
|
46
61
|
var _a;
|
|
47
|
-
const
|
|
62
|
+
const defaultOptions = this.readQueryOptions();
|
|
63
|
+
const rowLimit = (_a = options.rowLimit) !== null && _a !== void 0 ? _a : defaultOptions.rowLimit;
|
|
48
64
|
const statements = sql.split("-- hack: split on this");
|
|
49
65
|
while (statements.length > 1) {
|
|
50
66
|
await this.runRawSQL(statements[0]);
|
|
@@ -268,4 +284,7 @@ class DuckDBCommon {
|
|
|
268
284
|
}
|
|
269
285
|
}
|
|
270
286
|
exports.DuckDBCommon = DuckDBCommon;
|
|
287
|
+
DuckDBCommon.DEFAULT_QUERY_OPTIONS = {
|
|
288
|
+
rowLimit: 10,
|
|
289
|
+
};
|
|
271
290
|
//# sourceMappingURL=duckdb_common.js.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference path="../src/duckdb.d.ts" />
|
|
2
|
-
import { DuckDBCommon } from "./duckdb_common";
|
|
2
|
+
import { DuckDBCommon, QueryOptionsReader } from "./duckdb_common";
|
|
3
3
|
import { Database, Row } from "duckdb";
|
|
4
4
|
import { QueryDataRow, RunSQLOptions } from "@malloydata/malloy";
|
|
5
5
|
export declare class DuckDBConnection extends DuckDBCommon {
|
|
@@ -8,7 +8,7 @@ export declare class DuckDBConnection extends DuckDBCommon {
|
|
|
8
8
|
protected connection: import("duckdb").Connection;
|
|
9
9
|
protected database: Database;
|
|
10
10
|
protected isSetup: boolean;
|
|
11
|
-
constructor(name: string, databasePath?: string, workingDirectory?: string);
|
|
11
|
+
constructor(name: string, databasePath?: string, workingDirectory?: string, queryOptions?: QueryOptionsReader);
|
|
12
12
|
protected setup(): Promise<void>;
|
|
13
13
|
protected runDuckDBQuery(sql: string): Promise<{
|
|
14
14
|
rows: Row[];
|
|
@@ -40,8 +40,8 @@ const crypto = __importStar(require("crypto"));
|
|
|
40
40
|
const duckdb_common_1 = require("./duckdb_common");
|
|
41
41
|
const duckdb_1 = require("duckdb");
|
|
42
42
|
class DuckDBConnection extends duckdb_common_1.DuckDBCommon {
|
|
43
|
-
constructor(name, databasePath = "test/data/duckdb/duckdb_test.db", workingDirectory = "/") {
|
|
44
|
-
super();
|
|
43
|
+
constructor(name, databasePath = "test/data/duckdb/duckdb_test.db", workingDirectory = "/", queryOptions) {
|
|
44
|
+
super(queryOptions);
|
|
45
45
|
this.name = name;
|
|
46
46
|
this.workingDirectory = workingDirectory;
|
|
47
47
|
this.isSetup = false;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { QueryDataRow, RunSQLOptions } from "@malloydata/malloy";
|
|
2
2
|
import * as duckdb from "@duckdb/duckdb-wasm";
|
|
3
|
-
import { DuckDBCommon } from "./duckdb_common";
|
|
3
|
+
import { DuckDBCommon, QueryOptionsReader } from "./duckdb_common";
|
|
4
4
|
export declare class DuckDBWASMConnection extends DuckDBCommon {
|
|
5
5
|
readonly name: string;
|
|
6
6
|
private workingDirectory;
|
|
@@ -8,7 +8,7 @@ export declare class DuckDBWASMConnection extends DuckDBCommon {
|
|
|
8
8
|
protected _connection: duckdb.AsyncDuckDBConnection | null;
|
|
9
9
|
protected _database: duckdb.AsyncDuckDB | null;
|
|
10
10
|
protected isSetup: boolean;
|
|
11
|
-
constructor(name: string, databasePath?: string, workingDirectory?: string);
|
|
11
|
+
constructor(name: string, databasePath?: string, workingDirectory?: string, queryOptions?: QueryOptionsReader);
|
|
12
12
|
private init;
|
|
13
13
|
get connection(): duckdb.AsyncDuckDBConnection | null;
|
|
14
14
|
get database(): duckdb.AsyncDuckDB | null;
|
|
@@ -90,8 +90,8 @@ const unwrapTable = (table) => {
|
|
|
90
90
|
return table.toArray().map(unwrapRow);
|
|
91
91
|
};
|
|
92
92
|
class DuckDBWASMConnection extends duckdb_common_1.DuckDBCommon {
|
|
93
|
-
constructor(name, databasePath = "test/data/duckdb/duckdb_test.db", workingDirectory = "/") {
|
|
94
|
-
super();
|
|
93
|
+
constructor(name, databasePath = "test/data/duckdb/duckdb_test.db", workingDirectory = "/", queryOptions) {
|
|
94
|
+
super(queryOptions);
|
|
95
95
|
this.name = name;
|
|
96
96
|
this.workingDirectory = workingDirectory;
|
|
97
97
|
this._connection = null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@malloydata/db-duckdb",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
4
4
|
"license": "GPL-2.0",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -14,11 +14,12 @@
|
|
|
14
14
|
"lint-fix": "eslint '**/*.ts{,x}' --fix",
|
|
15
15
|
"test": "jest --config=../../jest.config.js",
|
|
16
16
|
"build": "tsc --build",
|
|
17
|
-
"malloyc": "ts-node ../../scripts/malloy-to-json"
|
|
17
|
+
"malloyc": "ts-node ../../scripts/malloy-to-json",
|
|
18
|
+
"prepublishOnly": "npm run build"
|
|
18
19
|
},
|
|
19
20
|
"dependencies": {
|
|
20
|
-
"@malloydata/malloy": "0.0.3",
|
|
21
21
|
"@duckdb/duckdb-wasm": "^1.17.0",
|
|
22
|
+
"@malloydata/malloy": "^0.0.5",
|
|
22
23
|
"duckdb": "0.5.1"
|
|
23
24
|
}
|
|
24
25
|
}
|