@cubejs-backend/sqlite-driver 1.3.77 → 1.3.79

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/CHANGELOG.md CHANGED
@@ -3,6 +3,16 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [1.3.79](https://github.com/cube-js/cube/compare/v1.3.78...v1.3.79) (2025-10-14)
7
+
8
+ ### Bug Fixes
9
+
10
+ - **sqlite-driver:** Use pragma_table_info to fetch table columns ([#10031](https://github.com/cube-js/cube/issues/10031)) ([070e6e0](https://github.com/cube-js/cube/commit/070e6e0d016537af293e3dc7ec02791072ccba42))
11
+
12
+ ## [1.3.78](https://github.com/cube-js/cube/compare/v1.3.77...v1.3.78) (2025-10-03)
13
+
14
+ **Note:** Version bump only for package @cubejs-backend/sqlite-driver
15
+
6
16
  ## [1.3.77](https://github.com/cube-js/cube/compare/v1.3.76...v1.3.77) (2025-10-01)
7
17
 
8
18
  **Note:** Version bump only for package @cubejs-backend/sqlite-driver
@@ -33,7 +33,7 @@ class SqliteDriver extends BaseDriver {
33
33
  const dataSource =
34
34
  config.dataSource ||
35
35
  assertDataSource('default');
36
-
36
+
37
37
  this.config = {
38
38
  database: getEnv('dbName', { dataSource }),
39
39
  ...config
@@ -64,7 +64,7 @@ class SqliteDriver extends BaseDriver {
64
64
 
65
65
  informationSchemaQuery() {
66
66
  return `
67
- SELECT name, sql
67
+ SELECT name
68
68
  FROM sqlite_master
69
69
  WHERE type='table'
70
70
  AND name!='sqlite_sequence'
@@ -72,31 +72,25 @@ class SqliteDriver extends BaseDriver {
72
72
  `;
73
73
  }
74
74
 
75
+ tableColumnsQuery(tableName) {
76
+ return `
77
+ SELECT name, type
78
+ FROM pragma_table_info('${tableName}')
79
+ `;
80
+ }
81
+
75
82
  async tablesSchema() {
76
83
  const query = this.informationSchemaQuery();
77
84
 
78
85
  const tables = await this.query(query);
79
86
 
87
+ const tableColumns = await Promise.all(tables.map(async table => {
88
+ const columns = await this.query(this.tableColumnsQuery(table.name));
89
+ return [table.name, columns];
90
+ }));
91
+
80
92
  return {
81
- main: tables.reduce((acc, table) => ({
82
- ...acc,
83
- [table.name]: table.sql
84
- // remove EOL for next .match to read full string
85
- .replace(/\n/g, '')
86
- // extract fields
87
- .match(/\((.*)\)/)[1]
88
- // split fields
89
- .split(',')
90
- .map((nameAndType) => {
91
- const match = nameAndType
92
- .trim()
93
- // replace \t with whitespace
94
- .replace(/\t/g, ' ')
95
- // obtain "([|`|")?name(]|`|")? type"
96
- .match(/([|`|"])?([^[\]"`]+)(]|`|")?\s+(\w+)/);
97
- return { name: match[2], type: match[4] };
98
- })
99
- }), {}),
93
+ main: Object.fromEntries(tableColumns)
100
94
  };
101
95
  }
102
96
 
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@cubejs-backend/sqlite-driver",
3
3
  "description": "Cube.js Sqlite database driver",
4
4
  "author": "Cube Dev, Inc.",
5
- "version": "1.3.77",
5
+ "version": "1.3.79",
6
6
  "repository": {
7
7
  "type": "git",
8
8
  "url": "https://github.com/cube-js/cube.git",
@@ -14,16 +14,18 @@
14
14
  "main": "driver/SqliteDriver.js",
15
15
  "typings": "driver/index.d.ts",
16
16
  "scripts": {
17
- "lint": "eslint **/*.js"
17
+ "lint": "eslint **/*.js",
18
+ "unit": "jest"
18
19
  },
19
20
  "dependencies": {
20
- "@cubejs-backend/base-driver": "1.3.77",
21
- "@cubejs-backend/shared": "1.3.77",
21
+ "@cubejs-backend/base-driver": "1.3.79",
22
+ "@cubejs-backend/shared": "1.3.79",
22
23
  "sqlite3": "^5.1.7"
23
24
  },
24
25
  "license": "Apache-2.0",
25
26
  "devDependencies": {
26
- "@cubejs-backend/linter": "1.3.77"
27
+ "@cubejs-backend/linter": "1.3.79",
28
+ "jest": "^29"
27
29
  },
28
30
  "publishConfig": {
29
31
  "access": "public"
@@ -31,5 +33,5 @@
31
33
  "eslintConfig": {
32
34
  "extends": "../cubejs-linter"
33
35
  },
34
- "gitHead": "4a3e0958afccfc9b710f04357e1445672d611b5a"
36
+ "gitHead": "e0c98076326f1f3a9522ce77debc9bfbb467b38f"
35
37
  }
@@ -0,0 +1,53 @@
1
+ /* globals describe, test, expect, beforeEach */
2
+ const sqlite3 = require('sqlite3');
3
+ const SqliteDriver = require('../driver/SqliteDriver.js');
4
+
5
+ describe('SqliteDriver', () => {
6
+ let driver;
7
+
8
+ beforeEach(() => {
9
+ const db = new sqlite3.Database(':memory:');
10
+ driver = new SqliteDriver({ db });
11
+ });
12
+
13
+ test('testConnection', async () => {
14
+ await driver.testConnection();
15
+ });
16
+
17
+ test('tableSchema', async () => {
18
+ await driver.query(`
19
+ CREATE TABLE users (
20
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
21
+ name TEXT NOT NULL,
22
+ email TEXT UNIQUE NOT NULL,
23
+ age INTEGER,
24
+ created_at DATETIME DEFAULT CURRENT_TIMESTAMP
25
+ );
26
+ `);
27
+
28
+ await driver.query(`
29
+ CREATE TABLE groups (
30
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
31
+ name TEXT NOT NULL
32
+ );
33
+ `);
34
+
35
+ const tableSchema = await driver.tablesSchema();
36
+
37
+ expect(tableSchema).toEqual({
38
+ main: {
39
+ users: [
40
+ { name: 'id', type: 'INTEGER' },
41
+ { name: 'name', type: 'TEXT' },
42
+ { name: 'email', type: 'TEXT' },
43
+ { name: 'age', type: 'INTEGER' },
44
+ { name: 'created_at', type: 'DATETIME' },
45
+ ],
46
+ groups: [
47
+ { name: 'id', type: 'INTEGER' },
48
+ { name: 'name', type: 'TEXT' },
49
+ ]
50
+ }
51
+ });
52
+ });
53
+ });