You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
607 B
26 lines
607 B
'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();
|
|
},
|
|
};
|
|
};
|
|
|