Postgres 查询不在 Node.js 上执行

时间:2021-01-16 20:28:41

标签: javascript node.js database postgresql

我遇到了一个问题。 Postgres 代码(查询)根本不执行。不得不提一下,与DB的连接是正确完成的。

我试过调试代码,但我真的不知道问题出在哪里

'use strict';

const config = require('../config');
const emailService = require('./email-service');
const pg = require('pg');
pg.defaults.ssl = true;


 module.exports = function(phone_number, user_name, previous_job, years_of_experience, job_vacancy){
    console.log('sending email');
    let emailContent = 'A new job inquiry from ' + user_name + ' for the job: ' + job_vacancy +
        '.<br> Previous job position: ' + previous_job + '.' +
        '.<br> Years of experience: ' + years_of_experience + '.' +
        '.<br> Phone number: ' + phone_number + '.';

    emailService.sendEmail('New job application', emailContent);
    try{
    var pool = new pg.Pool(config.PG_CONFIG);
    pool.connect(function(err, client, done) {
        if (err) {
            return console.error('Error acquiring client', err.stack);
        }
        client
            .query(
                'INSERT into job_applications ' +
                '(phone_number, user_name, previous_job, years_of_experience, job_vacancy) ' +
                'VALUES($1, $2, $3, $4, $5) RETURNING id',
                [phone_number, user_name, previous_job, years_of_experience, job_vacancy],
                function(err, result) {
                    if (err) {
                        console.log(err);
                    } else {
                        console.log('row inserted with id: ' + result.rows[0].id);
                    }

                });
    });
}
catch(e){
    console.log(e, 'error[][][]')
}
    pool.end();
} ```

0 个答案:

没有答案