MCPcopy
hub / github.com/etcd-io/bbolt / View

Method View

db.go:936–961  ·  view source on GitHub ↗

View executes a function within the context of a managed read-only transaction. Any error that is returned from the function is returned from the View() method. Attempting to manually rollback within the function will cause a panic.

(fn func(*Tx) error)

Source from the content-addressed store, hash-verified

934//
935// Attempting to manually rollback within the function will cause a panic.
936func (db *DB) View(fn func(*Tx) error) error {
937 t, err := db.Begin(false)
938 if err != nil {
939 return err
940 }
941
942 // Make sure the transaction rolls back in the event of a panic.
943 defer func() {
944 if t.db != nil {
945 t.rollback()
946 }
947 }()
948
949 // Mark as a managed tx so that the inner function cannot manually rollback.
950 t.managed = true
951
952 // If an error is returned from the function then pass it through.
953 err = fn(t)
954 t.managed = false
955 if err != nil {
956 _ = t.Rollback()
957 return err
958 }
959
960 return t.Rollback()
961}
962
963// Batch calls fn as part of a batch. It behaves similar to Update,
964// except:

Callers 15

MustCheckMethod · 0.95
CopyTempFileMethod · 0.95
TestCursor_SeekFunction · 0.80
TestCursor_DeleteFunction · 0.80
TestCursor_Seek_LargeFunction · 0.80
TestCursor_EmptyBucketFunction · 0.80
TestBucket_Put_LargeFunction · 0.80
TestBucket_Put_ReadOnlyFunction · 0.80

Calls 3

BeginMethod · 0.95
rollbackMethod · 0.80
RollbackMethod · 0.65

Tested by 15

TestCursor_SeekFunction · 0.64
TestCursor_DeleteFunction · 0.64
TestCursor_Seek_LargeFunction · 0.64
TestCursor_EmptyBucketFunction · 0.64
TestBucket_Put_LargeFunction · 0.64
TestBucket_Put_ReadOnlyFunction · 0.64
TestBucket_Delete_LargeFunction · 0.64
TestBucket_NestedFunction · 0.64