@malloydata/db-duckdb 0.0.120-dev240131220408 → 0.0.120

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.
@@ -1,17 +1,16 @@
1
- import { MalloyQueryData, PersistSQLResults, PooledConnection, QueryDataRow, QueryRunStats, RunSQLOptions, SQLBlock, StreamingConnection, StructDef, TestableConnection, FetchSchemaOptions } from '@malloydata/malloy';
1
+ import { FetchSchemaOptions, MalloyQueryData, PersistSQLResults, PooledConnection, QueryDataRow, QueryOptionsReader, QueryRunStats, RunSQLOptions, SQLBlock, StreamingConnection, StructDef, TestableConnection } from '@malloydata/malloy';
2
2
  export interface DuckDBQueryOptions {
3
3
  rowLimit: number;
4
4
  }
5
- export type QueryOptionsReader = Partial<DuckDBQueryOptions> | (() => Partial<DuckDBQueryOptions>);
6
5
  export declare abstract class DuckDBCommon implements TestableConnection, PersistSQLResults, StreamingConnection {
7
- private queryOptions?;
6
+ protected queryOptions?: QueryOptionsReader | undefined;
8
7
  private readonly dialect;
9
8
  static DEFAULT_QUERY_OPTIONS: DuckDBQueryOptions;
10
9
  private schemaCache;
11
10
  private sqlSchemaCache;
12
11
  readonly name: string;
13
12
  get dialectName(): string;
14
- private readQueryOptions;
13
+ protected readQueryOptions(): DuckDBQueryOptions;
15
14
  constructor(queryOptions?: QueryOptionsReader | undefined);
16
15
  isPool(): this is PooledConnection;
17
16
  canPersist(): this is PersistSQLResults;
@@ -25,7 +24,7 @@ export declare abstract class DuckDBCommon implements TestableConnection, Persis
25
24
  totalRows: number;
26
25
  }>;
27
26
  runSQL(sql: string, options?: RunSQLOptions): Promise<MalloyQueryData>;
28
- abstract runSQLStream(sql: string, _options: RunSQLOptions): AsyncIterableIterator<QueryDataRow>;
27
+ abstract runSQLStream(sql: string, options: RunSQLOptions): AsyncIterableIterator<QueryDataRow>;
29
28
  private getSQLBlockSchema;
30
29
  estimateQueryCost(_: string): Promise<QueryRunStats>;
