Create/Save ignoreDuplicates Option
See original GitHub issuebulkCreate
got an ignoreDuplicates
option based on this issue.
I can see there is no ignoreDuplicates
option for create
or save
but is there a way to INSERT IGNORE
when inserting one row?
Use Case:
I am in the process of refactoring Community Casts to use sequelize.
I want to port this line of code:
return connection.queryAsync('INSERT IGNORE INTO tags VALUES ?', values);
Here is a an example:
var Tag = sequelize.define('Tag', {
name: {
type: Sequelize.STRING,
primaryKey: true
}
});
sequelize.sync({ force: true }).then(function () {
Tag.create({
name: 'Hello'
}).then(function () {
// boom!
Tag.create({
name: 'Hello'
});
});
});
And the exception:
Executing (default): INSERT INTO `Tags` (`name`,`updatedAt`,`createdAt`) VALUES ('Hello','2015-09-15 08:51:44','2015-09-15 08:51:44');
Unhandled rejection SequelizeUniqueConstraintError: Validation error
at Query.formatError (c:\Users\alexb\Documents\Code\demo\node_modules\sequelize\lib\dialects\mysql\query.js:134:14)
at Query._callback (c:\Users\alexb\Documents\Code\demo\node_modules\sequelize\lib\dialects\mysql\query.js:35:21)
at Query.Sequence.end (c:\Users\alexb\Documents\Code\demo\node_modules\mysql\lib\protocol\sequences\Sequence.js:96:24)
at Query.ErrorPacket (c:\Users\alexb\Documents\Code\demo\node_modules\mysql\lib\protocol\sequences\Query.js:94:8)
at Protocol._parsePacket (c:\Users\alexb\Documents\Code\demo\node_modules\mysql\lib\protocol\Protocol.js:274:23)
at Parser.write (c:\Users\alexb\Documents\Code\demo\node_modules\mysql\lib\protocol\Parser.js:77:12)
at Protocol.write (c:\Users\alexb\Documents\Code\demo\node_modules\mysql\lib\protocol\Protocol.js:39:16)
at Socket.<anonymous> (c:\Users\alexb\Documents\Code\demo\node_modules\mysql\lib\Connection.js:96:28)
at Socket.emit (events.js:107:17)
at readableAddChunk (_stream_readable.js:163:16)
at Socket.Readable.push (_stream_readable.js:126:10)
at TCP.onread (net.js:538:20)
Ideally I would be able to use the nested syntax:
Screencast.create({
id: '123',
title: 'Sequelize video.',
Tags: [{ name:'Sequelize' }, { name:'Node' }]
}, {
include: [Tag]
}
Issue Analytics
- State:
- Created 8 years ago
- Reactions:3
- Comments:7 (5 by maintainers)
Top Results From Across the Web
node.js - BulkCreate ignore duplicate values for custom fields
I'm looking for some way in the bulkCreate() method to specify 'ignoreDuplicates' with my custom key 'title' and then use 'updateOnDuplicate' to ...
Read more >Pinnacle Studio 25 User Guide
item or right-clicking and choosing an option from the context menu. ... Title page includes basic create, save, load and duration controls.
Read more >BulkCreateOptions | @sequelize/core
Options for Model. ... Pass query execution time in milliseconds as second argument to logging function (options.logging). ... Optional ignoreDuplicates.
Read more >SAP BusinessObjects Live Data Connect Installation and ...
This document provides SAP BusinessObjects Business Intelligence administrators with information, procedures and options for the installation of ...
Read more >Content Composer Studio - Hyland Software Products
In the Filter tab, select one of the following options. ... Select the Use SQL Server Authentication option. ... 0 = Ignore -...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@alexbooker should be possible, you could then just ignore a unique constraint error with
.catch(Sequelize.UniqueConstraintError, noop)
+1
I would be very happy to see the
ignoreDuplicates
option for a single create if anyone finds a solution.