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.
javascript node.js postgresql express
add a comment |
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.
javascript node.js postgresql express
1
Are you sure that?
placeholders are valid forpg-promise
? See this answer.
– robertklep
Nov 11 at 15:41
add a comment |
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.
javascript node.js postgresql express
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
javascript node.js postgresql express
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 forpg-promise
? See this answer.
– robertklep
Nov 11 at 15:41
add a comment |
1
Are you sure that?
placeholders are valid forpg-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
add a comment |
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
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
add a comment |
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
add a comment |
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
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
answered Nov 11 at 15:40
Adam
27.1k84261
27.1k84261
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
1
Are you sure that
?
placeholders are valid forpg-promise
? See this answer.– robertklep
Nov 11 at 15:41