@@ -19,7 +19,6 @@ export const apply = async ({
1919 relationships,
2020 functions,
2121 types,
22- arrayTypes,
2322 detectOneToOneRelationships,
2423} : {
2524 schemas : PostgresSchema [ ]
@@ -30,7 +29,6 @@ export const apply = async ({
3029 relationships : PostgresRelationship [ ]
3130 functions : PostgresFunction [ ]
3231 types : PostgresType [ ]
33- arrayTypes : PostgresType [ ]
3432 detectOneToOneRelationships : boolean
3533} ) : Promise < string > => {
3634 const columnsByTableId = Object . fromEntries < PostgresColumn [ ] > (
@@ -289,25 +287,12 @@ export type Database = {
289287 }
290288
291289 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'
293292 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 )
309294 }
310- return { name, type : 'unknown' , has_default }
295+ return { name, type : tsType , has_default }
311296 } )
312297
313298 return `{
@@ -322,20 +307,12 @@ export type Database = {
322307 const tableArgs = args . filter ( ( { mode } ) => mode === 'table' )
323308 if ( tableArgs . length > 0 ) {
324309 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'
326312 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 )
333314 }
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 }
339316 } )
340317
341318 return `{
@@ -362,7 +339,7 @@ export type Database = {
362339 }`
363340 }
364341
365- // Case 3: returns base/composite/enum type.
342+ // Case 3: returns base/array/ composite/enum type.
366343 const type = types . find ( ( { id } ) => id === return_type_id )
367344 if ( type ) {
368345 return pgTypeToTsType ( type . name , types , schemas )
@@ -399,14 +376,11 @@ export type Database = {
399376 `${ JSON . stringify ( name ) } : {
400377 ${ attributes . map ( ( { name, type_id } ) => {
401378 const type = types . find ( ( { id } ) => id === type_id )
379+ let tsType = 'unknown'
402380 if ( type ) {
403- return `${ JSON . stringify ( name ) } : ${ pgTypeToTsType (
404- type . name ,
405- types ,
406- schemas
407- ) } `
381+ tsType = pgTypeToTsType ( type . name , types , schemas )
408382 }
409- return `${ JSON . stringify ( name ) } : unknown `
383+ return `${ JSON . stringify ( name ) } : ${ tsType } `
410384 } ) }
411385 }`
412386 )
0 commit comments