File tree Expand file tree Collapse file tree 1 file changed +16
-3
lines changed
Expand file tree Collapse file tree 1 file changed +16
-3
lines changed Original file line number Diff line number Diff line change @@ -3,9 +3,22 @@ import { pick } from '$lib/utils'
33import { getTableColumns } from 'drizzle-orm'
44import type { AnyPgTable } from 'drizzle-orm/pg-core'
55
6+ type InferColumnNames < T extends AnyPgTable > = keyof T [ '_' ] [ 'columns' ]
7+
68/**
7- * Used in .select({...pickSchema(schema, 'column1', 'column2', ...)})
9+ * Fully type-safe way to pick columns from a schema (plus rename-symbol support in IDEs)
10+ *
11+ * @example
12+ *
13+ * ```ts
14+ * .select({
15+ * ...pickSchema(userSchema, { id: true, email: true })
16+ * })
17+ * ```
818 */
9- export function pickSchema < T extends AnyPgTable > ( schema : T , ...keys : ( keyof T [ '_' ] [ 'columns' ] ) [ ] ) {
10- return pick ( getTableColumns ( schema ) , ...keys )
19+ export function pickSchema < T extends AnyPgTable > (
20+ schema : T ,
21+ include : { [ P in InferColumnNames < T > ] ?: true }
22+ ) {
23+ return pick ( getTableColumns ( schema ) , ...( Object . keys ( include ) as InferColumnNames < T > [ ] ) )
1124}
You can’t perform that action at this time.
0 commit comments