You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I dont understand how pass parameters of function
queryInterface.bulkUpdate(tableName, values, identifier, options, attributes);
I hava a table monitorDevice has fileld like id, monitorSpotId, alarmTypeDeviceSubType, isAvailable;
and I want to update column alarmTypeDeviceSubType, but it not work;
I write query like below, How can I work bulkquery
In my opinion it seems that you didn't fully understand how the models of Sequelize are used.
First let's all use the same vocabulary: I hava a table monitorDevice -> You mean you have a Sequelize-MODEL called "MonitorDevice" which has the following attributes:
id
monitorSpotId
alarm
(TypeDeviceSubType ?)
isAvailable
You query this Model by using MonitorDevice.doSomething.
For example MonitorDevice.findByID(1), which gives you the entry with the id 1.
If you want to CREATE a new entry, then you use: MonitorDevice.create({ id: 5, monitorSpotId: 99, alarm: 'something', isAvailable: false }).
This creates and saves these data to the database.
Bulk-create works the same, you just pass it an array which can contain many new entries which are written exactly like the one i wrote above.
So you create an array and fill it. Let's say you called that array "newDataArray".
you then do: MonitorDevice.bulkCreate(newDataArray); which creates and saves new entries for all of the containing entries within the array.
I hope this helpful and you did understand the Sequelize-concept a little bit more :)
Reacted by Taylor Johnson, Sebastian Alvarado, Austin Payne, Bello Gbadebo, Prorock201, sagewizard4096, Andrei and Kwan Lam
The question was asking about the bulkUpdate, which currently lacks documentation, not bulkCreate.
I was able to get the bulkUpdate function to run as follows: return queryInterface.bulkUpdate('table', { attributeToUpdate: 'newValue' }, { attributeToUpdateBy: 'valueToChange' });
However, I have not figured out how to set the identifier parameter to allow myself to bulk update via attributeToSearchBy: 'value1' OR 'value2'
My issue was using an object that specified the multiple values I wanted to select columns to update by. My reasoning for using objects instead of an array of values was because that's how the bulkDelete was able to function. I will try and make an update to the docs if I get some time to contribute (and find where to update docs).
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is still an issue, just leave a comment 🙂
@cyrilchapon OP is not responding since his first post so we have no way to communicate about the source issue of this thread. OP also had at least one big mistake in his original query (declaring an object without any attribute) so we can ignore that original error. Also, no offense, it seems because of this issue, that OP maybe lacks some general JS skills and may have more logical errors in his code.
If you have this or a related issue with TypeORM, please feel free to create your own issue :)
@mhombach, IMHO the issue is not about "bulkUpdate is not usable"; the issue is about "knowing how to use bulkUpdate", as the title suggests. Which implies mostly documentation, I guess. He starts the issue with "I don't understand", which is caused by lack of skills, indeed, but also a lack of documentation.
Digging through doc and sourceCode, I've been able to use bulkUpdate (inside migrations in my case) spending 2 hours understanding the whole concept of Sequelize query and stuff, while I've been able to use bulkInsert in less than 5 minutes.
This lacks documentation as hell, but the issue is a duplicate of #8820 (saner report and issue, better labels)
@cyrilchapon Yep, i also think that documentation could be better. My whole point was that in my opinion we should let this issue be closed, as the OP seems to not be interested in communicating here. So OP can never close this issue by himself or even tell us, if his problem was solved. So a different issue targeting the lack of documentation is the right way, i think. My point was primary on OP not responding, so this thread here can be considered "dead", at least "a dead end" :/
Activity
mhombach commentedon Jan 15, 2018
In my opinion it seems that you didn't fully understand how the models of Sequelize are used.
First let's all use the same vocabulary:
I hava a table monitorDevice-> You mean you have a Sequelize-MODEL called "MonitorDevice" which has the following attributes:You query this Model by using
MonitorDevice.doSomething.For example
MonitorDevice.findByID(1), which gives you the entry with the id 1.If you want to CREATE a new entry, then you use:
MonitorDevice.create({ id: 5, monitorSpotId: 99, alarm: 'something', isAvailable: false }).This creates and saves these data to the database.
Bulk-create works the same, you just pass it an array which can contain many new entries which are written exactly like the one i wrote above.
So you create an array and fill it. Let's say you called that array "newDataArray".
you then do:
MonitorDevice.bulkCreate(newDataArray);which creates and saves new entries for all of the containing entries within the array.I hope this helpful and you did understand the Sequelize-concept a little bit more :)
Taylor123 commentedon Jan 18, 2018
The question was asking about the bulkUpdate, which currently lacks documentation, not bulkCreate.
I was able to get the bulkUpdate function to run as follows:
return queryInterface.bulkUpdate('table', { attributeToUpdate: 'newValue' }, { attributeToUpdateBy: 'valueToChange' });However, I have not figured out how to set the identifier parameter to allow myself to bulk update via
attributeToSearchBy: 'value1' OR 'value2'A code example would be greatly appreciated.
Taylor123 commentedon Jan 18, 2018
working example of searching a column/attribute by multiple values:
return queryInterface.bulkUpdate('table', { attributeToUpdate: 'newValue' }, { attributeToUpdateBy: { [Sequelize.Op.or]: [ 'value1', 'value2' ] } });My issue was using an object that specified the multiple values I wanted to select columns to update by. My reasoning for using objects instead of an array of values was because that's how the bulkDelete was able to function. I will try and make an update to the docs if I get some time to contribute (and find where to update docs).
cyrilchapon commentedon Feb 20, 2018
@Taylor123 thanks for sharing.
Can you paste 1 or 2 full working examples of updates, including mutation ?
Thanks☺️
stale commentedon May 21, 2018
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is still an issue, just leave a comment 🙂
cyrilchapon commentedon May 22, 2018
This is still a god damned issue
mhombach commentedon May 22, 2018
@cyrilchapon OP is not responding since his first post so we have no way to communicate about the source issue of this thread. OP also had at least one big mistake in his original query (declaring an object without any attribute) so we can ignore that original error. Also, no offense, it seems because of this issue, that OP maybe lacks some general JS skills and may have more logical errors in his code.
If you have this or a related issue with TypeORM, please feel free to create your own issue :)
cyrilchapon commentedon May 22, 2018
@mhombach, IMHO the issue is not about "bulkUpdate is not usable"; the issue is about "knowing how to use bulkUpdate", as the title suggests. Which implies mostly documentation, I guess. He starts the issue with "I don't understand", which is caused by lack of skills, indeed, but also a lack of documentation.
Digging through doc and sourceCode, I've been able to use
bulkUpdate(inside migrations in my case) spending 2 hours understanding the whole concept of Sequelize query and stuff, while I've been able to usebulkInsertin less than 5 minutes.This lacks documentation as hell, but the issue is a duplicate of #8820 (saner report and issue, better labels)
mhombach commentedon May 22, 2018
@cyrilchapon Yep, i also think that documentation could be better. My whole point was that in my opinion we should let this issue be closed, as the OP seems to not be interested in communicating here. So OP can never close this issue by himself or even tell us, if his problem was solved. So a different issue targeting the lack of documentation is the right way, i think. My point was primary on OP not responding, so this thread here can be considered "dead", at least "a dead end" :/
sushantdhiman commentedon May 22, 2018
Duplicate of #8820