Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support upsert operation #123

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Support upsert operation
  • Loading branch information
mihajul committed Aug 9, 2022
commit acea92bba2b4e1f6765a28f174cdb6c82d6a9641
10 changes: 10 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,10 @@ exports.init = (sequelize, optionsArg) => {
}

const destroyOperation = operation === 'destroy';
const upsertOperation = operation === 'upsert';
if (upsertOperation) {
instance = opt.instance;
}

let previousVersion = {};
let currentVersion = {};
Expand Down Expand Up @@ -318,6 +322,10 @@ exports.init = (sequelize, optionsArg) => {
}

const destroyOperation = operation === 'destroy';
const upsertOperation = operation === 'upsert';
if (upsertOperation) {
instance = opt.instance;
}

if (
instance.context &&
Expand Down Expand Up @@ -570,9 +578,11 @@ exports.init = (sequelize, optionsArg) => {
this.addHook('beforeCreate', createBeforeHook('create'));
this.addHook('beforeDestroy', createBeforeHook('destroy'));
this.addHook('beforeUpdate', createBeforeHook('update'));
this.addHook('beforeUpsert', createBeforeHook('upsert'));
this.addHook('afterCreate', createAfterHook('create'));
this.addHook('afterDestroy', createAfterHook('destroy'));
this.addHook('afterUpdate', createAfterHook('update'));
this.addHook('afterUpsert', createAfterHook('upsert'));

// create association
return this.hasMany(sequelize.models[options.revisionModel], {
Expand Down