Skip to content

queryInterface.bulkUpdate usage #8687

Closed

Description

@chaoxihailing

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
image

#6909

Activity

  1. mhombach commented on Jan 15, 2018

    @mhombach

    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 :)

  2. Taylor123 commented on Jan 18, 2018

    @Taylor123

    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.

  3. Taylor123 commented on Jan 18, 2018

    @Taylor123

    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).

  4. cyrilchapon commented on Feb 20, 2018

    @cyrilchapon

    @Taylor123 thanks for sharing.

    Can you paste 1 or 2 full working examples of updates, including mutation ?

    Thanks ☺️

  5. stale commented on May 21, 2018

    @stale

    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 🙂

  6. cyrilchapon commented on May 22, 2018

    @cyrilchapon

    This is still a god damned issue

  7. mhombach commented on May 22, 2018

    @mhombach

    @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 :)

  8. cyrilchapon commented on May 22, 2018

    @cyrilchapon

    @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)

  9. mhombach commented on May 22, 2018

    @mhombach

    @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" :/

  10. sushantdhiman commented on May 22, 2018

    @sushantdhiman
    Contributor

    Duplicate of #8820

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions