@@ -13,12 +13,14 @@ export const apply = ({
13
13
views,
14
14
functions,
15
15
types,
16
+ arrayTypes,
16
17
} : {
17
18
schemas : PostgresSchema [ ]
18
19
tables : PostgresTable [ ]
19
20
views : PostgresView [ ]
20
21
functions : PostgresFunction [ ]
21
22
types : PostgresType [ ]
23
+ arrayTypes : PostgresType [ ]
22
24
} ) : string => {
23
25
let output = `
24
26
export type Json = string | number | boolean | null | { [key: string]: Json } | Json[]
@@ -214,11 +216,20 @@ export interface Database {
214
216
}
215
217
216
218
const argsNameAndType = inArgs . map ( ( { name, type_id } ) => {
217
- const type = types . find ( ( { id } ) => id === type_id )
218
- if ( ! type ) {
219
- return { name, type : 'unknown' }
219
+ let type = arrayTypes . find ( ( { id } ) => id === type_id )
220
+ if ( type ) {
221
+ // If it's an array type, the name looks like `_int8`.
222
+ const elementTypeName = type . name . substring ( 1 )
223
+ return {
224
+ name,
225
+ type : `(${ pgTypeToTsType ( elementTypeName , types , schemas ) } )[]` ,
226
+ }
227
+ }
228
+ type = types . find ( ( { id } ) => id === type_id )
229
+ if ( type ) {
230
+ return { name, type : pgTypeToTsType ( type . name , types , schemas ) }
220
231
}
221
- return { name, type : pgTypeToTsType ( type . name , types , schemas ) }
232
+ return { name, type : 'unknown' }
222
233
} )
223
234
224
235
return `{ ${ argsNameAndType . map (
@@ -230,11 +241,20 @@ export interface Database {
230
241
231
242
if ( tableArgs . length > 0 ) {
232
243
const argsNameAndType = tableArgs . map ( ( { name, type_id } ) => {
233
- const type = types . find ( ( { id } ) => id === type_id )
234
- if ( ! type ) {
235
- return { name, type : 'unknown' }
244
+ let type = arrayTypes . find ( ( { id } ) => id === type_id )
245
+ if ( type ) {
246
+ // If it's an array type, the name looks like `_int8`.
247
+ const elementTypeName = type . name . substring ( 1 )
248
+ return {
249
+ name,
250
+ type : `(${ pgTypeToTsType ( elementTypeName , types , schemas ) } )[]` ,
251
+ }
236
252
}
237
- return { name, type : pgTypeToTsType ( type . name , types , schemas ) }
253
+ type = types . find ( ( { id } ) => id === type_id )
254
+ if ( type ) {
255
+ return { name, type : pgTypeToTsType ( type . name , types , schemas ) }
256
+ }
257
+ return { name, type : 'unknown' }
238
258
} )
239
259
240
260
return `{ ${ argsNameAndType . map (
0 commit comments