🌐 AI搜索 & 代理 主页
Skip to content

Commit 2469a5e

Browse files
committed
Replace psql dependency with native pg client for connection testing
1 parent e1eb334 commit 2469a5e

File tree

3 files changed

+176
-9
lines changed

3 files changed

+176
-9
lines changed

cli/bin/postgres-ai.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -645,13 +645,18 @@ targets
645645

646646
console.log(`Testing connection to monitoring target '${name}'...`);
647647

648-
const { stdout, stderr } = await execFilePromise(
649-
"psql",
650-
[instance.conn_str, "-c", "SELECT version();", "--no-psqlrc"],
651-
{ timeout: 10000, env: { ...process.env, PAGER: 'cat' } }
652-
);
653-
console.log(`✓ Connection successful`);
654-
console.log(stdout.trim());
648+
// Use native pg client instead of requiring psql to be installed
649+
const { Client } = require('pg');
650+
const client = new Client({ connectionString: instance.conn_str });
651+
652+
try {
653+
await client.connect();
654+
const result = await client.query('select version();');
655+
console.log(`✓ Connection successful`);
656+
console.log(result.rows[0].version);
657+
} finally {
658+
await client.end();
659+
}
655660
} catch (error) {
656661
const message = error instanceof Error ? error.message : String(error);
657662
console.error(`✗ Connection failed: ${message}`);

cli/package-lock.json

Lines changed: 161 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cli/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,15 @@
2828
"dev": "tsc --watch"
2929
},
3030
"dependencies": {
31+
"@modelcontextprotocol/sdk": "^1.20.2",
3132
"commander": "^12.1.0",
3233
"js-yaml": "^4.1.0",
33-
"@modelcontextprotocol/sdk": "^1.20.2"
34+
"pg": "^8.16.3"
3435
},
3536
"devDependencies": {
3637
"@types/js-yaml": "^4.0.9",
3738
"@types/node": "^18.19.0",
39+
"@types/pg": "^8.15.6",
3840
"typescript": "^5.3.3"
3941
},
4042
"publishConfig": {

0 commit comments

Comments
 (0)