Skip to content

Commit 6d6d58c

Browse files
psteinroesoedirgo
andauthored
feat(typegen): add computed cols to row (#354)
* feat(typegen): add computed cols to row * Update 00-init.sql Co-authored-by: Bobbie Soedirgo <[email protected]>
1 parent 9ad6878 commit 6d6d58c

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

src/server/templates/typescript.ts

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,26 @@ export interface Database {
3737
: schemaTables.map(
3838
(table) => `${JSON.stringify(table.name)}: {
3939
Row: {
40-
${table.columns.map(
41-
(column) =>
42-
`${JSON.stringify(column.name)}: ${pgTypeToTsType(
43-
column.format,
44-
types,
45-
schemas
46-
)} ${column.is_nullable ? '| null' : ''}`
47-
)}
40+
${[
41+
...table.columns.map(
42+
(column) =>
43+
`${JSON.stringify(column.name)}: ${pgTypeToTsType(
44+
column.format,
45+
types,
46+
schemas
47+
)} ${column.is_nullable ? '| null' : ''}`
48+
),
49+
...schemaFunctions
50+
.filter((fn) => fn.argument_types === table.name)
51+
.map(
52+
(fn) =>
53+
`${JSON.stringify(fn.name)}: ${pgTypeToTsType(
54+
fn.return_type,
55+
types,
56+
schemas
57+
)}`
58+
),
59+
]}
4860
}
4961
Insert: {
5062
${table.columns.map((column) => {

test/db/00-init.sql

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,8 @@ end;
5151
$$ language plpgsql;
5252

5353
CREATE VIEW todos_view AS SELECT * FROM public.todos;
54+
55+
create function public.blurb(public.todos) returns text as
56+
$$
57+
select substring($1.details, 1, 3);
58+
$$ language sql stable;

0 commit comments

Comments
 (0)