File tree Expand file tree Collapse file tree 1 file changed +14
-20
lines changed
packages/cubejs-sqlite-driver/driver Expand file tree Collapse file tree 1 file changed +14
-20
lines changed Original file line number Diff line number Diff line change @@ -64,39 +64,33 @@ class SqliteDriver extends BaseDriver {
6464
6565 informationSchemaQuery ( ) {
6666 return `
67- SELECT name, sql
67+ SELECT name
6868 FROM sqlite_master
6969 WHERE type='table'
7070 AND name!='sqlite_sequence'
7171 ORDER BY name
7272 ` ;
7373 }
7474
75+ tableColumnsQuery ( tableName ) {
76+ return `
77+ SELECT name, type
78+ FROM pragma_table_info('${ tableName } ')
79+ ` ;
80+ }
81+
7582 async tablesSchema ( ) {
7683 const query = this . informationSchemaQuery ( ) ;
7784
7885 const tables = await this . query ( query ) ;
7986
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+
8092 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 )
10094 } ;
10195 }
10296
You can’t perform that action at this time.
0 commit comments