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

30 lines
772 B
TypeScript

import { DSQL_ChildrenTablesType, DSQL_TableSchemaType } from "../../../types";
type Params = {
tables?: DSQL_TableSchemaType[];
tableSchema?: DSQL_TableSchemaType;
childTableSchema?: DSQL_ChildrenTablesType;
tableName?: string;
};
export default function grabTargetTableSchemaIndex({
tables,
tableName,
tableSchema,
childTableSchema,
}: Params): number | undefined {
if (!tables) return undefined;
const targetTableIndex = tables.findIndex(
(tbl) =>
(tableName && tableName == tbl.tableName) ||
(tableSchema &&
tableSchema.tableName &&
tableSchema.tableName == tbl.tableName)
);
if (targetTableIndex < 0) return undefined;
return targetTableIndex;
}