37 lines
899 B
TypeScript
37 lines
899 B
TypeScript
import {
|
|
DSQL_ChildrenDatabaseObject,
|
|
DSQL_ChildrenTablesType,
|
|
DSQL_DatabaseSchemaType,
|
|
} from "../../../types";
|
|
|
|
type Params = {
|
|
dbs?: DSQL_DatabaseSchemaType[];
|
|
dbSchema?: DSQL_DatabaseSchemaType;
|
|
childDbSchema?: DSQL_ChildrenDatabaseObject;
|
|
childTableSchema?: DSQL_ChildrenTablesType;
|
|
dbSlug?: string;
|
|
dbFullName?: string;
|
|
};
|
|
|
|
export default function grabTargetDatabaseSchemaIndex({
|
|
dbs,
|
|
dbFullName,
|
|
dbSlug,
|
|
dbSchema,
|
|
childDbSchema,
|
|
childTableSchema,
|
|
}: Params): number | undefined {
|
|
if (!dbs) return undefined;
|
|
|
|
const targetDbIndex = dbs.findIndex(
|
|
(db) =>
|
|
(dbSlug && dbSlug == db.dbSlug) ||
|
|
(dbFullName && dbFullName == db.dbFullName) ||
|
|
(dbSchema && dbSchema.dbSlug && dbSchema.dbSlug == db.dbSlug)
|
|
);
|
|
|
|
if (targetDbIndex < 0) return undefined;
|
|
|
|
return targetDbIndex;
|
|
}
|