@@ -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
2241const 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