Skip to content

queryInterface.bulkUpdate usage #6909

Closed

Description

@Jhovanni

Is there any documentation or info available to use queryInterface.bulkUpdate method?
I'm trying to update several columns using a seeder file. But I cannot get it work, log keeps trowing
Seed file failed with error: val.replace is not a function

I know it should be something with the parameters passed, but looking at the method signature, there is no way I can figure out what params should be passed and how.

This is my code right now:

up : function(queryInterface, Sequelize) {
	return queryInterface.bulkUpdate("Catalogo", catalogos, {});
}
var catalogos = [
	{numero:"001", eExperiencia:64, eSalud:2},
	{numero:"002", eExperiencia:56, eSalud:3}
];

Table Catalogo has numero as primary key, and I'm trying to change its eExperiencia and eSalud values.

Activity

  1. janmeier commented on Nov 23, 2016

    @janmeier
    Member

    Bulk update allows you to update a set of rows, matching a where clause (http://docs.sequelizejs.com/en/v3/api/model/#updatevalues-options-promisearrayaffectedcount-affectedrows), i.e. something like UPDATE foo SET bar = 42 WHERE baz = 50;. It does not support updating multiple rows to different values

  2. Jhovanni commented on Nov 23, 2016

    @Jhovanni
    Author

    But that documentation is about update in sequelize object. There is a bulk update with the following signature in queryInterface

    bulkUpdate(tableName, values, identifier, options, attributes);

    How can I use it?

  3. janmeier commented on Nov 23, 2016

    @janmeier
    Member

    return this.QueryInterface.bulkUpdate(this.getTableName(options), attrValueHash, _.defaults(where, options.where), options, this.rawAttributes);

    bulkUpdate(tableName, values, identifier, options, attributes) {

    You've already read this far into the code, why don't you go ahead and read the rest. As I've said it's not part of the public API, and it cannot be used for what you want to do - Many separate updates in bulk. It can only do a single update (setting the same values) on many rows

  4. Jhovanni commented on Nov 23, 2016

    @Jhovanni
    Author

    Thank you.
    Then I'll make a promise to update each item individually

  5. mmenik commented on Mar 2, 2017

    @mmenik

    I dont understand how pass parameters of function
    queryInterface.bulkUpdate(tableName, values, identifier, options, attributes);

    I need for update a single row (filter by id) in a seeders file, you can show an example?
    Thanks

  6. chaoxihailing commented on Nov 24, 2017

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

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions