Skip to content

Commit

Permalink
fix(@cubejs-backend/sqlite-driver): sqlite name and type extraction (#…
Browse files Browse the repository at this point in the history
…659) Thanks to @avin3sh !

* Fix sqlite name and type extraction

* Fix lint issues
  • Loading branch information
avin3sh authored May 23, 2020
1 parent d3cb6ce commit b1c179d
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions packages/cubejs-sqlite-driver/driver/SqliteDriver.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class SqliteDriver extends BaseDriver {
SELECT name, sql
FROM sqlite_master
WHERE type='table'
AND name!='sqlite_sequence'
ORDER BY name
`;
}
Expand All @@ -58,8 +59,10 @@ class SqliteDriver extends BaseDriver {
.map((nameAndType) => {
const match = nameAndType
.trim()
// replace \t with whitespace
.replace(/\t/g, ' ')
// obtain "([|`|")?name(]|`|")? type"
.match(/([|`|")?([^[\]"`]+)(]|`|")?\s+(\w+)/);
.match(/([|`|"])?([^[\]"`]+)(]|`|")?\s+(\w+)/);
return { name: match[2], type: match[4] };
})
}), {}),
Expand All @@ -68,7 +71,7 @@ class SqliteDriver extends BaseDriver {

createSchemaIfNotExists(schemaName) {
return this.query(
`PRAGMA database_list`
'PRAGMA database_list'
).then((schemas) => {
if (!schemas.find(s => s.name === schemaName)) {
return this.query(`ATTACH DATABASE ${schemaName} AS ${schemaName}`);
Expand All @@ -79,7 +82,7 @@ class SqliteDriver extends BaseDriver {

async getTablesQuery(schemaName) {
const attachedDatabases = await this.query(
`PRAGMA database_list`
'PRAGMA database_list'
);
if (!attachedDatabases.find(s => s.name === schemaName)) {
return [];
Expand Down

0 comments on commit b1c179d

Please sign in to comment.