Skip to content

Commit c5cb8d7

Browse files
committed
feat: add methods to retrieve all tables and columns for MySQL connector
1 parent a880838 commit c5cb8d7

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

adminforth/dataConnectors/mysql.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,29 @@ class MysqlConnector extends AdminForthBaseConnector implements IAdminForthDataS
3939
[AdminForthSortDirections.desc]: 'DESC',
4040
};
4141

42+
async getAllTables(): Promise<Array<string>> {
43+
const [rows] = await this.client.query(
44+
`
45+
SELECT table_name
46+
FROM information_schema.tables
47+
WHERE table_schema = DATABASE() AND table_type = 'BASE TABLE';
48+
`
49+
);
50+
return rows.map((row: any) => row.TABLE_NAME);
51+
}
52+
53+
async getAllColumnsInTable(tableName: string): Promise<Array<string>> {
54+
const [rows] = await this.client.query(
55+
`
56+
SELECT column_name
57+
FROM information_schema.columns
58+
WHERE table_name = ? AND table_schema = DATABASE();
59+
`,
60+
[tableName]
61+
);
62+
return rows.map((row: any) => row.COLUMN_NAME);
63+
}
64+
4265
async discoverFields(resource) {
4366
const [results] = await this.client.execute("SHOW COLUMNS FROM " + resource.table);
4467
const fieldTypes = {};

0 commit comments

Comments
 (0)