node.js - Does Sequelize support Insert on duplicate key update? -
is there model or instance method perform insert or update, depending on whether or not record exists? preferably making use of mysql's "insert on duplicate key update" syntax?
they have added feature upsert
or insertorupdate
/** * insert or update single row. update executed if row * matches supplied values on either primary key or unique * key found. note unique index must defined in sequelize * model , not in table. otherwise may experience unique * constraint violation, because sequelize fails identify row * should updated. */ model.upsert({uniquekey: 1234, name: 'joe'}).then(function () { // cheer joy });
Comments
Post a Comment