pgInit.js 905 B

12345678910111213141516171819202122232425262728293031323334353637
  1. /*
  2. 项目组一般开发成员勿动此文件!
  3. */
  4. const pg = require('pg');
  5. let pgPool = null
  6. /* isOpen */
  7. if (u_config.pgConfig.isOpen) {
  8. pgPool = new pg.Pool(u_config.pgConfig.poolConfig);
  9. //系统启动连接自测
  10. pgPool.connect(function (err, client, release) {
  11. if (err) {
  12. console.log('\x1B[31m', '数据库连接测试失败:' + err.message);
  13. return;
  14. }
  15. client.query('select now();', [], function (err, result) {
  16. release();
  17. if (err) {
  18. console.log('\x1B[31m', '数据库测试查询失败:' + err.message)
  19. } else {
  20. let date = new Date(result.rows[0].now)
  21. console.log('\x1B[32m', `项目数据库(${u_config.pgConfig.poolConfig.database})测试查询成功/测试时间: ` + date)
  22. }
  23. })
  24. });
  25. }
  26. module.exports = pgPool;