mirror of
https://github.com/simstudioai/sim.git
synced 2026-09-24 15:45:35 +08:00
Fix row_count context (#3622)
Co-authored-by: Theodore Li <teddy@zenobiapay.com>
This commit is contained in:
co-authored by
Theodore Li
parent
974cc66b0e
commit
2a7b07e3b4
@@ -64,13 +64,28 @@ export async function getTableById(
|
||||
): Promise<TableDefinition | null> {
|
||||
const { includeArchived = false } = options ?? {}
|
||||
const results = await db
|
||||
.select()
|
||||
.select({
|
||||
id: userTableDefinitions.id,
|
||||
name: userTableDefinitions.name,
|
||||
description: userTableDefinitions.description,
|
||||
schema: userTableDefinitions.schema,
|
||||
metadata: userTableDefinitions.metadata,
|
||||
maxRows: userTableDefinitions.maxRows,
|
||||
workspaceId: userTableDefinitions.workspaceId,
|
||||
createdBy: userTableDefinitions.createdBy,
|
||||
archivedAt: userTableDefinitions.archivedAt,
|
||||
createdAt: userTableDefinitions.createdAt,
|
||||
updatedAt: userTableDefinitions.updatedAt,
|
||||
rowCount: sql<number>`coalesce(${count(userTableRows.id)}, 0)`.mapWith(Number),
|
||||
})
|
||||
.from(userTableDefinitions)
|
||||
.leftJoin(userTableRows, eq(userTableRows.tableId, userTableDefinitions.id))
|
||||
.where(
|
||||
includeArchived
|
||||
? eq(userTableDefinitions.id, tableId)
|
||||
: and(eq(userTableDefinitions.id, tableId), isNull(userTableDefinitions.archivedAt))
|
||||
)
|
||||
.groupBy(userTableDefinitions.id)
|
||||
.limit(1)
|
||||
|
||||
if (results.length === 0) return null
|
||||
|
||||
Reference in New Issue
Block a user