Sequelize - update record, and return resultUpdating model with Sequelize JSevent.preventDefault() vs. return falseWhy does ++[[]][+[]]+[+[]] return the string “10”?How to update a record using sequelize for node?How do I return the response from an asynchronous call?How do I update each dependency in package.json to the latest version?sequelize findOrCreate with include associationself.$expandAttributes is not a function with SequelizeSequelize updateSequelize model error-tring to make model in sequelize and getting this errorsequelize rollback not working with promise.all
If you attack a Tarrasque while swallowed, what AC do you need to beat to hit it?
How can I use 400 ASA film in a Leica IIIf, which does not have options higher than 100?
tikz: 5 squares on a row, roman numbered 1 -> 5
Salesforce bug enabled "Modify All"
Is there a realtime, uncut video of Saturn V ignition through tower clear?
400–430 degrees Celsius heated bath
How to safely discharge oneself
Is my company merging branches wrong?
Do most Taxis give Receipts in London?
Why is this python script running in background consuming 100 % CPU?
If the Charles SSL Proxy shows me sensitive data, is that data insecure/exposed?
Gambler's Fallacy Dice
Why use nominative in Coniugatio periphrastica passiva?
How can sister protect herself from impulse purchases with a credit card?
Is there any mention of ghosts who live outside the Hogwarts castle?
Mikrokosmos, BB 105, Vol. 1: No. 17 Contrary Motion (1) - Can't understand the structure
How can I prevent Bash expansion from passing files starting with "-" as argument?
Eigenvalues of the Laplace-Beltrami operator on a compact Riemannnian manifold
How did Jean Parisot de Valette, 49th Grand Master of the Order of Malta, die?
Good examples of "two is easy, three is hard" in computational sciences
Does the Aboleth have expertise in History and Perception?
why "American-born", not "America-born"?
How did Arya and the Hound get into King's Landing so easily?
Why did Nick Fury not hesitate in blowing up the plane he thought was carrying a nuke?
Sequelize - update record, and return result
Updating model with Sequelize JSevent.preventDefault() vs. return falseWhy does ++[[]][+[]]+[+[]] return the string “10”?How to update a record using sequelize for node?How do I return the response from an asynchronous call?How do I update each dependency in package.json to the latest version?sequelize findOrCreate with include associationself.$expandAttributes is not a function with SequelizeSequelize updateSequelize model error-tring to make model in sequelize and getting this errorsequelize rollback not working with promise.all
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I am using sequelize with MySQL. For example if I do:
models.People.update(OwnerId: peopleInfo.newuser,
where: id: peopleInfo.scenario.id)
.then(function (result)
response(result).code(200);
).catch(function (err)
request.server.log(['error'], err.stack);
).code(200);
);
I am not getting information back if the people model was succesfully updated or not. Variable result is just an array with one element, 0=1
How can I know for certain that the record was updated or not.
javascript sequelize.js
add a comment |
I am using sequelize with MySQL. For example if I do:
models.People.update(OwnerId: peopleInfo.newuser,
where: id: peopleInfo.scenario.id)
.then(function (result)
response(result).code(200);
).catch(function (err)
request.server.log(['error'], err.stack);
).code(200);
);
I am not getting information back if the people model was succesfully updated or not. Variable result is just an array with one element, 0=1
How can I know for certain that the record was updated or not.
javascript sequelize.js
add a comment |
I am using sequelize with MySQL. For example if I do:
models.People.update(OwnerId: peopleInfo.newuser,
where: id: peopleInfo.scenario.id)
.then(function (result)
response(result).code(200);
).catch(function (err)
request.server.log(['error'], err.stack);
).code(200);
);
I am not getting information back if the people model was succesfully updated or not. Variable result is just an array with one element, 0=1
How can I know for certain that the record was updated or not.
javascript sequelize.js
I am using sequelize with MySQL. For example if I do:
models.People.update(OwnerId: peopleInfo.newuser,
where: id: peopleInfo.scenario.id)
.then(function (result)
response(result).code(200);
).catch(function (err)
request.server.log(['error'], err.stack);
).code(200);
);
I am not getting information back if the people model was succesfully updated or not. Variable result is just an array with one element, 0=1
How can I know for certain that the record was updated or not.
javascript sequelize.js
javascript sequelize.js
asked Jul 22 '16 at 11:08
Vedran Maricevic.Vedran Maricevic.
2,49643662
2,49643662
add a comment |
add a comment |
5 Answers
5
active
oldest
votes
Here's what I think you're looking for.
db.connections.update(
user: data.username,
chatroomID: data.chatroomID
,
where: socketID: socket.id ,
returning: true,
plain: true
)
.then(function (result)
console.log(result);
// result = [x] or [x, y]
// [x] if you're not using Postgres
// [x, y] if you are using Postgres
);
From Sequelize docs:
The promise returns an array with one or two elements. The first element x
is always the number of affected rows, while the second element y
is the actual affected rows (only supported in postgres with options.returning
set to true
.)
Assuming you are using Postgres, you can access the updated object with result[1].dataValues
.
You must set returning: true
option to tell Sequelize to return the object. And plain: true
is just to return the object itself and not the other messy meta data that might not be useful.
1
I am using MySQL. I will test it with. Thanks for reply
– Vedran Maricevic.
Nov 11 '16 at 7:53
@Wexoni is it work using MySQL? give me feedback
– MH Rohman Masyhar
Dec 12 '16 at 11:14
4
I was not able to make it work with MySql. I guess this is only Postgresql feature :(
– Vedran Maricevic.
Dec 12 '16 at 11:16
2
Also, despite what the docs say, I getundefined
as the first parameter and the number of affected rows as the second parameter (using sqlite). To fix this I didresult = result.filter(Boolean);
before processing anything.
– Ryan Wheale
Jun 28 '17 at 20:42
Is there a way to specify returned columns? I'm working with Postgress
– Uri Abramson
Oct 2 '17 at 17:36
|
show 7 more comments
Update function of sequelize returns a number of affected rows (first parameter of result array).
You should call find to get updated row
models.People.update(OwnerId: peopleInfo.newuser,
where: id: peopleInfo.scenario.id)
.then(function (result)
models.People.findById(peopleInfo.scenario.id)
.then(function(user)
response(user).code(200);
).catch(function (err)
request.server.log(['error'], err.stack);
).code(200);
);
).catch(function (err)
request.server.log(['error'], err.stack);
).code(200);
);
1
So it seems the only way is to call find immediately after the update?
– Vedran Maricevic.
Jul 25 '16 at 11:20
anyway you should use find function.
– Tilekbekov Yrysbek
Jul 25 '16 at 12:05
2
you can callfind
function first, then do update with this object without usingwhere
– Tilekbekov Yrysbek
Jul 25 '16 at 12:07
1
if you're using PostgreSQL you can definereturning
option totrue
that returns affected rows
– Tilekbekov Yrysbek
Jul 25 '16 at 12:11
add a comment |
same thing you can do with async-await, especially to avoid nested Promises
You just need to create async function :)
const asyncFunction = async function(req, res)
try
//update
const updatePeople = await models.People.update(OwnerId: peopleInfo.newuser,
where: id: peopleInfo.scenario.id)
if (!updatePeople) throw ('Error while Updating');
// fetch updated data
const returnUpdatedPerson = await models.People.findById(peopleInfo.scenario.id)
if(!returnUpdatedPerson) throw ('Error while Fetching Data');
res(user).code(200);
catch (error)
res.send(error)
add a comment |
You can just find the item and update its properties and then save it.
The save() results in a UPDATE query to the db
const job = await Job.findOne(where: id, ownerId: req.user.id);
if (!job)
throw Error(`Job not updated. id: $id`);
job.name = input.name;
job.payload = input.payload;
await job.save();
On Postgres:
Executing (default): UPDATE "jobs" SET "payload"=$1,"updatedAt"=$2 WHERE "id" = $3
add a comment |
Simple snipet to update and get updated result
models.People.findOne(
where: id: peopleInfo.scenario.id
)
.then((people) =>
if(people == null) console.log("invalid people");
people.fieldOne = currentValue;
people.fieldtwo = currentValue;
return people.save()
)
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',
autoActivateHeartbeat: false,
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%2f38524938%2fsequelize-update-record-and-return-result%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
5 Answers
5
active
oldest
votes
5 Answers
5
active
oldest
votes
active
oldest
votes
active
oldest
votes
Here's what I think you're looking for.
db.connections.update(
user: data.username,
chatroomID: data.chatroomID
,
where: socketID: socket.id ,
returning: true,
plain: true
)
.then(function (result)
console.log(result);
// result = [x] or [x, y]
// [x] if you're not using Postgres
// [x, y] if you are using Postgres
);
From Sequelize docs:
The promise returns an array with one or two elements. The first element x
is always the number of affected rows, while the second element y
is the actual affected rows (only supported in postgres with options.returning
set to true
.)
Assuming you are using Postgres, you can access the updated object with result[1].dataValues
.
You must set returning: true
option to tell Sequelize to return the object. And plain: true
is just to return the object itself and not the other messy meta data that might not be useful.
1
I am using MySQL. I will test it with. Thanks for reply
– Vedran Maricevic.
Nov 11 '16 at 7:53
@Wexoni is it work using MySQL? give me feedback
– MH Rohman Masyhar
Dec 12 '16 at 11:14
4
I was not able to make it work with MySql. I guess this is only Postgresql feature :(
– Vedran Maricevic.
Dec 12 '16 at 11:16
2
Also, despite what the docs say, I getundefined
as the first parameter and the number of affected rows as the second parameter (using sqlite). To fix this I didresult = result.filter(Boolean);
before processing anything.
– Ryan Wheale
Jun 28 '17 at 20:42
Is there a way to specify returned columns? I'm working with Postgress
– Uri Abramson
Oct 2 '17 at 17:36
|
show 7 more comments
Here's what I think you're looking for.
db.connections.update(
user: data.username,
chatroomID: data.chatroomID
,
where: socketID: socket.id ,
returning: true,
plain: true
)
.then(function (result)
console.log(result);
// result = [x] or [x, y]
// [x] if you're not using Postgres
// [x, y] if you are using Postgres
);
From Sequelize docs:
The promise returns an array with one or two elements. The first element x
is always the number of affected rows, while the second element y
is the actual affected rows (only supported in postgres with options.returning
set to true
.)
Assuming you are using Postgres, you can access the updated object with result[1].dataValues
.
You must set returning: true
option to tell Sequelize to return the object. And plain: true
is just to return the object itself and not the other messy meta data that might not be useful.
1
I am using MySQL. I will test it with. Thanks for reply
– Vedran Maricevic.
Nov 11 '16 at 7:53
@Wexoni is it work using MySQL? give me feedback
– MH Rohman Masyhar
Dec 12 '16 at 11:14
4
I was not able to make it work with MySql. I guess this is only Postgresql feature :(
– Vedran Maricevic.
Dec 12 '16 at 11:16
2
Also, despite what the docs say, I getundefined
as the first parameter and the number of affected rows as the second parameter (using sqlite). To fix this I didresult = result.filter(Boolean);
before processing anything.
– Ryan Wheale
Jun 28 '17 at 20:42
Is there a way to specify returned columns? I'm working with Postgress
– Uri Abramson
Oct 2 '17 at 17:36
|
show 7 more comments
Here's what I think you're looking for.
db.connections.update(
user: data.username,
chatroomID: data.chatroomID
,
where: socketID: socket.id ,
returning: true,
plain: true
)
.then(function (result)
console.log(result);
// result = [x] or [x, y]
// [x] if you're not using Postgres
// [x, y] if you are using Postgres
);
From Sequelize docs:
The promise returns an array with one or two elements. The first element x
is always the number of affected rows, while the second element y
is the actual affected rows (only supported in postgres with options.returning
set to true
.)
Assuming you are using Postgres, you can access the updated object with result[1].dataValues
.
You must set returning: true
option to tell Sequelize to return the object. And plain: true
is just to return the object itself and not the other messy meta data that might not be useful.
Here's what I think you're looking for.
db.connections.update(
user: data.username,
chatroomID: data.chatroomID
,
where: socketID: socket.id ,
returning: true,
plain: true
)
.then(function (result)
console.log(result);
// result = [x] or [x, y]
// [x] if you're not using Postgres
// [x, y] if you are using Postgres
);
From Sequelize docs:
The promise returns an array with one or two elements. The first element x
is always the number of affected rows, while the second element y
is the actual affected rows (only supported in postgres with options.returning
set to true
.)
Assuming you are using Postgres, you can access the updated object with result[1].dataValues
.
You must set returning: true
option to tell Sequelize to return the object. And plain: true
is just to return the object itself and not the other messy meta data that might not be useful.
edited Aug 30 '18 at 13:48
Yves M.
19.5k1373104
19.5k1373104
answered Nov 11 '16 at 7:51
nickangnickang
711412
711412
1
I am using MySQL. I will test it with. Thanks for reply
– Vedran Maricevic.
Nov 11 '16 at 7:53
@Wexoni is it work using MySQL? give me feedback
– MH Rohman Masyhar
Dec 12 '16 at 11:14
4
I was not able to make it work with MySql. I guess this is only Postgresql feature :(
– Vedran Maricevic.
Dec 12 '16 at 11:16
2
Also, despite what the docs say, I getundefined
as the first parameter and the number of affected rows as the second parameter (using sqlite). To fix this I didresult = result.filter(Boolean);
before processing anything.
– Ryan Wheale
Jun 28 '17 at 20:42
Is there a way to specify returned columns? I'm working with Postgress
– Uri Abramson
Oct 2 '17 at 17:36
|
show 7 more comments
1
I am using MySQL. I will test it with. Thanks for reply
– Vedran Maricevic.
Nov 11 '16 at 7:53
@Wexoni is it work using MySQL? give me feedback
– MH Rohman Masyhar
Dec 12 '16 at 11:14
4
I was not able to make it work with MySql. I guess this is only Postgresql feature :(
– Vedran Maricevic.
Dec 12 '16 at 11:16
2
Also, despite what the docs say, I getundefined
as the first parameter and the number of affected rows as the second parameter (using sqlite). To fix this I didresult = result.filter(Boolean);
before processing anything.
– Ryan Wheale
Jun 28 '17 at 20:42
Is there a way to specify returned columns? I'm working with Postgress
– Uri Abramson
Oct 2 '17 at 17:36
1
1
I am using MySQL. I will test it with. Thanks for reply
– Vedran Maricevic.
Nov 11 '16 at 7:53
I am using MySQL. I will test it with. Thanks for reply
– Vedran Maricevic.
Nov 11 '16 at 7:53
@Wexoni is it work using MySQL? give me feedback
– MH Rohman Masyhar
Dec 12 '16 at 11:14
@Wexoni is it work using MySQL? give me feedback
– MH Rohman Masyhar
Dec 12 '16 at 11:14
4
4
I was not able to make it work with MySql. I guess this is only Postgresql feature :(
– Vedran Maricevic.
Dec 12 '16 at 11:16
I was not able to make it work with MySql. I guess this is only Postgresql feature :(
– Vedran Maricevic.
Dec 12 '16 at 11:16
2
2
Also, despite what the docs say, I get
undefined
as the first parameter and the number of affected rows as the second parameter (using sqlite). To fix this I did result = result.filter(Boolean);
before processing anything.– Ryan Wheale
Jun 28 '17 at 20:42
Also, despite what the docs say, I get
undefined
as the first parameter and the number of affected rows as the second parameter (using sqlite). To fix this I did result = result.filter(Boolean);
before processing anything.– Ryan Wheale
Jun 28 '17 at 20:42
Is there a way to specify returned columns? I'm working with Postgress
– Uri Abramson
Oct 2 '17 at 17:36
Is there a way to specify returned columns? I'm working with Postgress
– Uri Abramson
Oct 2 '17 at 17:36
|
show 7 more comments
Update function of sequelize returns a number of affected rows (first parameter of result array).
You should call find to get updated row
models.People.update(OwnerId: peopleInfo.newuser,
where: id: peopleInfo.scenario.id)
.then(function (result)
models.People.findById(peopleInfo.scenario.id)
.then(function(user)
response(user).code(200);
).catch(function (err)
request.server.log(['error'], err.stack);
).code(200);
);
).catch(function (err)
request.server.log(['error'], err.stack);
).code(200);
);
1
So it seems the only way is to call find immediately after the update?
– Vedran Maricevic.
Jul 25 '16 at 11:20
anyway you should use find function.
– Tilekbekov Yrysbek
Jul 25 '16 at 12:05
2
you can callfind
function first, then do update with this object without usingwhere
– Tilekbekov Yrysbek
Jul 25 '16 at 12:07
1
if you're using PostgreSQL you can definereturning
option totrue
that returns affected rows
– Tilekbekov Yrysbek
Jul 25 '16 at 12:11
add a comment |
Update function of sequelize returns a number of affected rows (first parameter of result array).
You should call find to get updated row
models.People.update(OwnerId: peopleInfo.newuser,
where: id: peopleInfo.scenario.id)
.then(function (result)
models.People.findById(peopleInfo.scenario.id)
.then(function(user)
response(user).code(200);
).catch(function (err)
request.server.log(['error'], err.stack);
).code(200);
);
).catch(function (err)
request.server.log(['error'], err.stack);
).code(200);
);
1
So it seems the only way is to call find immediately after the update?
– Vedran Maricevic.
Jul 25 '16 at 11:20
anyway you should use find function.
– Tilekbekov Yrysbek
Jul 25 '16 at 12:05
2
you can callfind
function first, then do update with this object without usingwhere
– Tilekbekov Yrysbek
Jul 25 '16 at 12:07
1
if you're using PostgreSQL you can definereturning
option totrue
that returns affected rows
– Tilekbekov Yrysbek
Jul 25 '16 at 12:11
add a comment |
Update function of sequelize returns a number of affected rows (first parameter of result array).
You should call find to get updated row
models.People.update(OwnerId: peopleInfo.newuser,
where: id: peopleInfo.scenario.id)
.then(function (result)
models.People.findById(peopleInfo.scenario.id)
.then(function(user)
response(user).code(200);
).catch(function (err)
request.server.log(['error'], err.stack);
).code(200);
);
).catch(function (err)
request.server.log(['error'], err.stack);
).code(200);
);
Update function of sequelize returns a number of affected rows (first parameter of result array).
You should call find to get updated row
models.People.update(OwnerId: peopleInfo.newuser,
where: id: peopleInfo.scenario.id)
.then(function (result)
models.People.findById(peopleInfo.scenario.id)
.then(function(user)
response(user).code(200);
).catch(function (err)
request.server.log(['error'], err.stack);
).code(200);
);
).catch(function (err)
request.server.log(['error'], err.stack);
).code(200);
);
answered Jul 25 '16 at 11:19
Tilekbekov YrysbekTilekbekov Yrysbek
1,51238
1,51238
1
So it seems the only way is to call find immediately after the update?
– Vedran Maricevic.
Jul 25 '16 at 11:20
anyway you should use find function.
– Tilekbekov Yrysbek
Jul 25 '16 at 12:05
2
you can callfind
function first, then do update with this object without usingwhere
– Tilekbekov Yrysbek
Jul 25 '16 at 12:07
1
if you're using PostgreSQL you can definereturning
option totrue
that returns affected rows
– Tilekbekov Yrysbek
Jul 25 '16 at 12:11
add a comment |
1
So it seems the only way is to call find immediately after the update?
– Vedran Maricevic.
Jul 25 '16 at 11:20
anyway you should use find function.
– Tilekbekov Yrysbek
Jul 25 '16 at 12:05
2
you can callfind
function first, then do update with this object without usingwhere
– Tilekbekov Yrysbek
Jul 25 '16 at 12:07
1
if you're using PostgreSQL you can definereturning
option totrue
that returns affected rows
– Tilekbekov Yrysbek
Jul 25 '16 at 12:11
1
1
So it seems the only way is to call find immediately after the update?
– Vedran Maricevic.
Jul 25 '16 at 11:20
So it seems the only way is to call find immediately after the update?
– Vedran Maricevic.
Jul 25 '16 at 11:20
anyway you should use find function.
– Tilekbekov Yrysbek
Jul 25 '16 at 12:05
anyway you should use find function.
– Tilekbekov Yrysbek
Jul 25 '16 at 12:05
2
2
you can call
find
function first, then do update with this object without using where
– Tilekbekov Yrysbek
Jul 25 '16 at 12:07
you can call
find
function first, then do update with this object without using where
– Tilekbekov Yrysbek
Jul 25 '16 at 12:07
1
1
if you're using PostgreSQL you can define
returning
option to true
that returns affected rows– Tilekbekov Yrysbek
Jul 25 '16 at 12:11
if you're using PostgreSQL you can define
returning
option to true
that returns affected rows– Tilekbekov Yrysbek
Jul 25 '16 at 12:11
add a comment |
same thing you can do with async-await, especially to avoid nested Promises
You just need to create async function :)
const asyncFunction = async function(req, res)
try
//update
const updatePeople = await models.People.update(OwnerId: peopleInfo.newuser,
where: id: peopleInfo.scenario.id)
if (!updatePeople) throw ('Error while Updating');
// fetch updated data
const returnUpdatedPerson = await models.People.findById(peopleInfo.scenario.id)
if(!returnUpdatedPerson) throw ('Error while Fetching Data');
res(user).code(200);
catch (error)
res.send(error)
add a comment |
same thing you can do with async-await, especially to avoid nested Promises
You just need to create async function :)
const asyncFunction = async function(req, res)
try
//update
const updatePeople = await models.People.update(OwnerId: peopleInfo.newuser,
where: id: peopleInfo.scenario.id)
if (!updatePeople) throw ('Error while Updating');
// fetch updated data
const returnUpdatedPerson = await models.People.findById(peopleInfo.scenario.id)
if(!returnUpdatedPerson) throw ('Error while Fetching Data');
res(user).code(200);
catch (error)
res.send(error)
add a comment |
same thing you can do with async-await, especially to avoid nested Promises
You just need to create async function :)
const asyncFunction = async function(req, res)
try
//update
const updatePeople = await models.People.update(OwnerId: peopleInfo.newuser,
where: id: peopleInfo.scenario.id)
if (!updatePeople) throw ('Error while Updating');
// fetch updated data
const returnUpdatedPerson = await models.People.findById(peopleInfo.scenario.id)
if(!returnUpdatedPerson) throw ('Error while Fetching Data');
res(user).code(200);
catch (error)
res.send(error)
same thing you can do with async-await, especially to avoid nested Promises
You just need to create async function :)
const asyncFunction = async function(req, res)
try
//update
const updatePeople = await models.People.update(OwnerId: peopleInfo.newuser,
where: id: peopleInfo.scenario.id)
if (!updatePeople) throw ('Error while Updating');
// fetch updated data
const returnUpdatedPerson = await models.People.findById(peopleInfo.scenario.id)
if(!returnUpdatedPerson) throw ('Error while Fetching Data');
res(user).code(200);
catch (error)
res.send(error)
edited May 5 at 13:47
answered Mar 23 at 19:33
Bharat SuryawanshiBharat Suryawanshi
213
213
add a comment |
add a comment |
You can just find the item and update its properties and then save it.
The save() results in a UPDATE query to the db
const job = await Job.findOne(where: id, ownerId: req.user.id);
if (!job)
throw Error(`Job not updated. id: $id`);
job.name = input.name;
job.payload = input.payload;
await job.save();
On Postgres:
Executing (default): UPDATE "jobs" SET "payload"=$1,"updatedAt"=$2 WHERE "id" = $3
add a comment |
You can just find the item and update its properties and then save it.
The save() results in a UPDATE query to the db
const job = await Job.findOne(where: id, ownerId: req.user.id);
if (!job)
throw Error(`Job not updated. id: $id`);
job.name = input.name;
job.payload = input.payload;
await job.save();
On Postgres:
Executing (default): UPDATE "jobs" SET "payload"=$1,"updatedAt"=$2 WHERE "id" = $3
add a comment |
You can just find the item and update its properties and then save it.
The save() results in a UPDATE query to the db
const job = await Job.findOne(where: id, ownerId: req.user.id);
if (!job)
throw Error(`Job not updated. id: $id`);
job.name = input.name;
job.payload = input.payload;
await job.save();
On Postgres:
Executing (default): UPDATE "jobs" SET "payload"=$1,"updatedAt"=$2 WHERE "id" = $3
You can just find the item and update its properties and then save it.
The save() results in a UPDATE query to the db
const job = await Job.findOne(where: id, ownerId: req.user.id);
if (!job)
throw Error(`Job not updated. id: $id`);
job.name = input.name;
job.payload = input.payload;
await job.save();
On Postgres:
Executing (default): UPDATE "jobs" SET "payload"=$1,"updatedAt"=$2 WHERE "id" = $3
answered May 3 at 2:25
David DehghanDavid Dehghan
6,58614862
6,58614862
add a comment |
add a comment |
Simple snipet to update and get updated result
models.People.findOne(
where: id: peopleInfo.scenario.id
)
.then((people) =>
if(people == null) console.log("invalid people");
people.fieldOne = currentValue;
people.fieldtwo = currentValue;
return people.save()
)
add a comment |
Simple snipet to update and get updated result
models.People.findOne(
where: id: peopleInfo.scenario.id
)
.then((people) =>
if(people == null) console.log("invalid people");
people.fieldOne = currentValue;
people.fieldtwo = currentValue;
return people.save()
)
add a comment |
Simple snipet to update and get updated result
models.People.findOne(
where: id: peopleInfo.scenario.id
)
.then((people) =>
if(people == null) console.log("invalid people");
people.fieldOne = currentValue;
people.fieldtwo = currentValue;
return people.save()
)
Simple snipet to update and get updated result
models.People.findOne(
where: id: peopleInfo.scenario.id
)
.then((people) =>
if(people == null) console.log("invalid people");
people.fieldOne = currentValue;
people.fieldtwo = currentValue;
return people.save()
)
answered May 6 at 8:05
Riajul IslamRiajul Islam
473511
473511
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.
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%2f38524938%2fsequelize-update-record-and-return-result%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