self.updateInfo = function (user) {
return db.query("UPDATE users SET name=${name} username=${username} email=${email} WHERE (id=${id} AND activated = true) RETURNING *;", user);
}
userSQL.updateInfo(user).then(function (newUser) {
response.json({
message: "user updated",
data: newUser
});
}).catch(function (error) {
handler.error(response, 400, error);
});
{"message":{"name":"error","length":305,"severity":"ERROR","code":"23505","detail":"Key \"(username)=(test)\" is already sushestvuet.","schema":"public","table":"users","constraint":"users_username_key","file":"nbtinsert.c","line":"434","routine":"_bt_check_unique"}}
Find more questions by tags JavaScriptSQLPostgreSQLNode.js
the latter will create a new entry or an existing proupdate, at my convenience. - sally_Carro commented on June 8th 19 at 17:23