@@ -64,13 +64,28 @@ export async function getTableById(
6464) : Promise < TableDefinition | null > {
6565 const { includeArchived = false } = options ?? { }
6666 const results = await db
67- . select ( )
67+ . select ( {
68+ id : userTableDefinitions . id ,
69+ name : userTableDefinitions . name ,
70+ description : userTableDefinitions . description ,
71+ schema : userTableDefinitions . schema ,
72+ metadata : userTableDefinitions . metadata ,
73+ maxRows : userTableDefinitions . maxRows ,
74+ workspaceId : userTableDefinitions . workspaceId ,
75+ createdBy : userTableDefinitions . createdBy ,
76+ archivedAt : userTableDefinitions . archivedAt ,
77+ createdAt : userTableDefinitions . createdAt ,
78+ updatedAt : userTableDefinitions . updatedAt ,
79+ rowCount : sql < number > `coalesce(${ count ( userTableRows . id ) } , 0)` . mapWith ( Number ) ,
80+ } )
6881 . from ( userTableDefinitions )
82+ . leftJoin ( userTableRows , eq ( userTableRows . tableId , userTableDefinitions . id ) )
6983 . where (
7084 includeArchived
7185 ? eq ( userTableDefinitions . id , tableId )
7286 : and ( eq ( userTableDefinitions . id , tableId ) , isNull ( userTableDefinitions . archivedAt ) )
7387 )
88+ . groupBy ( userTableDefinitions . id )
7489 . limit ( 1 )
7590
7691 if ( results . length === 0 ) return null
0 commit comments