Partial start on types for prizma query
This commit is contained in:
parent
4c2c578311
commit
1cc34744a8
1 changed files with 44 additions and 0 deletions
44
leaky-ships/src/lib/utils/prizma.ts
Normal file
44
leaky-ships/src/lib/utils/prizma.ts
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
import { PgColumn, PgTableWithColumns } from "drizzle-orm/pg-core"
|
||||||
|
import * as schema from "../../drizzle/schemas/Tables"
|
||||||
|
|
||||||
|
type FilteredKeys<T, U> = {
|
||||||
|
[K in keyof T]: T[K] extends U ? K : never
|
||||||
|
}[keyof T]
|
||||||
|
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
|
type TableNames = FilteredKeys<typeof schema, PgTableWithColumns<any>>
|
||||||
|
type ColumnNames<T extends TableNames> = FilteredKeys<
|
||||||
|
(typeof schema)[T],
|
||||||
|
PgColumn
|
||||||
|
>
|
||||||
|
|
||||||
|
type ColumnDataType<
|
||||||
|
T extends TableNames,
|
||||||
|
C extends ColumnNames<T>,
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
|
> = (typeof schema)[T][C] extends PgColumn<infer Type, any, any>
|
||||||
|
? Type["data"]
|
||||||
|
: never
|
||||||
|
|
||||||
|
type Config<T extends TableNames, TT extends ColumnNames<T>> = {
|
||||||
|
table: T
|
||||||
|
where: Pick<
|
||||||
|
{
|
||||||
|
[C in ColumnNames<T>]: ColumnDataType<T, C>
|
||||||
|
},
|
||||||
|
TT
|
||||||
|
>
|
||||||
|
}
|
||||||
|
|
||||||
|
export const prism = {
|
||||||
|
findFirst<T extends TableNames, TT extends ColumnNames<T>>(
|
||||||
|
config: Config<T, TT>,
|
||||||
|
) {
|
||||||
|
JSON.stringify(config)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
prism.findFirst({
|
||||||
|
table: "games",
|
||||||
|
where: { id: "123456" },
|
||||||
|
})
|
Loading…
Add table
Add a link
Reference in a new issue