31
30
  /**
@@ -1,6 +1,11 @@
1
- import { DuckDBCommon, QueryOptionsReader } from './duckdb_common';
1
+ import { DuckDBCommon } from './duckdb_common';
2
2
  import { Connection, Database, TableData } from 'duckdb';
3
- import { QueryDataRow, RunSQLOptions } from '@malloydata/malloy';
3
+ import { ConnectionConfig, QueryDataRow, QueryOptionsReader, RunSQLOptions } from '@malloydata/malloy';
4
+ export interface DuckDBConnectionOptions extends ConnectionConfig {
5
+ databasePath?: string;
6
+ workingDirectory?: string;
7
+ readOnly?: boolean;
8
+ }
4
9
  interface ActiveDB {
5
10
  database: Database;
6
11
  connections: Connection[];
@@ -9,10 +14,12 @@ export declare class DuckDBConnection extends DuckDBCommon {
9
14
  readonly name: string;
10
15
  private databasePath;
11
16
  private workingDirectory;
17
+ private readOnly;
12
18
  connecting: Promise<void>;
13
19
  protected connection: Connection | null;
14
20
  protected isSetup: Promise<void> | undefined;
15
21
  static activeDBs: Record<string, ActiveDB>;
22
+ constructor(options: DuckDBConnectionOptions, queryOptions?: QueryOptionsReader);
16
23
  constructor(name: string, databasePath?: string, workingDirectory?: string, queryOptions?: QueryOptionsReader);
17
24
  private init;
18
25
  loadExtension(ext: string): Promise<void>;
@@ -30,12 +30,42 @@ const crypto_1 = __importDefault(require("crypto"));
30
30
  const duckdb_common_1 = require("./duckdb_common");
31
31
  const duckdb_1 = require("duckdb");
32
32
  class DuckDBConnection extends duckdb_common_1.DuckDBCommon {
33
- constructor(name, databasePath = ':memory:', workingDirectory = '.', queryOptions) {
34
- super(queryOptions);
35
- this.name = name;
36
- this.databasePath = databasePath;
37
- this.workingDirectory = workingDirectory;
33
+ constructor(arg, arg2, workingDirectory, queryOptions) {
34
+ super();
35
+ this.databasePath = ':memory:';
36
+ this.workingDirectory = '.';
37
+ this.readOnly = false;
38
38
  this.connection = null;
39
+ if (typeof arg === 'string') {
40
+ this.name = arg;
41
+ if (typeof arg2 === 'string') {
42
+ this.databasePath = arg2;
43
+ }
44
+ if (typeof workingDirectory === 'string') {
45
+ this.workingDirectory = workingDirectory;
46
+ }
47
+ if (queryOptions) {
48
+ this.queryOptions = queryOptions;
49
+ }
50
+ }
51
+ else {
52
+ this.name = arg.name;
53
+ if (arg2) {
54
+ this.queryOptions = arg2;
55
+ }
56
+ if (typeof arg.readOnly === 'boolean') {
57
+ this.readOnly = arg.readOnly;
58
+ }
59
+ if (typeof arg.databasePath === 'string') {
60
+ this.databasePath = arg.databasePath;
61
+ }
62
+ if (typeof arg.workingDirectory === 'string') {
63
+ this.workingDirectory = arg.workingDirectory;
64
+ }
65
+ }
66
+ if (this.databasePath === ':memory:') {
67
+ this.readOnly = false;
68
+ }
39
69
  this.connecting = this.init();
40
70
  }
41
71
  async init() {
@@ -45,9 +75,7 @@ class DuckDBConnection extends duckdb_common_1.DuckDBCommon {
45
75
  activeDB = DuckDBConnection.activeDBs[this.databasePath];
46
76
  }
47
77
  else {
48
- const database = new duckdb_1.Database(this.databasePath, duckdb_1.OPEN_READWRITE, // databasePath === ":memory:" ? OPEN_READWRITE : OPEN_READONLY,
49
- // databasePath === ":memory:" ? OPEN_READWRITE : OPEN_READONLY,
50
- err => {
78
+ const database = new duckdb_1.Database(this.databasePath, this.readOnly ? duckdb_1.OPEN_READONLY : duckdb_1.OPEN_READWRITE, err => {
51
79
  if (err) {
52
80
  reject(err);
53
81
  }
@@ -125,6 +153,8 @@ class DuckDBConnection extends duckdb_common_1.DuckDBCommon {
125
153
  });
126
154
  }
127
155
  async *runSQLStream(sql, { rowLimit, abortSignal } = {}) {
156
+ const defaultOptions = this.readQueryOptions();
157
+ rowLimit !== null && rowLimit !== void 0 ? rowLimit : (rowLimit = defaultOptions.rowLimit);
128
158
  await this.setup();
129
159
  if (!this.connection) {
130
160
  throw new Error('Connection not open');
@@ -1,8 +1,13 @@
1
1
  import * as duckdb from '@malloydata/duckdb-wasm';
2
- import { FetchSchemaOptions, QueryDataRow, RunSQLOptions, StructDef, SQLBlock } from '@malloydata/malloy';
3
- import { DuckDBCommon, QueryOptionsReader } from './duckdb_common';
2
+ import { FetchSchemaOptions, QueryDataRow, QueryOptionsReader, RunSQLOptions, StructDef, SQLBlock, ConnectionConfig } from '@malloydata/malloy';
3
+ import { DuckDBCommon } from './duckdb_common';
4
4
  type RemoteFileCallback = (tableName: string) => Promise<Uint8Array | undefined>;
5
+ export interface DuckDBWasmOptions extends ConnectionConfig {
6
+ databasePath?: string;
7
+ workingDirectory?: string;
8
+ }
5
9
  export declare abstract class DuckDBWASMConnection extends DuckDBCommon {
10
+ readonly arg: string | DuckDBWasmOptions;
6
11
  readonly name: string;
7
12
  private databasePath;
8
13
  protected workingDirectory: string;
@@ -13,6 +18,7 @@ export declare abstract class DuckDBWASMConnection extends DuckDBCommon {
13
18
  private worker;
14
19
  private remoteFileCallbacks;
15
20
  private remoteFileStatus;
21
+ constructor(options: DuckDBWasmOptions, queryOptions?: QueryOptionsReader);
16
22
  constructor(name: string, databasePath?: string | null, workingDirectory?: string, queryOptions?: QueryOptionsReader);
17
23
  private init;
18
24
  abstract getBundles(): duckdb.DuckDBBundles;
@@ -121,16 +121,40 @@ const unwrapTable = (table) => {
121
121
  };
122
122
  const isNode = () => typeof navigator === 'undefined';
123
123
  class DuckDBWASMConnection extends duckdb_common_1.DuckDBCommon {
124
- constructor(name, databasePath = null, workingDirectory = '/', queryOptions) {
125
- super(queryOptions);
126
- this.name = name;
127
- this.databasePath = databasePath;
128
- this.workingDirectory = workingDirectory;
124
+ constructor(arg, arg2, workingDirectory, queryOptions) {
125
+ super();
126
+ this.arg = arg;
127
+ this.databasePath = null;
128
+ this.workingDirectory = '/';
129
129
  this._connection = null;
130
130
  this._database = null;
131
131
  this.worker = null;
132
132
  this.remoteFileCallbacks = [];
133
133
  this.remoteFileStatus = {};
134
+ if (typeof arg === 'string') {
135
+ this.name = arg;
136
+ if (typeof arg2 === 'string') {
137
+ this.databasePath = arg2;
138
+ }
139
+ if (typeof workingDirectory === 'string') {
140
+ this.workingDirectory = workingDirectory;
141
+ }
142
+ if (queryOptions) {
143
+ this.queryOptions = queryOptions;
144
+ }
145
+ }
146
+ else {
147
+ this.name = arg.name;
148
+ if (arg2) {
149
+ this.queryOptions = arg2;
150
+ }
151
+ if (typeof arg.databasePath === 'string') {
152
+ this.databasePath = arg.databasePath;
153
+ }
154
+ if (typeof arg.workingDirectory === 'string') {
155
+ this.workingDirectory = arg.workingDirectory;
156
+ }
157
+ }
134
158
  this.connecting = this.init();
135
159
  }
136
160
  async init() {
@@ -230,6 +254,8 @@ class DuckDBWASMConnection extends duckdb_common_1.DuckDBCommon {
230
254
  if (!this.connection) {
231
255
  throw new Error('duckdb-wasm not connected');
232
256
  }
257
+ const defaultOptions = this.readQueryOptions();
258
+ rowLimit !== null && rowLimit !== void 0 ? rowLimit : (rowLimit = defaultOptions.rowLimit);
233
259
  await this.setup();
234
260
  const statements = sql.split('-- hack: split on this');
235
261
  let done = false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@malloydata/db-duckdb",
3
- "version": "0.0.120-dev240131220408",
3
+ "version": "0.0.120",
4
4
  "license": "MIT",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -41,7 +41,7 @@
41
41
  },
42
42
  "dependencies": {
43
43
  "@malloydata/duckdb-wasm": "0.0.6",
44
- "@malloydata/malloy": "^0.0.120-dev240131220408",
44
+ "@malloydata/malloy": "^0.0.120",
45
45
  "apache-arrow": "^13.0.0",
46
46
  "duckdb": "0.9.2",
47
47
  "web-worker": "^1.2.0"