@visactor/vquery 0.1.34 → 0.1.36

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,3 +1,4 @@
1
+ import { QueryResult } from '../types';
1
2
  export declare class DuckDB {
2
3
  private db;
3
4
  private connection;
@@ -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
@@ -92,6 +92,16 @@ class DuckDB {
92
92
  table
93
93
  };
94
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
+ };
95
105
  }
96
106
  class IndexedDB {
97
107
  db = null;
@@ -220,6 +230,7 @@ class VQuery {
220
230
  }
221
231
  };
222
232
  };
233
+ getSchema = async (fileName)=>this.duckDB.getSchema(fileName);
223
234
  }
224
235
  exports.VQuery = __webpack_exports__.VQuery;
225
236
  for(var __webpack_i__ in __webpack_exports__)if (-1 === [
package/dist/index.js CHANGED
@@ -61,6 +61,16 @@ class DuckDB {
61
61
  table
62
62
  };
63
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
+ };
64
74
  }
65
75
  class IndexedDB {
66
76
  db = null;
@@ -189,5 +199,6 @@ class VQuery {
189
199
  }
190
200
  };
191
201
  };
202
+ getSchema = async (fileName)=>this.duckDB.getSchema(fileName);
192
203
  }
193
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 CHANGED
@@ -1,3 +1,4 @@
1
+ import { QueryResult } from './types';
1
2
  export declare class VQuery {
2
3
  private duckDB;
3
4
  private indexedDB;
@@ -38,4 +39,10 @@ export declare class VQuery {
38
39
  dataset: any[];
39
40
  table: any;
40
41
  }>;
42
+ /**
43
+ * @description 获取文件的 Schema
44
+ * @param fileName 文件名
45
+ * @returns 文件的 Schema
46
+ */
47
+ getSchema: (fileName: string) => Promise<QueryResult>;
41
48
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@visactor/vquery",
3
- "version": "0.1.34",
3
+ "version": "0.1.36",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {