mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-19 04:56:00 +00:00
export model - filter by schema
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import type { DatabaseInfo, TableInfo, ApplicationDefinition, ViewInfo, CollectionInfo } from 'dbgate-types';
|
||||
import _flatten from 'lodash/flatten';
|
||||
import _uniq from 'lodash/uniq';
|
||||
|
||||
export function addTableDependencies(db: DatabaseInfo): DatabaseInfo {
|
||||
if (!db.tables) {
|
||||
@@ -142,3 +143,28 @@ export function isViewInfo(obj: { objectTypeField?: string }): obj is ViewInfo {
|
||||
export function isCollectionInfo(obj: { objectTypeField?: string }): obj is CollectionInfo {
|
||||
return obj.objectTypeField == 'collections';
|
||||
}
|
||||
|
||||
export function filterStructureBySchema(db: DatabaseInfo, schema: string) {
|
||||
return {
|
||||
...db,
|
||||
tables: (db.tables || []).filter(x => x.schemaName == schema),
|
||||
views: (db.views || []).filter(x => x.schemaName == schema),
|
||||
collections: (db.collections || []).filter(x => x.schemaName == schema),
|
||||
matviews: (db.matviews || []).filter(x => x.schemaName == schema),
|
||||
procedures: (db.procedures || []).filter(x => x.schemaName == schema),
|
||||
functions: (db.functions || []).filter(x => x.schemaName == schema),
|
||||
triggers: (db.triggers || []).filter(x => x.schemaName == schema),
|
||||
};
|
||||
}
|
||||
|
||||
export function getSchemasUsedByStructure(db: DatabaseInfo) {
|
||||
return _uniq([
|
||||
...(db.tables || []).map(x => x.schemaName),
|
||||
...(db.views || []).map(x => x.schemaName),
|
||||
...(db.collections || []).map(x => x.schemaName),
|
||||
...(db.matviews || []).map(x => x.schemaName),
|
||||
...(db.procedures || []).map(x => x.schemaName),
|
||||
...(db.functions || []).map(x => x.schemaName),
|
||||
...(db.triggers || []).map(x => x.schemaName),
|
||||
]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user