Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(postgres, sqlite): allow override of conflict keys for bulkCreate (
- Loading branch information
Showing
5 changed files
with
205 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { | ||
Model, | ||
InferAttributes, | ||
CreationOptional, | ||
InferCreationAttributes, | ||
} from 'sequelize'; | ||
import { sequelize } from './connection'; | ||
import type { MakeNullishOptional } from 'sequelize/types/utils'; | ||
|
||
class TestModel extends Model< | ||
InferAttributes<TestModel>, | ||
InferCreationAttributes<TestModel> | ||
> { | ||
declare id: CreationOptional<number>; | ||
declare testString: CreationOptional<string | null>; | ||
declare testEnum: CreationOptional<'d' | 'e' | 'f' | null>; | ||
} | ||
|
||
type wat = InferCreationAttributes<TestModel>; | ||
|
||
sequelize.transaction(async trx => { | ||
const newItems: Array< | ||
MakeNullishOptional<InferCreationAttributes<TestModel>> | ||
> = [ | ||
{ | ||
testEnum: 'e', | ||
testString: 'abc', | ||
}, | ||
{ | ||
testEnum: null, | ||
testString: undefined, | ||
}, | ||
]; | ||
|
||
const res1: Array<TestModel> = await TestModel.bulkCreate(newItems, { | ||
benchmark: true, | ||
fields: ['testEnum'], | ||
hooks: true, | ||
logging: true, | ||
returning: true, | ||
transaction: trx, | ||
validate: true, | ||
ignoreDuplicates: true, | ||
}); | ||
|
||
const res2: Array<TestModel> = await TestModel.bulkCreate(newItems, { | ||
benchmark: true, | ||
fields: ['testEnum'], | ||
hooks: true, | ||
logging: true, | ||
returning: false, | ||
transaction: trx, | ||
validate: true, | ||
updateOnDuplicate: ['testEnum', 'testString'], | ||
}); | ||
|
||
const res3: Array<TestModel> = await TestModel.bulkCreate(newItems, { | ||
conflictAttributes: ['testEnum', 'testString'], | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters