Skip to content

Commit

Permalink
feat: add Table and Enum helper types to typegen.
Browse files Browse the repository at this point in the history
  • Loading branch information
thorwebdev committed Nov 20, 2023
1 parent 6097379 commit cf93925
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/server/templates/typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,13 @@ export interface Database {
}
}`
})}
}`
}
export type Tables<T extends keyof Database["public"]["Tables"]> =
Database["public"]["Tables"][T]["Row"];
export type Enums<T extends keyof Database["public"]["Enums"]> =
Database["public"]["Enums"][T];
`

output = prettier.format(output, {
parser: 'typescript',
Expand Down
10 changes: 10 additions & 0 deletions test/server/typegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,11 @@ test('typegen', async () => {
}
}
}
export type Tables<T extends keyof Database["public"]["Tables"]> =
Database["public"]["Tables"][T]["Row"]
export type Enums<T extends keyof Database["public"]["Enums"]> =
Database["public"]["Enums"][T]
"
`)
})
Expand Down Expand Up @@ -747,6 +752,11 @@ test('typegen w/ one-to-one relationships', async () => {
}
}
}
export type Tables<T extends keyof Database["public"]["Tables"]> =
Database["public"]["Tables"][T]["Row"]
export type Enums<T extends keyof Database["public"]["Enums"]> =
Database["public"]["Enums"][T]
"
`)
})

0 comments on commit cf93925

Please sign in to comment.