datasquirel/package-shared/utils/db/schema/grab-target-db-schema-index.ts
Benjamin Toby 7e8bb37c09 Updates
2025-07-05 14:59:30 +01:00

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;
}