update
parent
0797ab1b4b
commit
95880712b8
|
@ -36,13 +36,13 @@ type (
|
||||||
)
|
)
|
||||||
|
|
||||||
type BatchWriterConfig struct {
|
type BatchWriterConfig struct {
|
||||||
channelBuffer int
|
channelBuffer int
|
||||||
batchSize int
|
batchSize int
|
||||||
batchInterval time.Duration
|
batchInterval time.Duration
|
||||||
jobNum int
|
jobNum int
|
||||||
asyncWorkerNum int
|
asyncWorkerNum int
|
||||||
duplicateUpdate *clause.OnConflict
|
clauseExpr []clause.Expression
|
||||||
debug bool
|
debug bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type BatchWriter[T any] struct {
|
type BatchWriter[T any] struct {
|
||||||
|
@ -93,9 +93,9 @@ func WithAsyncWorkerNum(v int) BatchWriterOpt {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func WithDuplicateUpdate(v *clause.OnConflict) BatchWriterOpt {
|
func WithClause(v ...clause.Expression) BatchWriterOpt {
|
||||||
return func(c *BatchWriterConfig) {
|
return func(c *BatchWriterConfig) {
|
||||||
c.duplicateUpdate = v
|
c.clauseExpr = v
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -269,8 +269,8 @@ func (bw *BatchWriter[T]) asyncWriteToDb(jobIndex int, copyDataList []T) {
|
||||||
|
|
||||||
query := bw.db.Table(bw.tableName)
|
query := bw.db.Table(bw.tableName)
|
||||||
|
|
||||||
if bw.config.duplicateUpdate != nil {
|
if len(bw.config.clauseExpr) > 0 {
|
||||||
query.Clauses(bw.config.duplicateUpdate)
|
query.Clauses(bw.config.clauseExpr...)
|
||||||
}
|
}
|
||||||
|
|
||||||
err := query.Create(copyDataList).Error
|
err := query.Create(copyDataList).Error
|
||||||
|
|
Loading…
Reference in New Issue