Skip to content

Commit

Permalink
fix(typings): upsert options (#10655)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmca authored and sushantdhiman committed Mar 30, 2019
1 parent ea5afbf commit a676eea
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
18 changes: 14 additions & 4 deletions types/lib/model.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -559,14 +559,24 @@ export interface FindOrCreateOptions extends Logging, Transactionable {
*/
export interface UpsertOptions extends Logging, Transactionable, SearchPathable {
/**
* Run validations before the row is inserted
* The fields to insert / update. Defaults to all fields
*/
validate?: boolean;
fields?: string[];

/**
* The fields to insert / update. Defaults to all fields
* Run before / after bulk create hooks?
*/
fields?: string[];
hooks?: boolean;

/**
* Return the affected rows (only for postgres)
*/
returning?: boolean;

This comment has been minimized.

Copy link
@SimonSchick

SimonSchick Mar 30, 2019

Contributor

@sushantdhiman as a note, we create a bunch of interfaces for single aspects like there, in the future it would be good if we make sure that fields like validate and hooks get their own interface to avoid duplication.


/**
* Run validations before the row is inserted
*/
validate?: boolean;
}

/**
Expand Down
20 changes: 20 additions & 0 deletions types/test/upsert.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import {Model} from "sequelize"
import {sequelize} from './connection';

class TestModel extends Model {
}

TestModel.init({}, {sequelize})

sequelize.transaction(trx => {
return TestModel.upsert({}, {
benchmark: true,
fields: ['testField'],
hooks: true,
logging: true,
returning: true,
searchPath: 'DEFAULT',
transaction: trx,
validate: true,
})
})

0 comments on commit a676eea

Please sign in to comment.