forked from 14790897/auto-read-liunxdo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug_db.js
More file actions
55 lines (47 loc) · 1.63 KB
/
debug_db.js
File metadata and controls
55 lines (47 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import { Pool } from 'pg';
import fs from 'fs';
import dotenv from 'dotenv';
dotenv.config();
if (fs.existsSync(".env.local")) {
console.log("Using .env.local file to supply config environment variables");
const envConfig = dotenv.parse(fs.readFileSync(".env.local"));
for (const k in envConfig) {
process.env[k] = envConfig[k];
}
}
const pool = new Pool({
connectionString: process.env.POSTGRES_URI,
max: 5,
idleTimeoutMillis: 30000,
connectionTimeoutMillis: 2000,
ssl: { rejectUnauthorized: false }
});
async function debugDatabase() {
try {
// 检查最近的一些posts
const res = await pool.query('SELECT guid, title, created_at FROM posts ORDER BY created_at DESC LIMIT 10');
console.log('Recent posts in database:');
res.rows.forEach(row => {
console.log(`GUID: ${row.guid}, Title: ${row.title.substring(0, 50)}..., Created: ${row.created_at}`);
});
// 检查特定GUID是否存在
const testGuids = [
'https://linux.do/t/topic/298776',
'https://linux.do/t/topic/298777',
'https://linux.do/t/topic/298778'
];
console.log('\nChecking specific GUIDs:');
for (const guid of testGuids) {
const check = await pool.query('SELECT COUNT(*) FROM posts WHERE guid = $1', [guid]);
console.log(`GUID ${guid}: exists = ${check.rows[0].count > 0}`);
}
// 查看总记录数
const countRes = await pool.query('SELECT COUNT(*) FROM posts');
console.log(`\nTotal posts in database: ${countRes.rows[0].count}`);
} catch (error) {
console.error('Database error:', error);
} finally {
await pool.end();
}
}
debugDatabase();