Comments (3)
In MySQL, this query is done using INSERT ... ON DUPLICATE KEY UPDATE
. I believe we could have a big IF statement for the updated_at
column that would look like this:
-- assumes "a" is unique
INSERT INTO daily_events (a, b, updated_at)
VALUES (1, 2, '2024-04-04 04:04:04') AS new
ON DUPLICATE KEY UPDATE
b = new.b,
updated_at = IF(a <> new.a, new.updated_at, updated_at);
Similarly, updated_at
should automatically be added to updateOnDuplicate
if updateOnDuplicate
is specified and silent
is not false
from sequelize.
Interesting, how can we do it with Sequelize? Does Sequelize support it?
Looks like Sequelize we can only provide the array of the fields, please check here
updateOnDuplicate?: Array<keyof TAttributes>;
from sequelize.
Nothing clean as far as I know. Maybe you'll have some change with Model.upsert
, but I doubt it, hence why I turned this into a feature request
from sequelize.
Related Issues (20)
- Customize toJSON() for custom serialization logic HOT 6
- Can't make table queries. TypeError: _.includes is not a function HOT 1
- DATE parse function crashes in SQLite HOT 1
- PostgreSQL. Error in getQueryInterface().describeTable() with column comments and schemas
- Unable to find dialect at HOT 2
- Cyclic sequelize sync doesn't handle several cases in the non-cyclic version HOT 1
- Introducing @EncryptedAttribute() decorator
- Add `Model.exists()` to allow efficient checking of at least one matching row
- Filter As on Properties of Associated Bs But Still Return all Bs Associated to the Resulting A's
- Feature Request: support 'schema' for MySQL HOT 1
- Merge Failure When Using Raw Where Query With Scope HOT 2
- Recieving sqlite related errors, but dialect used is postgres
- An In-Class @Scope Decorator HOT 1
- Add method for accessing #transactionCls Sequelize v7
- 使用webpack5 打包 后报错 TypeError: i is not a function HOT 2
- `unique: true` does not generate same index name and constraint in model and migrations
- Please include src/ in public package if you're going to publish source maps
- Node.js start fails on Linux platform due to invalid ELF header error HOT 1
- Weird Failure When Using this.reload(); "Cannot use offset or limit without a model or order being set" HOT 2
- Raw Queries with multiple Bind Parameters and in wrong order not working properly - (tested on Oracle)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sequelize.