diff --git a/leaky-ships/src/lib/utils/prizma.ts b/leaky-ships/src/lib/utils/prizma.ts new file mode 100644 index 0000000..e790f99 --- /dev/null +++ b/leaky-ships/src/lib/utils/prizma.ts @@ -0,0 +1,44 @@ +import { PgColumn, PgTableWithColumns } from "drizzle-orm/pg-core" +import * as schema from "../../drizzle/schemas/Tables" + +type FilteredKeys = { + [K in keyof T]: T[K] extends U ? K : never +}[keyof T] + +// eslint-disable-next-line @typescript-eslint/no-explicit-any +type TableNames = FilteredKeys> +type ColumnNames = FilteredKeys< + (typeof schema)[T], + PgColumn +> + +type ColumnDataType< + T extends TableNames, + C extends ColumnNames, + // eslint-disable-next-line @typescript-eslint/no-explicit-any +> = (typeof schema)[T][C] extends PgColumn + ? Type["data"] + : never + +type Config> = { + table: T + where: Pick< + { + [C in ColumnNames]: ColumnDataType + }, + TT + > +} + +export const prism = { + findFirst>( + config: Config, + ) { + JSON.stringify(config) + }, +} + +prism.findFirst({ + table: "games", + where: { id: "123456" }, +})