Express Postgres Unhandled Promise Rejection Warning











up vote
0
down vote

favorite












I am learning Node JS with express and postgres and while I was making a CRUD app I got error like this when I execute my INSERT INTO statement.



(node:4998) UnhandledPromiseRejectionWarning: TypeError: Invalid Query Result Mask specified.
at Database.$query (/home/aabishkar/Documents/meanstack/node_modules/pg-promise/lib/query.js:121:25)
at Database.<anonymous> (/home/aabishkar/Documents/meanstack/node_modules/pg-promise/lib/query.js:259:23)
at config.$npm.connect.pool.then.db (/home/aabishkar/Documents/meanstack/node_modules/pg-promise/lib/database.js:326:42)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7) (node:4998) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 3) (node:4998) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.


My code looks like this:



exports.dynamicadd =  function(req, res) {
var name = req.body.name;
var dob = req.body.dob;
var gender = req.body.gender;
var values = [name, gender, dob];
console.log(values); //Up to here code is fine. It returns the value.
//from here the error comes
var sql = "INSERT INTO students (name, gender, dob) VALUES ?";
db.query(sql, [values], function (err, result) {
if (err) throw err;
console.log("Number of records inserted: " + result.affectedRows);
});
res.redirect('/');
}


The DB is connected. Also for reference the following code works fine. The error comes when i try to insert the values dynamically.



//this codes works finely
exports.addlist = function(req, res) {
qry = "INSERT INTO students (name, gender, dob) VALUES ('sdasda', 'male', '12-12-1999')";
db.query(qry, function (err, result) {
if (err) throw err;
console.log("Number of records inserted: " + result.affectedRows);
});
res.redirect('/');
}


Thanks.










share|improve this question




















  • 1




    Are you sure that ? placeholders are valid for pg-promise? See this answer.
    – robertklep
    Nov 11 at 15:41

















up vote
0
down vote

favorite












I am learning Node JS with express and postgres and while I was making a CRUD app I got error like this when I execute my INSERT INTO statement.



(node:4998) UnhandledPromiseRejectionWarning: TypeError: Invalid Query Result Mask specified.
at Database.$query (/home/aabishkar/Documents/meanstack/node_modules/pg-promise/lib/query.js:121:25)
at Database.<anonymous> (/home/aabishkar/Documents/meanstack/node_modules/pg-promise/lib/query.js:259:23)
at config.$npm.connect.pool.then.db (/home/aabishkar/Documents/meanstack/node_modules/pg-promise/lib/database.js:326:42)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7) (node:4998) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 3) (node:4998) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.


My code looks like this:



exports.dynamicadd =  function(req, res) {
var name = req.body.name;
var dob = req.body.dob;
var gender = req.body.gender;
var values = [name, gender, dob];
console.log(values); //Up to here code is fine. It returns the value.
//from here the error comes
var sql = "INSERT INTO students (name, gender, dob) VALUES ?";
db.query(sql, [values], function (err, result) {
if (err) throw err;
console.log("Number of records inserted: " + result.affectedRows);
});
res.redirect('/');
}


The DB is connected. Also for reference the following code works fine. The error comes when i try to insert the values dynamically.



//this codes works finely
exports.addlist = function(req, res) {
qry = "INSERT INTO students (name, gender, dob) VALUES ('sdasda', 'male', '12-12-1999')";
db.query(qry, function (err, result) {
if (err) throw err;
console.log("Number of records inserted: " + result.affectedRows);
});
res.redirect('/');
}


Thanks.










share|improve this question




















  • 1




    Are you sure that ? placeholders are valid for pg-promise? See this answer.
    – robertklep
    Nov 11 at 15:41















up vote
0
down vote

favorite









up vote
0
down vote

favorite











I am learning Node JS with express and postgres and while I was making a CRUD app I got error like this when I execute my INSERT INTO statement.



(node:4998) UnhandledPromiseRejectionWarning: TypeError: Invalid Query Result Mask specified.
at Database.$query (/home/aabishkar/Documents/meanstack/node_modules/pg-promise/lib/query.js:121:25)
at Database.<anonymous> (/home/aabishkar/Documents/meanstack/node_modules/pg-promise/lib/query.js:259:23)
at config.$npm.connect.pool.then.db (/home/aabishkar/Documents/meanstack/node_modules/pg-promise/lib/database.js:326:42)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7) (node:4998) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 3) (node:4998) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.


My code looks like this:



exports.dynamicadd =  function(req, res) {
var name = req.body.name;
var dob = req.body.dob;
var gender = req.body.gender;
var values = [name, gender, dob];
console.log(values); //Up to here code is fine. It returns the value.
//from here the error comes
var sql = "INSERT INTO students (name, gender, dob) VALUES ?";
db.query(sql, [values], function (err, result) {
if (err) throw err;
console.log("Number of records inserted: " + result.affectedRows);
});
res.redirect('/');
}


