mirror of
https://github.com/Mintplex-Labs/anything-llm
synced 2026-04-27 09:57:18 +02:00
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:
@@ -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'`;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user