forked from typeorm/typeorm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add upsert methods for the drivers that support it
This adds EntityManager#upsert, BaseEntity#upsert and EntityManager#upsert Closes: typeorm#2363
- Loading branch information
1 parent
e9366b3
commit a3b5f01
Showing
10 changed files
with
175 additions
and
12 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
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,10 @@ | ||
/** | ||
* Special options passed to Repository#upsert | ||
*/ | ||
export interface UpsertOptions<T> { | ||
|
||
/** | ||
* Define which columns to conflict on | ||
*/ | ||
conflictProperties?: ((keyof T) & string)[]; | ||
} |
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 |
---|---|---|
@@ -1,22 +1,39 @@ | ||
import {Entity} from "../../../../../src/decorator/entity/Entity"; | ||
import {PrimaryGeneratedColumn} from "../../../../../src/decorator/columns/PrimaryGeneratedColumn"; | ||
import {Column} from "../../../../../src/decorator/columns/Column"; | ||
import {CreateDateColumn,UpdateDateColumn} from "../../../../../src"; | ||
|
||
@Entity() | ||
export class Post { | ||
|
||
@PrimaryGeneratedColumn() | ||
id: number|undefined|null|string; | ||
|
||
@Column({ | ||
nullable: true, | ||
unique: true, | ||
name: "eXtErNal___id" // makes sure we test handling differing property/database names where necessary | ||
}) | ||
externalId?: string; | ||
|
||
@Column() | ||
title: string; | ||
|
||
@Column({ | ||
nullable: true, | ||
type: "date", | ||
transformer: { | ||
from: (value: any) => new Date(value), | ||
to: (value: Date) => value.toISOString(), | ||
to: (value?: Date) => value?.toISOString(), | ||
} | ||
}) | ||
dateAdded: Date; | ||
dateAdded?: Date; | ||
|
||
@CreateDateColumn() | ||
createdAt!: Date; | ||
|
||
@UpdateDateColumn({ | ||
name: "uPdAtEd___At" // makes sure we test handling differing property/database names where necessary | ||
}) | ||
updatedAt!: Date; | ||
} |
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