The DB is connected. Also for reference the following code works fine. The error comes when i try to insert the values dynamically.



//this codes works finely
exports.addlist = function(req, res) {
qry = "INSERT INTO students (name, gender, dob) VALUES ('sdasda', 'male', '12-12-1999')";
db.query(qry, function (err, result) {
if (err) throw err;
console.log("Number of records inserted: " + result.affectedRows);
});
res.redirect('/');
}


Thanks.










share|improve this question















I am learning Node JS with express and postgres and while I was making a CRUD app I got error like this when I execute my INSERT INTO statement.



(node:4998) UnhandledPromiseRejectionWarning: TypeError: Invalid Query Result Mask specified.
at Database.$query (/home/aabishkar/Documents/meanstack/node_modules/pg-promise/lib/query.js:121:25)
at Database.<anonymous> (/home/aabishkar/Documents/meanstack/node_modules/pg-promise/lib/query.js:259:23)
at config.$npm.connect.pool.then.db (/home/aabishkar/Documents/meanstack/node_modules/pg-promise/lib/database.js:326:42)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7) (node:4998) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 3) (node:4998) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.


My code looks like this:



exports.dynamicadd =  function(req, res) {
var name = req.body.name;
var dob = req.body.dob;
var gender = req.body.gender;
var values = [name, gender, dob];
console.log(values); //Up to here code is fine. It returns the value.
//from here the error comes
var sql = "INSERT INTO students (name, gender, dob) VALUES ?";
db.query(sql, [values], function (err, result) {
if (err) throw err;
console.log("Number of records inserted: " + result.affectedRows);
});
res.redirect('/');
}


The DB is connected. Also for reference the following code works fine. The error comes when i try to insert the values dynamically.



//this codes works finely
exports.addlist = function(req, res) {
qry = "INSERT INTO students (name, gender, dob) VALUES ('sdasda', 'male', '12-12-1999')";
db.query(qry, function (err, result) {
if (err) throw err;
console.log("Number of records inserted: " + result.affectedRows);
});
res.redirect('/');
}


Thanks.







javascript node.js postgresql express






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 11 at 15:41









alexmac

12.4k62650




12.4k62650










asked Nov 11 at 15:34









Aabishkar Wagle

12




12








  • 1




    Are you sure that ? placeholders are valid for pg-promise? See this answer.
    – robertklep
    Nov 11 at 15:41
















  • 1




    Are you sure that ? placeholders are valid for pg-promise? See this answer.
    – robertklep
    Nov 11 at 15:41










1




1




Are you sure that ? placeholders are valid for pg-promise? See this answer.
– robertklep
Nov 11 at 15:41






Are you sure that ? placeholders are valid for pg-promise? See this answer.
– robertklep
Nov 11 at 15:41














1 Answer
1






active

oldest

votes

















up vote
1
down vote













pg-promise returns a promise, it doesn't take a callback. You are using the library incorrectly. When values are the second parameter, then the third parameter is not supposed to be a callback, it is supposed to be a QueryResultMask



You should be using it is:



db.query(...)
.then(r => console.log(r))
.catch(e => console.log(e))


Check out this simple insert example






share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53250276%2fexpress-postgres-unhandled-promise-rejection-warning%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    1
    down vote













    pg-promise returns a promise, it doesn't take a callback. You are using the library incorrectly. When values are the second parameter, then the third parameter is not supposed to be a callback, it is supposed to be a QueryResultMask



    You should be using it is:



    db.query(...)
    .then(r => console.log(r))
    .catch(e => console.log(e))


    Check out this simple insert example






    share|improve this answer

























      up vote
      1
      down vote













      pg-promise returns a promise, it doesn't take a callback. You are using the library incorrectly. When values are the second parameter, then the third parameter is not supposed to be a callback, it is supposed to be a QueryResultMask



      You should be using it is:



      db.query(...)
      .then(r => console.log(r))
      .catch(e => console.log(e))


      Check out this simple insert example






      share|improve this answer























        up vote
        1
        down vote










        up vote
        1
        down vote









        pg-promise returns a promise, it doesn't take a callback. You are using the library incorrectly. When values are the second parameter, then the third parameter is not supposed to be a callback, it is supposed to be a QueryResultMask



        You should be using it is:



        db.query(...)
        .then(r => console.log(r))
        .catch(e => console.log(e))


        Check out this simple insert example






        share|improve this answer












        pg-promise returns a promise, it doesn't take a callback. You are using the library incorrectly. When values are the second parameter, then the third parameter is not supposed to be a callback, it is supposed to be a QueryResultMask



        You should be using it is:



        db.query(...)
        .then(r => console.log(r))
        .catch(e => console.log(e))


        Check out this simple insert example







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 11 at 15:40









        Adam

        27.1k84261




        27.1k84261






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53250276%2fexpress-postgres-unhandled-promise-rejection-warning%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Florida Star v. B. J. F.

            Error while running script in elastic search , gateway timeout

            Adding quotations to stringified JSON object values