@visactor/vquery 0.1.33 → 0.1.35
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/db/duckDb.d.ts +13 -1
- package/dist/index.cjs +28 -5
- package/dist/index.d.ts +1 -41
- package/dist/index.js +26 -6
- package/dist/types/QueryResult.d.ts +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/vquery.d.ts +48 -0
- package/package.json +1 -1
package/dist/db/duckDb.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { QueryResult } from '../types';
|
|
1
2
|
export declare class DuckDB {
|
|
2
3
|
private db;
|
|
3
4
|
private connection;
|
|
@@ -5,7 +6,7 @@ export declare class DuckDB {
|
|
|
5
6
|
/**
|
|
6
7
|
* @description 初始化 DuckDB 实例
|
|
7
8
|
*/
|
|
8
|
-
|
|
9
|
+
init: () => Promise<void>;
|
|
9
10
|
/**
|
|
10
11
|
* @description 释放 DuckDB 实例
|
|
11
12
|
*/
|
|
@@ -25,4 +26,15 @@ export declare class DuckDB {
|
|
|
25
26
|
dataset: any[];
|
|
26
27
|
table: any;
|
|
27
28
|
}>;
|
|
29
|
+
/**
|
|
30
|
+
* 确保一个文件存在,如果不存在,则根据同名文件创建临时表
|
|
31
|
+
* @param fileName 文件名
|
|
32
|
+
*/
|
|
33
|
+
private ensureSchema;
|
|
34
|
+
/**
|
|
35
|
+
* @description 获取文件的 Schema
|
|
36
|
+
* @param fileName 文件名
|
|
37
|
+
* @returns 文件的 Schema
|
|
38
|
+
*/
|
|
39
|
+
getSchema: (fileName: string) => Promise<QueryResult>;
|
|
28
40
|
}
|
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
const __rslib_import_meta_url__ = /*#__PURE__*/ function() {
|
|
3
|
+
return 'undefined' == typeof document ? new (require('url'.replace('', ''))).URL('file:' + __filename).href : document.currentScript && document.currentScript.src || new URL('main.js', document.baseURI).href;
|
|
4
|
+
}();
|
|
2
5
|
var __webpack_require__ = {};
|
|
3
6
|
(()=>{
|
|
4
7
|
__webpack_require__.d = (exports1, definition)=>{
|
|
@@ -31,9 +34,18 @@ class DuckDB {
|
|
|
31
34
|
db = null;
|
|
32
35
|
connection = null;
|
|
33
36
|
constructor(){}
|
|
34
|
-
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
+
init = async ()=>{
|
|
38
|
+
const MANUAL_BUNDLES = {
|
|
39
|
+
mvp: {
|
|
40
|
+
mainModule: new URL('@duckdb/duckdb-wasm/dist/duckdb-mvp.wasm', __rslib_import_meta_url__).href,
|
|
41
|
+
mainWorker: new URL('@duckdb/duckdb-wasm/dist/duckdb-browser-mvp.worker.js', __rslib_import_meta_url__).toString()
|
|
42
|
+
},
|
|
43
|
+
eh: {
|
|
44
|
+
mainModule: new URL('@duckdb/duckdb-wasm/dist/duckdb-eh.wasm', __rslib_import_meta_url__).href,
|
|
45
|
+
mainWorker: new URL('@duckdb/duckdb-wasm/dist/duckdb-browser-eh.worker.js', __rslib_import_meta_url__).toString()
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
const bundle = await (0, duckdb_wasm_namespaceObject.selectBundle)(MANUAL_BUNDLES);
|
|
37
49
|
const worker_url = URL.createObjectURL(new Blob([
|
|
38
50
|
`importScripts("${bundle.mainWorker}");`
|
|
39
51
|
], {
|
|
@@ -80,6 +92,16 @@ class DuckDB {
|
|
|
80
92
|
table
|
|
81
93
|
};
|
|
82
94
|
};
|
|
95
|
+
ensureSchema = async (fileName)=>{
|
|
96
|
+
if (!this.connection) throw new Error('connection is null');
|
|
97
|
+
await this.connection.query(`CREATE TEMP TABLE IF NOT EXISTS "${fileName}" AS SELECT * FROM read_csv_auto('${fileName}')`);
|
|
98
|
+
};
|
|
99
|
+
getSchema = async (fileName)=>{
|
|
100
|
+
if (!this.connection) throw new Error('connection is null');
|
|
101
|
+
await this.ensureSchema(fileName);
|
|
102
|
+
const result = await this.connection.query(`PRAGMA table_info('${fileName}')`);
|
|
103
|
+
return result.toArray().map((row)=>row.toJSON());
|
|
104
|
+
};
|
|
83
105
|
}
|
|
84
106
|
class IndexedDB {
|
|
85
107
|
db = null;
|
|
@@ -165,8 +187,8 @@ class VQuery {
|
|
|
165
187
|
this.duckDB = new DuckDB();
|
|
166
188
|
this.indexedDB = new IndexedDB(dbName);
|
|
167
189
|
}
|
|
168
|
-
|
|
169
|
-
await this.duckDB.
|
|
190
|
+
init = async ()=>{
|
|
191
|
+
await this.duckDB.init();
|
|
170
192
|
await this.indexedDB.open();
|
|
171
193
|
};
|
|
172
194
|
close = async ()=>{
|
|
@@ -208,6 +230,7 @@ class VQuery {
|
|
|
208
230
|
}
|
|
209
231
|
};
|
|
210
232
|
};
|
|
233
|
+
getSchema = async (fileName)=>this.duckDB.getSchema(fileName);
|
|
211
234
|
}
|
|
212
235
|
exports.VQuery = __webpack_exports__.VQuery;
|
|
213
236
|
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
package/dist/index.d.ts
CHANGED
|
@@ -1,41 +1 @@
|
|
|
1
|
-
export
|
|
2
|
-
private duckDB;
|
|
3
|
-
private indexedDB;
|
|
4
|
-
constructor(dbName?: string);
|
|
5
|
-
/**
|
|
6
|
-
* @description 初始化数据库
|
|
7
|
-
*/
|
|
8
|
-
instantiate: () => Promise<void>;
|
|
9
|
-
/**
|
|
10
|
-
* @description 关闭数据库
|
|
11
|
-
*/
|
|
12
|
-
close: () => Promise<void>;
|
|
13
|
-
/**
|
|
14
|
-
* @description 注册文件
|
|
15
|
-
* @param fileName 文件名
|
|
16
|
-
* @param source 文件内容
|
|
17
|
-
*/
|
|
18
|
-
writeFile: (fileName: string, source: string | ArrayBuffer | Uint8Array | Blob) => Promise<void>;
|
|
19
|
-
/**
|
|
20
|
-
* @description 从 IndexedDB 读取文件并注册到 DuckDB
|
|
21
|
-
* @param fileName 文件名
|
|
22
|
-
*/
|
|
23
|
-
readFile: (fileName: string) => Promise<void>;
|
|
24
|
-
/**
|
|
25
|
-
* @description 列出 IndexedDB 中的所有文件
|
|
26
|
-
*/
|
|
27
|
-
listFiles: () => Promise<string[]>;
|
|
28
|
-
/**
|
|
29
|
-
* @description 执行 SQL 查询
|
|
30
|
-
* @param sql SQL 语句
|
|
31
|
-
*/
|
|
32
|
-
query: (sql: string) => Promise<{
|
|
33
|
-
performance: {
|
|
34
|
-
startAt: string;
|
|
35
|
-
endAt: string;
|
|
36
|
-
duration: number;
|
|
37
|
-
};
|
|
38
|
-
dataset: any[];
|
|
39
|
-
table: any;
|
|
40
|
-
}>;
|
|
41
|
-
}
|
|
1
|
+
export { VQuery } from './vquery';
|
package/dist/index.js
CHANGED
|
@@ -1,11 +1,20 @@
|
|
|
1
|
-
import { AsyncDuckDB, ConsoleLogger,
|
|
1
|
+
import { AsyncDuckDB, ConsoleLogger, selectBundle } from "@duckdb/duckdb-wasm";
|
|
2
2
|
class DuckDB {
|
|
3
3
|
db = null;
|
|
4
4
|
connection = null;
|
|
5
5
|
constructor(){}
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
|
|
6
|
+
init = async ()=>{
|
|
7
|
+
const MANUAL_BUNDLES = {
|
|
8
|
+
mvp: {
|
|
9
|
+
mainModule: new URL('@duckdb/duckdb-wasm/dist/duckdb-mvp.wasm', import.meta.url).href,
|
|
10
|
+
mainWorker: new URL('@duckdb/duckdb-wasm/dist/duckdb-browser-mvp.worker.js', import.meta.url).toString()
|
|
11
|
+
},
|
|
12
|
+
eh: {
|
|
13
|
+
mainModule: new URL('@duckdb/duckdb-wasm/dist/duckdb-eh.wasm', import.meta.url).href,
|
|
14
|
+
mainWorker: new URL('@duckdb/duckdb-wasm/dist/duckdb-browser-eh.worker.js', import.meta.url).toString()
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
const bundle = await selectBundle(MANUAL_BUNDLES);
|
|
9
18
|
const worker_url = URL.createObjectURL(new Blob([
|
|
10
19
|
`importScripts("${bundle.mainWorker}");`
|
|
11
20
|
], {
|
|
@@ -52,6 +61,16 @@ class DuckDB {
|
|
|
52
61
|
table
|
|
53
62
|
};
|
|
54
63
|
};
|
|
64
|
+
ensureSchema = async (fileName)=>{
|
|
65
|
+
if (!this.connection) throw new Error('connection is null');
|
|
66
|
+
await this.connection.query(`CREATE TEMP TABLE IF NOT EXISTS "${fileName}" AS SELECT * FROM read_csv_auto('${fileName}')`);
|
|
67
|
+
};
|
|
68
|
+
getSchema = async (fileName)=>{
|
|
69
|
+
if (!this.connection) throw new Error('connection is null');
|
|
70
|
+
await this.ensureSchema(fileName);
|
|
71
|
+
const result = await this.connection.query(`PRAGMA table_info('${fileName}')`);
|
|
72
|
+
return result.toArray().map((row)=>row.toJSON());
|
|
73
|
+
};
|
|
55
74
|
}
|
|
56
75
|
class IndexedDB {
|
|
57
76
|
db = null;
|
|
@@ -137,8 +156,8 @@ class VQuery {
|
|
|
137
156
|
this.duckDB = new DuckDB();
|
|
138
157
|
this.indexedDB = new IndexedDB(dbName);
|
|
139
158
|
}
|
|
140
|
-
|
|
141
|
-
await this.duckDB.
|
|
159
|
+
init = async ()=>{
|
|
160
|
+
await this.duckDB.init();
|
|
142
161
|
await this.indexedDB.open();
|
|
143
162
|
};
|
|
144
163
|
close = async ()=>{
|
|
@@ -180,5 +199,6 @@ class VQuery {
|
|
|
180
199
|
}
|
|
181
200
|
};
|
|
182
201
|
};
|
|
202
|
+
getSchema = async (fileName)=>this.duckDB.getSchema(fileName);
|
|
183
203
|
}
|
|
184
204
|
export { VQuery };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type QueryResult = any;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type { QueryResult } from './QueryResult';
|
package/dist/vquery.d.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { QueryResult } from './types';
|
|
2
|
+
export declare class VQuery {
|
|
3
|
+
private duckDB;
|
|
4
|
+
private indexedDB;
|
|
5
|
+
constructor(dbName?: string);
|
|
6
|
+
/**
|
|
7
|
+
* @description 初始化数据库
|
|
8
|
+
*/
|
|
9
|
+
init: () => Promise<void>;
|
|
10
|
+
/**
|
|
11
|
+
* @description 关闭数据库
|
|
12
|
+
*/
|
|
13
|
+
close: () => Promise<void>;
|
|
14
|
+
/**
|
|
15
|
+
* @description 注册文件
|
|
16
|
+
* @param fileName 文件名
|
|
17
|
+
* @param source 文件内容
|
|
18
|
+
*/
|
|
19
|
+
writeFile: (fileName: string, source: string | ArrayBuffer | Uint8Array | Blob) => Promise<void>;
|
|
20
|
+
/**
|
|
21
|
+
* @description 从 IndexedDB 读取文件并注册到 DuckDB
|
|
22
|
+
* @param fileName 文件名
|
|
23
|
+
*/
|
|
24
|
+
readFile: (fileName: string) => Promise<void>;
|
|
25
|
+
/**
|
|
26
|
+
* @description 列出 IndexedDB 中的所有文件
|
|
27
|
+
*/
|
|
28
|
+
listFiles: () => Promise<string[]>;
|
|
29
|
+
/**
|
|
30
|
+
* @description 执行 SQL 查询
|
|
31
|
+
* @param sql SQL 语句
|
|
32
|
+
*/
|
|
33
|
+
query: (sql: string) => Promise<{
|
|
34
|
+
performance: {
|
|
35
|
+
startAt: string;
|
|
36
|
+
endAt: string;
|
|
37
|
+
duration: number;
|
|
38
|
+
};
|
|
39
|
+
dataset: any[];
|
|
40
|
+
table: any;
|
|
41
|
+
}>;
|
|
42
|
+
/**
|
|
43
|
+
* @description 获取文件的 Schema
|
|
44
|
+
* @param fileName 文件名
|
|
45
|
+
* @returns 文件的 Schema
|
|
46
|
+
*/
|
|
47
|
+
getSchema: (fileName: string) => Promise<QueryResult>;
|
|
48
|
+
}
|