Skip to content

Commit

Permalink
fix(typegen): handle tables without any columns
Browse files Browse the repository at this point in the history
  • Loading branch information
sweatybridge authored and soedirgo committed Feb 21, 2024
1 parent 9b14fae commit ba87d22
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions src/server/templates/typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,13 @@ export const apply = async ({
arrayTypes: PostgresType[]
detectOneToOneRelationships: boolean
}): Promise<string> => {
const columnsByTableId = columns
const columnsByTableId = Object.fromEntries<PostgresColumn[]>(
[...tables, ...views, ...materializedViews].map((t) => [t.id, []])
)
columns
.filter((c) => c.table_id in columnsByTableId)
.sort(({ name: a }, { name: b }) => a.localeCompare(b))
.reduce(
(acc, curr) => {
acc[curr.table_id] ??= []
acc[curr.table_id].push(curr)
return acc
},
{} as Record<string, PostgresColumn[]>
)
.forEach((c) => columnsByTableId[c.table_id].push(c))

let output = `
export type Json = string | number | boolean | null | { [key: string]: Json | undefined } | Json[]
Expand Down

0 comments on commit ba87d22

Please sign in to comment.