@@ -80,20 +80,22 @@ export interface Database {
8080 ${
8181 schemaTables . length === 0
8282 ? '[_ in never]: never'
83- : schemaTables . map (
84- ( table ) => `${ JSON . stringify ( table . name ) } : {
83+ : schemaTables . map ( ( table ) => {
84+ const tableColumns = schemaColumns . filter (
85+ ( column ) => column . table_id === table . id
86+ )
87+
88+ return `${ JSON . stringify ( table . name ) } : {
8589 Row: {
8690 ${ [
87- ...schemaColumns
88- . filter ( ( column ) => column . table_id === table . id )
89- . map (
90- ( column ) =>
91- `${ JSON . stringify ( column . name ) } : ${ pgTypeToTsType (
92- column . format ,
93- types ,
94- schemas
95- ) } ${ column . is_nullable ? '| null' : '' } `
96- ) ,
91+ ...tableColumns . map (
92+ ( column ) =>
93+ `${ JSON . stringify ( column . name ) } : ${ pgTypeToTsType (
94+ column . format ,
95+ types ,
96+ schemas
97+ ) } ${ column . is_nullable ? '| null' : '' } `
98+ ) ,
9799 ...schemaFunctions
98100 . filter ( ( fn ) => fn . argument_types === table . name )
99101 . map (
@@ -107,52 +109,48 @@ export interface Database {
107109 ] }
108110 }
109111 Insert: {
110- ${ schemaColumns
111- . filter ( ( column ) => column . table_id === table . id )
112- . map ( ( column ) => {
113- let output = JSON . stringify ( column . name )
112+ ${ tableColumns . map ( ( column ) => {
113+ let output = JSON . stringify ( column . name )
114114
115- if ( column . identity_generation === 'ALWAYS' ) {
116- return `${ output } ?: never`
117- }
115+ if ( column . identity_generation === 'ALWAYS' ) {
116+ return `${ output } ?: never`
117+ }
118118
119- if (
120- column . is_nullable ||
121- column . is_identity ||
122- column . default_value !== null
123- ) {
124- output += '?:'
125- } else {
126- output += ':'
127- }
119+ if (
120+ column . is_nullable ||
121+ column . is_identity ||
122+ column . default_value !== null
123+ ) {
124+ output += '?:'
125+ } else {
126+ output += ':'
127+ }
128128
129- output += pgTypeToTsType ( column . format , types , schemas )
129+ output += pgTypeToTsType ( column . format , types , schemas )
130130
131- if ( column . is_nullable ) {
132- output += '| null'
133- }
131+ if ( column . is_nullable ) {
132+ output += '| null'
133+ }
134134
135- return output
136- } ) }
135+ return output
136+ } ) }
137137 }
138138 Update: {
139- ${ schemaColumns
140- . filter ( ( column ) => column . table_id === table . id )
141- . map ( ( column ) => {
142- let output = JSON . stringify ( column . name )
139+ ${ tableColumns . map ( ( column ) => {
140+ let output = JSON . stringify ( column . name )
143141
144- if ( column . identity_generation === 'ALWAYS' ) {
145- return `${ output } ?: never`
146- }
142+ if ( column . identity_generation === 'ALWAYS' ) {
143+ return `${ output } ?: never`
144+ }
147145
148- output += `?: ${ pgTypeToTsType ( column . format , types , schemas ) } `
146+ output += `?: ${ pgTypeToTsType ( column . format , types , schemas ) } `
149147
150- if ( column . is_nullable ) {
151- output += '| null'
152- }
148+ if ( column . is_nullable ) {
149+ output += '| null'
150+ }
153151
154- return output
155- } ) }
152+ return output
153+ } ) }
156154 }
157155 Relationships: [
158156 ${ relationships
@@ -174,66 +172,55 @@ export interface Database {
174172 ) }
175173 ]
176174 }`
177- )
175+ } )
178176 }
179177 }
180178 Views: {
181179 ${
182180 schemaViews . length === 0
183181 ? '[_ in never]: never'
184- : schemaViews . map (
185- ( view ) => `${ JSON . stringify ( view . name ) } : {
182+ : schemaViews . map ( ( view ) => {
183+ const viewColumns = schemaColumns . filter (
184+ ( column ) => column . table_id === view . id
185+ )
186+ return `${ JSON . stringify ( view . name ) } : {
186187 Row: {
187- ${ schemaColumns
188- . filter ( ( column ) => column . table_id === view . id )
189- . map (
190- ( column ) =>
191- `${ JSON . stringify ( column . name ) } : ${ pgTypeToTsType (
192- column . format ,
193- types ,
194- schemas
195- ) } ${ column . is_nullable ? '| null' : '' } `
196- ) }
188+ ${ viewColumns . map (
189+ ( column ) =>
190+ `${ JSON . stringify ( column . name ) } : ${ pgTypeToTsType (
191+ column . format ,
192+ types ,
193+ schemas
194+ ) } ${ column . is_nullable ? '| null' : '' } `
195+ ) }
197196 }
198197 ${
199198 'is_updatable' in view && view . is_updatable
200199 ? `Insert: {
201- ${ schemaColumns
202- . filter ( ( column ) => column . table_id === view . id )
203- . map ( ( column ) => {
204- let output = JSON . stringify ( column . name )
205-
206- if ( ! column . is_updatable ) {
207- return `${ output } ?: never`
208- }
209-
210- output += `?: ${ pgTypeToTsType (
211- column . format ,
212- types ,
213- schemas
214- ) } | null`
215-
216- return output
217- } ) }
200+ ${ viewColumns . map ( ( column ) => {
201+ let output = JSON . stringify ( column . name )
202+
203+ if ( ! column . is_updatable ) {
204+ return `${ output } ?: never`
205+ }
206+
207+ output += `?: ${ pgTypeToTsType ( column . format , types , schemas ) } | null`
208+
209+ return output
210+ } ) }
218211 }
219212 Update: {
220- ${ schemaColumns
221- . filter ( ( column ) => column . table_id === view . id )
222- . map ( ( column ) => {
223- let output = JSON . stringify ( column . name )
224-
225- if ( ! column . is_updatable ) {
226- return `${ output } ?: never`
227- }
228-
229- output += `?: ${ pgTypeToTsType (
230- column . format ,
231- types ,
232- schemas
233- ) } | null`
234-
235- return output
236- } ) }
213+ ${ viewColumns . map ( ( column ) => {
214+ let output = JSON . stringify ( column . name )
215+
216+ if ( ! column . is_updatable ) {
217+ return `${ output } ?: never`
218+ }
219+
220+ output += `?: ${ pgTypeToTsType ( column . format , types , schemas ) } | null`
221+
222+ return output
223+ } ) }
237224 }
238225 `
239226 : ''
@@ -256,7 +243,7 @@ export interface Database {
256243 ) }
257244 ]
258245 }`
259- )
246+ } )
260247 }
261248 }
262249 Functions: {
0 commit comments