Refactor Create to separate batch and single insert logic
This commit is contained in:
parent
9ca84b3dde
commit
8eebbb4687
@ -19,10 +19,7 @@ func (db *DB) Create(value interface{}) (tx *DB) {
|
||||
if db.CreateBatchSize > 0 {
|
||||
return db.CreateInBatches(value, db.CreateBatchSize)
|
||||
}
|
||||
|
||||
tx = db.getInstance()
|
||||
tx.Statement.Dest = value
|
||||
return tx.callbacks.Create().Execute(tx)
|
||||
return db.create(value)
|
||||
}
|
||||
|
||||
// CreateInBatches inserts value in batches of batchSize
|
||||
@ -63,12 +60,15 @@ func (db *DB) CreateInBatches(value interface{}, batchSize int) (tx *DB) {
|
||||
|
||||
tx.RowsAffected = rowsAffected
|
||||
default:
|
||||
tx = db.getInstance()
|
||||
tx.Statement.Dest = value
|
||||
tx = tx.callbacks.Create().Execute(tx)
|
||||
db.create(value)
|
||||
}
|
||||
return
|
||||
}
|
||||
func (db *DB) create(value interface{}) (tx *DB) {
|
||||
tx = db.getInstance()
|
||||
tx.Statement.Dest = value
|
||||
return tx.callbacks.Create().Execute(tx)
|
||||
}
|
||||
|
||||
// Save updates value in database. If value doesn't contain a matching primary key, value is inserted.
|
||||
func (db *DB) Save(value interface{}) (tx *DB) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user