Skip to content

Commit

Permalink
fix(typegen): allow composite type attributes to be null
Browse files Browse the repository at this point in the history
  • Loading branch information
arin-c committed Sep 20, 2023
1 parent a11bae5 commit aa71282
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/server/templates/typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ export interface Database {
type.name,
types,
schemas
)}`
)} | null`
}
return `${JSON.stringify(name)}: unknown`
})}
Expand Down
4 changes: 3 additions & 1 deletion test/db/01-memes.sql
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@

CREATE TYPE public.composite_t AS (attr int);

CREATE TABLE public.category (
id serial NOT NULL PRIMARY KEY,
name text NOT NULL
name text NOT NULL,
composite composite_t
);

-- Fake policies
Expand Down
7 changes: 6 additions & 1 deletion test/server/typegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,17 @@ test('typegen', async () => {
Tables: {
category: {
Row: {
composite: Database["public"]["CompositeTypes"]["composite_t"] | null
id: number
name: string
}
Insert: {
composite?: Database["public"]["CompositeTypes"]["composite_t"] | null
id?: number
name: string
}
Update: {
composite?: Database["public"]["CompositeTypes"]["composite_t"] | null
id?: number
name?: string
}
Expand Down Expand Up @@ -264,7 +267,9 @@ test('typegen', async () => {
user_status: "ACTIVE" | "INACTIVE"
}
CompositeTypes: {
[_ in never]: never
composite_t: {
attr: number | null
}
}
}
}
Expand Down

0 comments on commit aa71282

Please sign in to comment.