blob: e8ab91e058e69d86c6c94781016308390b76c51c (
plain)
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
|
import pg from 'pg';
import { readFileSync } from 'node:fs';
import { join } from 'node:path';
// 读取 .env 文件
const envPath = join(process.cwd(), '.env');
const envContent = readFileSync(envPath, 'utf-8');
const envLines = envContent.split('\n');
for (const line of envLines) {
const match = line.match(/^([^=]+)=(.*)$/);
if (match) {
const key = match[1]?.trim();
let value = match[2]?.trim() || '';
if ((value.startsWith('"') && value.endsWith('"')) || (value.startsWith("'") && value.endsWith("'"))) {
value = value.slice(1, -1);
}
if (key) {
process.env[key] = value;
}
}
}
const { Pool } = pg;
async function checkUsers() {
const pool = new Pool({
connectionString: process.env.DATABASE_URL,
});
try {
const result = await pool.query('SELECT id, email, name FROM payload.users');
console.log('Payload users:', result.rows);
} catch (error) {
console.error('Error:', error);
} finally {
await pool.end();
}
}
checkUsers();
|