MCPcopy Index your code
hub / github.com/simstudioai/sim / getTableById

Function getTableById

apps/sim/lib/table/service.ts:115–164  ·  view source on GitHub ↗
(
  tableId: string,
  options?: { includeArchived?: boolean; tx?: DbOrTx }
)

Source from the content-addressed store, hash-verified

113 * @returns Table definition or null if not found
114 */
115export async function getTableById(
116 tableId: string,
117 options?: { includeArchived?: boolean; tx?: DbOrTx }
118): Promise<TableDefinition | null> {
119 const { includeArchived = false, tx } = options ?? {}
120 const executor = tx ?? db
121 const results = await executor
122 .select({
123 id: userTableDefinitions.id,
124 name: userTableDefinitions.name,
125 description: userTableDefinitions.description,
126 schema: userTableDefinitions.schema,
127 metadata: userTableDefinitions.metadata,
128 maxRows: userTableDefinitions.maxRows,
129 workspaceId: userTableDefinitions.workspaceId,
130 createdBy: userTableDefinitions.createdBy,
131 archivedAt: userTableDefinitions.archivedAt,
132 createdAt: userTableDefinitions.createdAt,
133 updatedAt: userTableDefinitions.updatedAt,
134 rowCount: userTableDefinitions.rowCount,
135 })
136 .from(userTableDefinitions)
137 .where(
138 includeArchived
139 ? eq(userTableDefinitions.id, tableId)
140 : and(eq(userTableDefinitions.id, tableId), isNull(userTableDefinitions.archivedAt))
141 )
142 .limit(1)
143
144 if (results.length === 0) return null
145
146 const table = results[0]
147 const metadata = (table.metadata as TableMetadata) ?? null
148 const { pendingDeleteRemaining, ...jobFields } = await latestJobForTable(tableId, executor)
149 return {
150 id: table.id,
151 name: table.name,
152 description: table.description,
153 schema: applyColumnOrderToSchema(table.schema as TableSchema, metadata),
154 metadata,
155 rowCount: Math.max(0, table.rowCount - pendingDeleteRemaining),
156 maxRows: table.maxRows,
157 workspaceId: table.workspaceId,
158 createdBy: table.createdBy,
159 archivedAt: table.archivedAt,
160 createdAt: table.createdAt,
161 updatedAt: table.updatedAt,
162 ...jobFields,
163 }
164}
165
166/**
167 * Lists all tables in a workspace.

Callers 15

performRestoreResourceFunction · 0.90
resolveTableRefFunction · 0.90
resolveResourceFunction · 0.90
executeFunction · 0.90
maybeWriteOutputToTableFunction · 0.90
maybeWriteReadCsvToTableFunction · 0.90
resolveTableResourceFunction · 0.90
runTableImportFunction · 0.90
runTableUpdateFunction · 0.90
runTableExportFunction · 0.90
runTableBackfillFunction · 0.90
runTableDeleteFunction · 0.90

Calls 3

latestJobForTableFunction · 0.90
applyColumnOrderToSchemaFunction · 0.85
eqFunction · 0.50

Tested by

no test coverage detected