@@ -80,20 +80,22 @@ export interface Database {
80
80
${
81
81
schemaTables . length === 0
82
82
? '[_ 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 ) } : {
85
89
Row: {
86
90
${ [
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
+ ) ,
97
99
...schemaFunctions
98
100
. filter ( ( fn ) => fn . argument_types === table . name )
99
101
. map (
@@ -107,52 +109,48 @@ export interface Database {
107
109
] }
108
110
}
109
111
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 )
114
114
115
- if ( column . identity_generation === 'ALWAYS' ) {
116
- return `${ output } ?: never`
117
- }
115
+ if ( column . identity_generation === 'ALWAYS' ) {
116
+ return `${ output } ?: never`
117
+ }
118
118
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
+ }
128
128
129
- output += pgTypeToTsType ( column . format , types , schemas )
129
+ output += pgTypeToTsType ( column . format , types , schemas )
130
130
131
- if ( column . is_nullable ) {
132
- output += '| null'
133
- }
131
+ if ( column . is_nullable ) {
132
+ output += '| null'
133
+ }
134
134
135
- return output
136
- } ) }
135
+ return output
136
+ } ) }
137
137
}
138
138
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 )
143
141
144
- if ( column . identity_generation === 'ALWAYS' ) {
145
- return `${ output } ?: never`
146
- }
142
+ if ( column . identity_generation === 'ALWAYS' ) {
143
+ return `${ output } ?: never`
144
+ }
147
145
148
- output += `?: ${ pgTypeToTsType ( column . format , types , schemas ) } `
146
+ output += `?: ${ pgTypeToTsType ( column . format , types , schemas ) } `
149
147
150
- if ( column . is_nullable ) {
151
- output += '| null'
152
- }
148
+ if ( column . is_nullable ) {
149
+ output += '| null'
150
+ }
153
151
154
- return output
155
- } ) }
152
+ return output
153
+ } ) }
156
154
}
157
155
Relationships: [
158
156
${ relationships
@@ -174,66 +172,55 @@ export interface Database {
174
172
) }
175
173
]
176
174
}`
177
- )
175
+ } )
178
176
}
179
177
}
180
178
Views: {
181
179
${
182
180
schemaViews . length === 0
183
181
? '[_ 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 ) } : {
186
187
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
+ ) }
197
196
}
198
197
${
199
198
'is_updatable' in view && view . is_updatable
200
199
? `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
+ } ) }
218
211
}
219
212
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
+ } ) }
237
224
}
238
225
`
239
226
: ''
@@ -256,7 +243,7 @@ export interface Database {
256
243
) }
257
244
]
258
245
}`
259
- )
246
+ } )
260
247
}
261
248
}
262
249
Functions: {
0 commit comments