Refactor Create to separate batch and single insert logic

This commit is contained in:
KEHyeon 2025-01-25 21:32:32 +09:00
parent 9ca84b3dde
commit 8eebbb4687

View File

@ -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) {