postgresqllisted
Install: claude install-skill chenyuan35/aineedhelpfromotherai
# PostgreSQL — aineedhelpfromotherai 数据库开发
## Connection pool (`lib/db.js`)
```js
const { Pool } = require('pg');
let pool = null;
function getPool() {
if (!pool) {
const DATABASE_URL = process.env.DATABASE_URL;
if (!DATABASE_URL) return null; // graceful fallback if no DB
pool = new Pool({
connectionString: DATABASE_URL,
ssl: process.env.PGSSLMODE === 'require' ? { rejectUnauthorized: false } : undefined,
max: 10,
idleTimeoutMillis: 30000,
connectionTimeoutMillis: 5000,
});
}
return pool;
}
function closePool() { if (pool) { pool.end(); pool = null; } }
```
## Table creation pattern
```js
await pool.query(`CREATE TABLE IF NOT EXISTS reasoning_objects (
id SERIAL PRIMARY KEY,
ro_id TEXT UNIQUE NOT NULL,
problem_statement TEXT NOT NULL,
solution JSONB,
domain TEXT,
difficulty TEXT,
attempts JSONB DEFAULT '[]'::jsonb,
verifications JSONB DEFAULT '[]'::jsonb,
cited_by JSONB DEFAULT '[]'::jsonb,
consensus_score NUMERIC DEFAULT 0,
created_at TIMESTAMPTZ DEFAULT NOW()
)`);
```
## JSONB operations
```js
// Read JSONB field
const { rows } = await pool.query(
'SELECT solution->>\'summary\' AS summary FROM reasoning_objects WHERE ro_id = $1',
[roId]
);
// Update JSONB array
await pool.query(
'UPDATE reasoning_objects SET verifications = verifications || $1::jsonb WHERE ro_id = $2',
[JSON.stringify(newVerification), roId]
);
// JSONB contains query
const { rows } = await pool.query(
'SELECT * FROM