File tree Expand file tree Collapse file tree 3 files changed +10
-19
lines changed Expand file tree Collapse file tree 3 files changed +10
-19
lines changed Original file line number Diff line number Diff line change @@ -35,7 +35,7 @@ WITH roles AS (${
3535 } )
3636SELECT
3737 *,
38- ${ coalesceRowsToArray ( 'grants' , 'SELECT * FROM grants WHERE grants.grantee = roles.name' ) }
38+ ${ coalesceRowsToArray ( 'grants' , 'grants.grantee = roles.name' ) }
3939FROM
4040 roles`
4141 if ( limit ) {
Original file line number Diff line number Diff line change @@ -211,21 +211,13 @@ WITH tables AS (${tablesSql}),
211211 relationships AS (${ relationshipsSql } )
212212SELECT
213213 *,
214- ${ coalesceRowsToArray ( 'columns' , 'SELECT * FROM columns WHERE columns.table_id = tables.id' ) } ,
215- ${ coalesceRowsToArray ( 'grants' , 'SELECT * FROM grants WHERE grants.table_id = tables.id' ) } ,
216- ${ coalesceRowsToArray ( 'policies' , 'SELECT * FROM policies WHERE policies.table_id = tables.id' ) } ,
217- ${ coalesceRowsToArray (
218- 'primary_keys' ,
219- 'SELECT * FROM primary_keys WHERE primary_keys.table_id = tables.id'
220- ) } ,
214+ ${ coalesceRowsToArray ( 'columns' , 'columns.table_id = tables.id' ) } ,
215+ ${ coalesceRowsToArray ( 'grants' , 'grants.table_id = tables.id' ) } ,
216+ ${ coalesceRowsToArray ( 'policies' , 'policies.table_id = tables.id' ) } ,
217+ ${ coalesceRowsToArray ( 'primary_keys' , 'primary_keys.table_id = tables.id' ) } ,
221218 ${ coalesceRowsToArray (
222219 'relationships' ,
223- `SELECT
224- *
225- FROM
226- relationships
227- WHERE
228- (relationships.source_schema = tables.schema AND relationships.source_table_name = tables.name)
220+ `(relationships.source_schema = tables.schema AND relationships.source_table_name = tables.name)
229221 OR (relationships.target_table_schema = tables.schema AND relationships.target_table_name = tables.name)`
230222 ) }
231223FROM tables`
Original file line number Diff line number Diff line change 1- export const coalesceRowsToArray = ( source : string , joinQuery : string ) => {
2- // Note that array_to_json(array_agg(row_to_json())) seems to perform better than json_agg
1+ export const coalesceRowsToArray = ( source : string , filter : string ) => {
32 return `
43COALESCE(
54 (
65 SELECT
7- array_to_json( array_agg(row_to_json(${ source } )))
6+ array_agg(row_to_json(${ source } )) FILTER (WHERE ${ filter } )
87 FROM
9- ( ${ joinQuery } ) ${ source }
8+ ${ source }
109 ),
11- '[] '
10+ '{} '
1211) AS ${ source } `
1312}
You can’t perform that action at this time.
0 commit comments