File tree Expand file tree Collapse file tree 3 files changed +44
-8
lines changed
Expand file tree Collapse file tree 3 files changed +44
-8
lines changed Original file line number Diff line number Diff line change @@ -99,14 +99,14 @@ export interface Database {
9999 ) ,
100100 ...schemaFunctions
101101 . filter ( ( fn ) => fn . argument_types === table . name )
102- . map (
103- ( fn ) =>
104- ` ${ JSON . stringify ( fn . name ) } : ${ pgTypeToTsType (
105- fn . return_type ,
106- types ,
107- schemas
108- ) } | null`
109- ) ,
102+ . map ( ( fn ) => {
103+ const type = types . find ( ( { id } ) => id === fn . return_type_id )
104+ let tsType = 'unknown'
105+ if ( type ) {
106+ tsType = pgTypeToTsType ( type . name , types , schemas )
107+ }
108+ return ` ${ JSON . stringify ( fn . name ) } : ${ tsType } | null`
109+ } ) ,
110110 ] }
111111 }
112112 Insert: {
Original file line number Diff line number Diff line change 6161select substring ($1 .details, 1 , 3 );
6262$$ language sql stable;
6363
64+ create function public .blurb_varchar(public .todos ) returns character varying as
65+ $$
66+ select substring ($1 .details, 1 , 3 );
67+ $$ language sql stable;
68+
69+ create function public .details_length(public .todos ) returns integer as
70+ $$
71+ select length($1 .details);
72+ $$ language sql stable;
73+
74+ create function public .details_is_long(public .todos ) returns boolean as
75+ $$
76+ select $1 .details_length > 20 ;
77+ $$ language sql stable;
78+
6479create extension postgres_fdw;
6580create server foreign_server foreign data wrapper postgres_fdw options (host ' localhost' , port ' 5432' , dbname ' postgres' );
6681create user mapping for postgres server foreign_server options (user ' postgres' , password ' postgres' );
Original file line number Diff line number Diff line change @@ -72,6 +72,9 @@ test('typegen', async () => {
7272 id: number
7373 "user-id": number
7474 blurb: string | null
75+ blurb_varchar: string | null
76+ details_is_long: boolean | null
77+ details_length: number | null
7578 }
7679 Insert: {
7780 details?: string | null
@@ -217,6 +220,24 @@ test('typegen', async () => {
217220 }
218221 Returns: string
219222 }
223+ blurb_varchar: {
224+ Args: {
225+ "": unknown
226+ }
227+ Returns: string
228+ }
229+ details_is_long: {
230+ Args: {
231+ "": unknown
232+ }
233+ Returns: boolean
234+ }
235+ details_length: {
236+ Args: {
237+ "": unknown
238+ }
239+ Returns: number
240+ }
220241 function_returning_row: {
221242 Args: Record<PropertyKey, never>
222243 Returns: {
You can’t perform that action at this time.
0 commit comments