@@ -19,7 +19,6 @@ export const apply = async ({
19
19
relationships,
20
20
functions,
21
21
types,
22
- arrayTypes,
23
22
detectOneToOneRelationships,
24
23
} : {
25
24
schemas : PostgresSchema [ ]
@@ -30,7 +29,6 @@ export const apply = async ({
30
29
relationships : PostgresRelationship [ ]
31
30
functions : PostgresFunction [ ]
32
31
types : PostgresType [ ]
33
- arrayTypes : PostgresType [ ]
34
32
detectOneToOneRelationships : boolean
35
33
} ) : Promise < string > => {
36
34
const columnsByTableId = Object . fromEntries < PostgresColumn [ ] > (
@@ -289,25 +287,12 @@ export type Database = {
289
287
}
290
288
291
289
const argsNameAndType = inArgs . map ( ( { name, type_id, has_default } ) => {
292
- let type = arrayTypes . find ( ( { id } ) => id === type_id )
290
+ const type = types . find ( ( { id } ) => id === type_id )
291
+ let tsType = 'unknown'
293
292
if ( type ) {
294
- // If it's an array type, the name looks like `_int8`.
295
- const elementTypeName = type . name . substring ( 1 )
296
- return {
297
- name,
298
- type : `(${ pgTypeToTsType ( elementTypeName , types , schemas ) } )[]` ,
299
- has_default,
300
- }
301
- }
302
- type = types . find ( ( { id } ) => id === type_id )
303
- if ( type ) {
304
- return {
305
- name,
306
- type : pgTypeToTsType ( type . name , types , schemas ) ,
307
- has_default,
308
- }
293
+ tsType = pgTypeToTsType ( type . name , types , schemas )
309
294
}
310
- return { name, type : 'unknown' , has_default }
295
+ return { name, type : tsType , has_default }
311
296
} )
312
297
313
298
return `{
@@ -322,20 +307,12 @@ export type Database = {
322
307
const tableArgs = args . filter ( ( { mode } ) => mode === 'table' )
323
308
if ( tableArgs . length > 0 ) {
324
309
const argsNameAndType = tableArgs . map ( ( { name, type_id } ) => {
325
- let type = arrayTypes . find ( ( { id } ) => id === type_id )
310
+ const type = types . find ( ( { id } ) => id === type_id )
311
+ let tsType = 'unknown'
326
312
if ( type ) {
327
- // If it's an array type, the name looks like `_int8`.
328
- const elementTypeName = type . name . substring ( 1 )
329
- return {
330
- name,
331
- type : `(${ pgTypeToTsType ( elementTypeName , types , schemas ) } )[]` ,
332
- }
313
+ tsType = pgTypeToTsType ( type . name , types , schemas )
333
314
}
334
- type = types . find ( ( { id } ) => id === type_id )
335
- if ( type ) {
336
- return { name, type : pgTypeToTsType ( type . name , types , schemas ) }
337
- }
338
- return { name, type : 'unknown' }
315
+ return { name, type : tsType }
339
316
} )
340
317
341
318
return `{
@@ -362,7 +339,7 @@ export type Database = {
362
339
}`
363
340
}
364
341
365
- // Case 3: returns base/composite/enum type.
342
+ // Case 3: returns base/array/ composite/enum type.
366
343
const type = types . find ( ( { id } ) => id === return_type_id )
367
344
if ( type ) {
368
345
return pgTypeToTsType ( type . name , types , schemas )
@@ -399,14 +376,11 @@ export type Database = {
399
376
`${ JSON . stringify ( name ) } : {
400
377
${ attributes . map ( ( { name, type_id } ) => {
401
378
const type = types . find ( ( { id } ) => id === type_id )
379
+ let tsType = 'unknown'
402
380
if ( type ) {
403
- return `${ JSON . stringify ( name ) } : ${ pgTypeToTsType (
404
- type . name ,
405
- types ,
406
- schemas
407
- ) } `
381
+ tsType = pgTypeToTsType ( type . name , types , schemas )
408
382
}
409
- return `${ JSON . stringify ( name ) } : unknown `
383
+ return `${ JSON . stringify ( name ) } : ${ tsType } `
410
384
} ) }
411
385
}`
412
386
)
0 commit comments