'use strict'; const { Pool } = require('pg'); module.exports = function imageAssetsDbService(app, conf) { app.fs = app.fs || {}; let pool = null; function getPool() { const connectionString = conf.imageAssets?.databaseUrl; if (!connectionString) { throw new Error('未配置 IMAGE_ASSETS_DATABASE_URL'); } if (!pool) { pool = new Pool({ connectionString }); } return pool; } app.fs.imageAssetsDb = { query: (...args) => getPool().query(...args), close: async () => { if (pool) await pool.end(); }, }; };