MCPcopy Create free account
hub / github.com/outerbase/studio / legacyTableSchema

Method legacyTableSchema

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

Source from the content-addressed store, hash-verified

136 }
137
138 protected async legacyTableSchema(
139 schemaName: string,
140 tableName: string
141 ): Promise<DatabaseTableSchema> {
142 const sql = `SELECT * FROM ${this.escapeId(schemaName)}.pragma_table_info(${this.escapeValue(tableName)});`;
143 const result = await this.query(sql);
144
145 const rows = result.rows as Array<{
146 name: string;
147 type: string;
148 pk: number;
149 }>;
150
151 const columns: DatabaseTableColumn[] = rows.map((row) => ({
152 name: row.name,
153 type: row.type,
154 pk: !!row.pk,
155 }));
156
157 // Check auto increment
158 let hasAutoIncrement = false;
159
160 try {
161 const seqCount = await this.query(
162 `SELECT COUNT(*) AS total FROM ${this.escapeId(schemaName)}.sqlite_sequence WHERE name=${escapeSqlValue(
163 tableName
164 )};`
165 );
166
167 const seqRow = seqCount.rows[0];
168 if (seqRow && Number(seqRow[0] ?? 0) > 0) {
169 hasAutoIncrement = true;
170 }
171 } catch (e) {
172 console.error(e);
173 }
174
175 return {
176 columns,
177 schemaName,
178 pk: columns.filter((col) => col.pk).map((col) => col.name),
179 autoIncrement: hasAutoIncrement,
180 };
181 }
182
183 async schemas(): Promise<DatabaseSchemas> {
184 let databaseList = [{ name: "main" }];

Callers 1

tableSchemaMethod · 0.95

Calls 4

escapeIdMethod · 0.95
escapeValueMethod · 0.95
queryMethod · 0.95
escapeSqlValueFunction · 0.90

Tested by

no test coverage detected