(connection: Connection, databaseName: string)
| 85 | }; |
| 86 | |
| 87 | const getTableSchema = async (connection: Connection, databaseName: string): Promise<Schema[]> => { |
| 88 | const conn = await getMySQLConnection(connection); |
| 89 | // get All tableList from database |
| 90 | const [rows] = await conn.query<RowDataPacket[]>( |
| 91 | // SYSTEM VERSIONED is a special table for MariaDB https://mariadb.com/kb/en/system-versioned-tables/ |
| 92 | `SELECT TABLE_NAME as table_name FROM information_schema.tables WHERE TABLE_SCHEMA=? AND (TABLE_TYPE='BASE TABLE' || TABLE_TYPE='SYSTEM VERSIONED');`, |
| 93 | [databaseName] |
| 94 | ); |
| 95 | const tableList = []; |
| 96 | for (const row of rows) { |
| 97 | if (row["table_name"]) { |
| 98 | tableList.push(row["table_name"]); |
| 99 | } |
| 100 | } |
| 101 | const SchemaList: Schema[] = [{ name: "", tables: [] as Table[] }]; |
| 102 | |
| 103 | for (const tableName of tableList) { |
| 104 | const [rows] = await conn.query<RowDataPacket[]>(`SHOW CREATE TABLE \`${databaseName}\`.\`${tableName}\`;`); |
| 105 | if (rows.length !== 1) { |
| 106 | throw new Error("Unexpected number of rows."); |
| 107 | } |
| 108 | |
| 109 | SchemaList[0].tables.push({ name: tableName, structure: rows[0]["Create Table"] || "" }); |
| 110 | } |
| 111 | return SchemaList; |
| 112 | }; |
| 113 | |
| 114 | const newConnector = (connection: Connection): Connector => { |
| 115 | return { |
no test coverage detected