@@ -139,8 +139,24 @@ ORDER BY lower(views.name);
139139 } ) ;
140140
141141 const filteredTableIds = filteredTables . map ( ( it ) => it . object_id ) ;
142- const viewsIds = viewsList . map ( ( it ) => it . object_id ) ;
143- const filteredViewsAndTableIds = [ ...filteredTableIds , ...viewsIds ] ;
142+ const filteredViewIds = viewsList . map ( ( it ) => it . object_id ) ;
143+ const filteredViewsAndTableIds = [ ...filteredTableIds , ...filteredViewIds ] ;
144+
145+ if ( filteredViewIds . length === 0 && filteredTableIds . length === 0 ) {
146+ return {
147+ schemas,
148+ tables : [ ] ,
149+ columns : [ ] ,
150+ pks : [ ] ,
151+ fks : [ ] ,
152+ indexes : [ ] ,
153+ uniques : [ ] ,
154+ defaults : [ ] ,
155+ checks : [ ] ,
156+ views : [ ] ,
157+ viewColumns : [ ] ,
158+ } ;
159+ }
144160
145161 const filterByTableIds = filteredTableIds . length > 0 ? `(${ filteredTableIds . join ( ',' ) } )` : '' ;
146162 const filterByTableAndViewIds = filteredViewsAndTableIds . length > 0 ? `(${ filteredViewsAndTableIds . join ( ',' ) } )` : '' ;
@@ -250,30 +266,31 @@ ORDER BY lower(fk.name);
250266 filter_definition : string ;
251267 column_id : number ;
252268 } ;
269+
253270 const pksUniquesAndIdxsQuery = await db . query < RawIdxsAndConstraints > ( `
254- SELECT
255- i.object_id as table_id,
256- i.index_id as index_id,
257- i.name AS name,
258- i.is_unique as is_unique,
259- i.is_primary_key as is_primary_key,
260- i.is_unique_constraint as is_unique_constraint,
261- i.has_filter as has_filter,
262- i.filter_definition as filter_definition,
263- ic.column_id as column_id
264- FROM sys.indexes i
265- INNER JOIN sys.index_columns ic
266- ON i.object_id = ic.object_id
267- AND i.index_id = ic.index_id
268- ${ filterByTableIds ? 'WHERE i.object_id in ' + filterByTableIds : '' }
269- ORDER BY lower(i.name)
270- ;` ) . then ( ( rows ) => {
271- queryCallback ( 'indexes' , rows , null ) ;
272- return rows ;
273- } ) . catch ( ( error ) => {
274- queryCallback ( 'indexes' , [ ] , error ) ;
275- throw error ;
276- } ) ;
271+ SELECT
272+ i.object_id as table_id,
273+ i.index_id as index_id,
274+ i.name AS name,
275+ i.is_unique as is_unique,
276+ i.is_primary_key as is_primary_key,
277+ i.is_unique_constraint as is_unique_constraint,
278+ i.has_filter as has_filter,
279+ i.filter_definition as filter_definition,
280+ ic.column_id as column_id
281+ FROM sys.indexes i
282+ INNER JOIN sys.index_columns ic
283+ ON i.object_id = ic.object_id
284+ AND i.index_id = ic.index_id
285+ ${ filterByTableIds ? 'WHERE i.object_id in ' + filterByTableIds : '' }
286+ ORDER BY lower(i.name);` )
287+ . then ( ( rows ) => {
288+ queryCallback ( 'indexes' , rows , null ) ;
289+ return rows ;
290+ } ) . catch ( ( error ) => {
291+ queryCallback ( 'indexes' , [ ] , error ) ;
292+ throw error ;
293+ } ) ;
277294
278295 const columnsQuery = await db . query < {
279296 column_id : number ;
@@ -323,8 +340,7 @@ LEFT JOIN sys.computed_columns computed
323340LEFT JOIN sys.objects obj
324341 ON obj.object_id = col.object_id
325342WHERE obj.type in ('U', 'V')
326- AND AND obj.is_ms_shipped = 0
327- ${ filterByTableAndViewIds ? ` AND col.object_id IN ${ filterByTableAndViewIds } ` : `` } ;
343+ AND col.object_id IN ${ filterByTableAndViewIds } ;
328344` ) . then ( ( rows ) => {
329345 queryCallback ( 'columns' , rows , null ) ;
330346 return rows ;
0 commit comments