Skip to content

Commit ba87d22

Browse files
sweatybridgesoedirgo
authored andcommitted
fix(typegen): handle tables without any columns
1 parent 9b14fae commit ba87d22

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

src/server/templates/typescript.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,13 @@ export const apply = async ({
3333
arrayTypes: PostgresType[]
3434
detectOneToOneRelationships: boolean
3535
}): Promise<string> => {
36-
const columnsByTableId = columns
36+
const columnsByTableId = Object.fromEntries<PostgresColumn[]>(
37+
[...tables, ...views, ...materializedViews].map((t) => [t.id, []])
38+
)
39+
columns
40+
.filter((c) => c.table_id in columnsByTableId)
3741
.sort(({ name: a }, { name: b }) => a.localeCompare(b))
38-
.reduce(
39-
(acc, curr) => {
40-
acc[curr.table_id] ??= []
41-
acc[curr.table_id].push(curr)
42-
return acc
43-
},
44-
{} as Record<string, PostgresColumn[]>
45-
)
42+
.forEach((c) => columnsByTableId[c.table_id].push(c))
4643

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

0 commit comments

Comments
 (0)