MCPcopy Index your code
hub / github.com/outerbase/studio / tableSchema

Method tableSchema

src/drivers/sqlite-base-driver.ts:234–266  ·  view source on GitHub ↗
(
    schemaName: string,
    tableName: string
  )

Source from the content-addressed store, hash-verified

232 }
233
234 async tableSchema(
235 schemaName: string,
236 tableName: string
237 ): Promise<DatabaseTableSchema> {
238 const sql = `SELECT * FROM ${this.escapeId(schemaName)}.sqlite_schema WHERE tbl_name = ${escapeSqlValue(
239 tableName
240 )};`;
241 const result = await this.query(sql);
242
243 try {
244 try {
245 const rows = result.rows as Array<{ type: string; sql: string }>;
246 const def = rows.find((row) => row.type === "table");
247
248 if (def) {
249 const createScript = def.sql;
250
251 return {
252 ...parseCreateTableScript(schemaName, createScript),
253 createScript,
254 schemaName,
255 type: "table",
256 };
257 }
258
259 throw new Error("Unexpected error finding table " + tableName);
260 } catch (e) {
261 throw new Error("Unexpected error while parsing");
262 }
263 } catch {
264 return await this.legacyTableSchema(schemaName, tableName);
265 }
266 }
267
268 createUpdateTableSchema(change: DatabaseTableSchemaChange): string[] {
269 return generateSqlSchemaChange(change);

Callers 1

selectTableMethod · 0.95

Calls 5

escapeIdMethod · 0.95
queryMethod · 0.95
legacyTableSchemaMethod · 0.95
escapeSqlValueFunction · 0.90
parseCreateTableScriptFunction · 0.90

Tested by

no test coverage detected