Skip to content
This repository was archived by the owner on Aug 19, 2025. It is now read-only.

Commit e717878

Browse files
filter out join tables from hook generation
1 parent 49ac82c commit e717878

2 files changed

Lines changed: 23 additions & 4 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@backengine/codegen",
3-
"version": "1.0.11",
3+
"version": "1.0.12",
44
"description": "Generate code for Backengine projects.",
55
"bin": "build/index.js",
66
"files": [

src/hooks/table.ts

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,31 @@ const parseTableNames = (types: File): string[] => {
1111
);
1212

1313
const node = sourceFile.getInterface("Database")!;
14+
1415
const tables = node.getProperty("public")!.getType().getProperty("Tables")!;
1516

16-
return tables
17+
const tableNames = tables
1718
.getTypeAtLocation(node)
1819
.getProperties()
1920
.map((property) => property.getName());
21+
22+
const tableIdTypes = tables
23+
.getTypeAtLocation(node)
24+
.getProperties()
25+
.map((property) => {
26+
const id = property
27+
.getTypeAtLocation(node)
28+
.getProperty("Row")!
29+
.getTypeAtLocation(node)
30+
.getProperty("id")!;
31+
if (!id) {
32+
return null;
33+
}
34+
return id.getTypeAtLocation(node).getText();
35+
});
36+
37+
// filter tables with no "id" column
38+
return tableNames.filter((_, index) => tableIdTypes.at(index) !== null);
2039
};
2140

2241
const mapTableToFile = async (tableName: string): Promise<HookFile> => {
@@ -71,7 +90,7 @@ const mapTableToFile = async (tableName: string): Promise<HookFile> => {
7190
}
7291
};
7392
74-
const update${pascalCase} = async (id: number, updatedData: Update${pascalCase}) => {
93+
const update${pascalCase} = async (id: ${pascalCase}["id"], updatedData: Update${pascalCase}) => {
7594
try {
7695
const { data, error } = await supabase
7796
.from("${tableName}")
@@ -91,7 +110,7 @@ const mapTableToFile = async (tableName: string): Promise<HookFile> => {
91110
}
92111
};
93112
94-
const delete${pascalCase} = async (id: number) => {
113+
const delete${pascalCase} = async (id: ${pascalCase}["id"]) => {
95114
try {
96115
const { error } = await supabase
97116
.from("${tableName}")

0 commit comments

Comments
 (0)