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 {
|
if db.CreateBatchSize > 0 {
|
||||||
return db.CreateInBatches(value, db.CreateBatchSize)
|
return db.CreateInBatches(value, db.CreateBatchSize)
|
||||||
}
|
}
|
||||||
|
return db.create(value)
|
||||||
tx = db.getInstance()
|
|
||||||
tx.Statement.Dest = value
|
|
||||||
return tx.callbacks.Create().Execute(tx)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateInBatches inserts value in batches of batchSize
|
// CreateInBatches inserts value in batches of batchSize
|
||||||
@ -63,12 +60,15 @@ func (db *DB) CreateInBatches(value interface{}, batchSize int) (tx *DB) {
|
|||||||
|
|
||||||
tx.RowsAffected = rowsAffected
|
tx.RowsAffected = rowsAffected
|
||||||
default:
|
default:
|
||||||
tx = db.getInstance()
|
db.create(value)
|
||||||
tx.Statement.Dest = value
|
|
||||||
tx = tx.callbacks.Create().Execute(tx)
|
|
||||||
}
|
}
|
||||||
return
|
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.
|
// 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) {
|
func (db *DB) Save(value interface{}) (tx *DB) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user