0
点赞
收藏
分享

微信扫一扫

Windows 系统使用Jenkins 实现CI一键打包部署操作

双井暮色 2024-05-07 阅读 35
  • pgsql.js
const { Client } = require('pg');
const config = {
    host: "127.0.0.1",
    database: "postgres",
    user: "postgres",
    password: "postgres",
    port: 5432, // 默认的PostgreSQL端口号
}

const pg = require("pg");
const pool = new pg.Pool({
    host: "127.0.0.1",
    database: "postgres",
    user: "postgres",
    password: "postgres",
    port: 5432,
    max: 20,
    idleTimeoutMillis: 3000
})

//新建连接的方法
function qurey_files(req, res) {
    var strSql = 
    "select name, path, suffix, status, \
    to_char(upload_date_time,'yyyy-mm-dd_HH24:MI:ss') as time \
    from public.\"Test\" \
    ORDER BY key ASC";
    let client = new Client(config);
    client.connect();
    client.query(strSql, (err, result) => {
        if (err) {
            res.status(404).send(err.message);
            console.log(err);
        }
        else {
            res.send(result.rows);
        }
        client.end();
    })
}

//使用线程池的方法
function qurey_files_pool(req, res) {
    var strSql = 
    "select name, path, suffix, status, \
    to_char(upload_date_time,'yyyy-mm-dd_HH24:MI:ss') as time \
    from public.\"Test\" \
    ORDER BY key ASC";
    pool.connect((err, client, done)=>{
        // if (err) throw err;
        client.query(strSql, (err, result)=>{
            done();
            res.send(result.rows);
        })
    })
}

module.exports = {
    qurey_files,
    qurey_files_pool
}
  • server.js
const db = require('./server/pgsql')
db.qurey_files_pool(req, res)
举报

相关推荐

0 条评论