Skip to content

Commit 33a2413

Browse files
committed
feat: add methods to retrieve all tables and columns for Clickhouse connector
1 parent c5cb8d7 commit 33a2413

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

adminforth/dataConnectors/clickhouse.ts

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,36 @@ class ClickhouseConnector extends AdminForthBaseConnector implements IAdminForth
3030
// }
3131
});
3232
}
33-
33+
async getAllTables(): Promise<Array<string>> {
34+
const res = await this.client.query({
35+
query: `
36+
SELECT name
37+
FROM system.tables
38+
WHERE database = '${this.dbName}'
39+
`,
40+
format: 'JSON',
41+
});
42+
const jsonResult = await res.json();
43+
return jsonResult.data.map((row: any) => row.name);
44+
}
45+
46+
async getAllColumnsInTable(tableName: string): Promise<string[]> {
47+
const res = await this.client.query({
48+
query: `
49+
SELECT name
50+
FROM system.columns
51+
WHERE database = '${this.dbName}' AND table = {table:String}
52+
`,
53+
format: 'JSON',
54+
query_params: {
55+
table: tableName,
56+
},
57+
});
58+
59+
const jsonResult = await res.json();
60+
return jsonResult.data.map((row: any) => row.name);
61+
}
62+
3463
async discoverFields(resource: AdminForthResource): Promise<{[key: string]: AdminForthResourceColumn}> {
3564
const tableName = resource.table;
3665

0 commit comments

Comments
 (0)