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

Function listTables

apps/sim/lib/table/service.ts:172–229  ·  view source on GitHub ↗
(
  workspaceId: string,
  options?: { scope?: TableScope }
)

Source from the content-addressed store, hash-verified

170 * @returns Array of table definitions
171 */
172export async function listTables(
173 workspaceId: string,
174 options?: { scope?: TableScope }
175): Promise<TableDefinition[]> {
176 const { scope = 'active' } = options ?? {}
177 const tables = await db
178 .select({
179 id: userTableDefinitions.id,
180 name: userTableDefinitions.name,
181 description: userTableDefinitions.description,
182 schema: userTableDefinitions.schema,
183 metadata: userTableDefinitions.metadata,
184 maxRows: userTableDefinitions.maxRows,
185 workspaceId: userTableDefinitions.workspaceId,
186 createdBy: userTableDefinitions.createdBy,
187 archivedAt: userTableDefinitions.archivedAt,
188 createdAt: userTableDefinitions.createdAt,
189 updatedAt: userTableDefinitions.updatedAt,
190 rowCount: userTableDefinitions.rowCount,
191 })
192 .from(userTableDefinitions)
193 .where(
194 scope === 'all'
195 ? eq(userTableDefinitions.workspaceId, workspaceId)
196 : scope === 'archived'
197 ? and(
198 eq(userTableDefinitions.workspaceId, workspaceId),
199 sql`${userTableDefinitions.archivedAt} IS NOT NULL`
200 )
201 : and(
202 eq(userTableDefinitions.workspaceId, workspaceId),
203 isNull(userTableDefinitions.archivedAt)
204 )
205 )
206 .orderBy(userTableDefinitions.createdAt)
207
208 const jobsByTable = await latestJobsForTables(tables.map((t) => t.id))
209
210 return tables.map((t) => {
211 const metadata = (t.metadata as TableMetadata) ?? null
212 const { pendingDeleteRemaining, ...jobFields } = jobsByTable.get(t.id) ?? EMPTY_JOB_FIELDS
213 return {
214 id: t.id,
215 name: t.name,
216 description: t.description,
217 schema: applyColumnOrderToSchema(t.schema as TableSchema, metadata),
218 metadata,
219 rowCount: Math.max(0, t.rowCount - pendingDeleteRemaining),
220 maxRows: t.maxRows,
221 workspaceId: t.workspaceId,
222 createdBy: t.createdBy,
223 archivedAt: t.archivedAt,
224 createdAt: t.createdAt,
225 updatedAt: t.updatedAt,
226 ...jobFields,
227 }
228 })
229}

Callers 6

resolveInputFilesFunction · 0.90
materializeTablesMethod · 0.90
route.tsFile · 0.90
route.tsFile · 0.90
route.tsFile · 0.90

Calls 4

latestJobsForTablesFunction · 0.90
applyColumnOrderToSchemaFunction · 0.85
getMethod · 0.65
eqFunction · 0.50

Tested by

no test coverage detected