mirror of
https://github.com/luxfi/vm.git
synced 2026-10-30 15:13:40 +00:00
23 lines
764 B
Go
23 lines
764 B
Go
// Copyright (C) 2019-2025, Lux Industries, Inc. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
package atomic
|
|
|
|
import "github.com/luxfi/database"
|
|
|
|
// WriteAll writes all of the batches to the underlying database of baseBatch.
|
|
// Assumes all batches have the same underlying database.
|
|
func WriteAll(baseBatch database.Batch, batches ...database.Batch) error {
|
|
baseBatch = baseBatch.Inner()
|
|
// Replay the inner batches onto [baseBatch] so that it includes all DB
|
|
// operations as they would be applied to the base database.
|
|
for _, batch := range batches {
|
|
batch = batch.Inner()
|
|
if err := batch.Replay(baseBatch); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
// Write all of the combined operations in one atomic batch.
|
|
return baseBatch.Write()
|
|
}
|