import { EntityTarget } from '@typedorm/common' ; import { Batch } from './batch' ; export interface WriteBatchCreate < Entity > { create : { item : Entity ; } ; } export interface WriteBatchDelete < Entity , PrimaryKey > { delete : { item : EntityTarget < Entity > ; primaryKey : PrimaryKey ; } ; } export type WriteBatchItem < Entity , PrimaryKey > = WriteBatchCreate < Entity > | WriteBatchDelete < Entity , PrimaryKey > ; export class WriteBatch extends Batch < WriteBatchItem < any , any > > { add ( batchItems ) { this . items . push ( ... batchItems ) ; return this ; } addCreateItem < Entity > ( item ) { this . items . push ( { create : { item , } , } ) ; return this ; } addDeleteItem < Entity , PrimaryKey = Partial < Entity > > ( item , primaryKey ) { this . items . push ( { delete : { item , primaryKey , } , } ) ; return this ; } }