MCPcopy Create free account
hub / github.com/bytebase/dbhub / getViews

Method getViews

src/connectors/mysql/index.ts:221–246  ·  view source on GitHub ↗
(schema?: string)

Source from the content-addressed store, hash-verified

219 }
220
221 async getViews(schema?: string): Promise<string[]> {
222 if (!this.pool) {
223 throw new Error("Not connected to database");
224 }
225
226 try {
227 const schemaClause = schema ? "WHERE TABLE_SCHEMA = ?" : "WHERE TABLE_SCHEMA = DATABASE()";
228 const queryParams = schema ? [schema] : [];
229
230 const [rows] = (await this.pool.query(
231 `
232 SELECT TABLE_NAME
233 FROM INFORMATION_SCHEMA.TABLES
234 ${schemaClause}
235 AND TABLE_TYPE = 'VIEW'
236 ORDER BY TABLE_NAME
237 `,
238 queryParams
239 )) as [any[], any];
240
241 return rows.map((row) => row.TABLE_NAME);
242 } catch (error) {
243 console.error("Error getting views:", error);
244 throw error;
245 }
246 }
247
248 async tableExists(tableName: string, schema?: string): Promise<boolean> {
249 if (!this.pool) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected