@@ -731,67 +731,25 @@ func (db *DB) CreateIgnoreStreamed(
731731 )
732732}
733733
734- func WithOnSuccessUpsert (onSuccess ... OnSuccess [Entity ]) ExecOption {
735- return func (options * ExecOptions ) {
736- options .onSuccess = onSuccess
737- }
738- }
739-
740- func WithStatement (stmt string , placeholders int ) ExecOption {
741- return func (options * ExecOptions ) {
742- options .stmt = stmt
743- options .placeholders = placeholders
744- }
745- }
746-
747- type ExecOption func (options * ExecOptions )
748-
749- type ExecOptions struct {
750- onSuccess []OnSuccess [Entity ]
751- stmt string
752- placeholders int
753- }
754-
755- func NewExecOptions (execOpts ... ExecOption ) * ExecOptions {
756- execOptions := & ExecOptions {}
757-
758- for _ , option := range execOpts {
759- option (execOptions )
760- }
761-
762- return execOptions
763- }
764-
765734// UpsertStreamed bulk upserts the specified entities via NamedBulkExec.
766735// The upsert statement is created using BuildUpsertStmt with the first entity from the entities stream.
767736// Bulk size is controlled via Options.MaxPlaceholdersPerStatement and
768737// concurrency is controlled via Options.MaxConnectionsPerTable.
769738// Entities for which the query ran successfully will be passed to onSuccess.
770739func (db * DB ) UpsertStreamed (
771- ctx context.Context , entities <- chan Entity , execOpts ... ExecOption ,
740+ ctx context.Context , entities <- chan Entity , onSuccess ... OnSuccess [ Entity ] ,
772741) error {
773-
774- execOptions := NewExecOptions (execOpts ... )
775-
776742 first , forward , err := com .CopyFirst (ctx , entities )
777743 if err != nil {
778744 return errors .Wrap (err , "can't copy first entity" )
779745 }
780746
781747 sem := db .GetSemaphoreForTable (TableName (first ))
782- var stmt string
783- var placeholders int
784-
785- if execOptions .stmt != "" {
786- stmt = execOptions .stmt
787- placeholders = execOptions .placeholders
788- } else {
789- stmt , placeholders = db .BuildUpsertStmt (first )
790- }
748+ stmt , placeholders := db .BuildUpsertStmt (first )
791749
792750 return db .NamedBulkExec (
793751 ctx , stmt , db .BatchSizeByPlaceholders (placeholders ), sem ,
794- forward , SplitOnDupId [Entity ], execOptions . onSuccess ... ,
752+ forward , SplitOnDupId [Entity ], onSuccess ... ,
795753 )
796754}
797755
@@ -810,58 +768,17 @@ func (db *DB) UpdateStreamed(ctx context.Context, entities <-chan Entity) error
810768 return db .NamedBulkExecTx (ctx , stmt , db .Options .MaxRowsPerTransaction , sem , forward )
811769}
812770
813- func WithOnSuccessDelete (onSuccess ... OnSuccess [any ]) DeleteOption {
814- return func (options * DeleteOptions ) {
815- options .onSuccess = onSuccess
816- }
817- }
818-
819- func ByColumn (column string ) DeleteOption {
820- return func (options * DeleteOptions ) {
821- options .column = column
822- }
823- }
824-
825- type DeleteOption func (options * DeleteOptions )
826-
827- type DeleteOptions struct {
828- onSuccess []OnSuccess [any ]
829- column string
830- }
831-
832- func NewDeleteOptions (execOpts ... DeleteOption ) * DeleteOptions {
833- deleteOptions := & DeleteOptions {}
834-
835- for _ , option := range execOpts {
836- option (deleteOptions )
837- }
838-
839- return deleteOptions
840- }
841-
842771// DeleteStreamed bulk deletes the specified ids via BulkExec.
843772// The delete statement is created using BuildDeleteStmt with the passed entityType.
844773// Bulk size is controlled via Options.MaxPlaceholdersPerStatement and
845774// concurrency is controlled via Options.MaxConnectionsPerTable.
846775// IDs for which the query ran successfully will be passed to onSuccess.
847776func (db * DB ) DeleteStreamed (
848- ctx context.Context , entityType Entity , ids <- chan interface {}, deleteOpts ... DeleteOption ,
777+ ctx context.Context , entityType Entity , ids <- chan interface {}, onSuccess ... OnSuccess [ any ] ,
849778) error {
850-
851- deleteOptions := NewDeleteOptions (deleteOpts ... )
852-
853779 sem := db .GetSemaphoreForTable (TableName (entityType ))
854-
855- var stmt string
856-
857- if deleteOptions .column != "" {
858- stmt = fmt .Sprintf ("DELETE FROM %s WHERE %s IN (?)" , TableName (entityType ), deleteOptions .column )
859- } else {
860- stmt = db .BuildDeleteStmt (entityType )
861- }
862-
863780 return db .BulkExec (
864- ctx , stmt , db .Options .MaxPlaceholdersPerStatement , sem , ids , deleteOptions . onSuccess ... ,
781+ ctx , db . BuildDeleteStmt ( entityType ) , db .Options .MaxPlaceholdersPerStatement , sem , ids , onSuccess ... ,
865782 )
866783}
867784
@@ -877,7 +794,7 @@ func (db *DB) Delete(
877794 }
878795 close (idsCh )
879796
880- return db .DeleteStreamed (ctx , entityType , idsCh , WithOnSuccessDelete ( onSuccess ... ) )
797+ return db .DeleteStreamed (ctx , entityType , idsCh , onSuccess ... )
881798}
882799
883800// ExecTx executes the provided function within a database transaction.
0 commit comments