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

Function buildTable

apps/sim/app/api/table/import-csv/route.ts:127–149  ·  view source on GitHub ↗
(sampleRows: Record<string, unknown>[])

Source from the content-addressed store, hash-verified

125
126 /** Infer the schema from the buffered sample and create the (empty) table. */
127 const buildTable = async (sampleRows: Record<string, unknown>[]): Promise<ImportState> => {
128 const inferred = inferSchemaFromCsv(Object.keys(sampleRows[0]), sampleRows)
129 const schema: TableSchema = { columns: inferred.columns.map(normalizeColumn) }
130 const planLimits = await getWorkspaceTableLimits(workspaceId)
131 const tableName = sanitizeName(file.filename.replace(/\.[^.]+$/, ''), 'imported_table').slice(
132 0,
133 TABLE_LIMITS.MAX_TABLE_NAME_LENGTH
134 )
135 const table = await createTable(
136 {
137 name: tableName,
138 description: `Imported from ${file.filename}`,
139 schema,
140 workspaceId,
141 userId,
142 maxTables: planLimits.maxTables,
143 },
144 requestId
145 )
146 // Coerce against the *created* schema so rows key by the ids `createTable`
147 // assigned (the local `schema` is the id-less inferred one).
148 return { table, schema: table.schema, headerToColumn: inferred.headerToColumn }
149 }
150
151 let state: ImportState | null = null
152 let inserted = 0

Callers 1

route.tsFile · 0.70

Calls 5

inferSchemaFromCsvFunction · 0.90
getWorkspaceTableLimitsFunction · 0.90
sanitizeNameFunction · 0.90
createTableFunction · 0.90
replaceMethod · 0.65

Tested by

no test coverage detected