SQL preflight connection validation (#4150)

* wip sql connection string validation

* handle failed sql connections in frontend

* sql preflight connection validation on modal save

* revert unneeded be/fe changes

* linting, form updates

---------

Co-authored-by: timothycarambat <rambat1010@gmail.com>
This commit is contained in:
Sean Hatfield
2025-07-16 09:02:39 -07:00
committed by GitHub
parent 9bd77b0c2d
commit 49ea545d7f
9 changed files with 185 additions and 36 deletions

View File

@@ -22,7 +22,7 @@ class PostgresSQLConnector {
/**
*
* @param {string} queryString the SQL query to be run
* @returns {import(".").QueryResult}
* @returns {Promise<import(".").QueryResult>}
*/
async runQuery(queryString = "") {
const result = { rows: [], count: 0, error: null };
@@ -35,12 +35,24 @@ class PostgresSQLConnector {
console.log(this.constructor.name, err);
result.error = err.message;
} finally {
await this._client.end();
this.#connected = false;
// Check client is connected before closing since we use this for validation
if (this._client) {
await this._client.end();
this.#connected = false;
}
}
return result;
}
async validateConnection() {
try {
const result = await this.runQuery("SELECT 1");
return { success: !result.error, error: result.error };
} catch (error) {
return { success: false, error: error.message };
}
}
getTablesSql() {
return `SELECT * FROM pg_catalog.pg_tables WHERE schemaname = 'public'`;
}