@@ -42,9 +42,12 @@ type NewPrivacyMapDB func(groupID session.ID) PrivacyMapDB
4242// PrivacyDB constructs a PrivacyMapDB that will be indexed under the given
4343// group ID key.
4444func (db * DB ) PrivacyDB (groupID session.ID ) PrivacyMapDB {
45- return & privacyMapDB {
46- db : db ,
47- groupID : groupID ,
45+ return & kvdbExecutor [PrivacyMapTx ]{
46+ db : db .DB ,
47+ wrapper : & privacyMapDB {
48+ db : db ,
49+ groupID : groupID ,
50+ },
4851 }
4952}
5053
@@ -78,44 +81,14 @@ type privacyMapDB struct {
7881 groupID session.ID
7982}
8083
81- // Update opens a database read/write transaction and executes the function f
82- // with the transaction passed as a parameter. After f exits, if f did not
83- // error, the transaction is committed. Otherwise, if f did error, the
84- // transaction is rolled back. If the rollback fails, the original error
85- // returned by f is still returned. If the commit fails, the commit error is
86- // returned.
84+ // wrap returns a new PrivacyMapTx that wraps the given bolt transaction.
8785//
88- // NOTE: this is part of the PrivacyMapDB interface.
89- func (p * privacyMapDB ) Update (ctx context.Context , fn func (ctx context.Context ,
90- tx PrivacyMapTx ) error ) error {
91-
92- return p .db .Update (func (tx * bbolt.Tx ) error {
93- boltTx := & privacyMapTx {
94- privacyMapDB : p ,
95- boltTx : tx ,
96- }
97-
98- return fn (ctx , boltTx )
99- })
100- }
101-
102- // View opens a database read transaction and executes the function f with the
103- // transaction passed as a parameter. After f exits, the transaction is rolled
104- // back. If f errors, its error is returned, not a rollback error (if any
105- // occur).
106- //
107- // NOTE: this is part of the PrivacyMapDB interface.
108- func (p * privacyMapDB ) View (ctx context.Context , fn func (ctx context.Context ,
109- tx PrivacyMapTx ) error ) error {
110-
111- return p .db .View (func (tx * bbolt.Tx ) error {
112- boltTx := & privacyMapTx {
113- privacyMapDB : p ,
114- boltTx : tx ,
115- }
116-
117- return fn (ctx , boltTx )
118- })
86+ // NOTE: this is part of the txWrapper interface.
87+ func (p * privacyMapDB ) wrap (tx * bbolt.Tx ) PrivacyMapTx {
88+ return & privacyMapTx {
89+ boltTx : tx ,
90+ privacyMapDB : p ,
91+ }
11992}
12093
12194// privacyMapTx is an implementation of PrivacyMapTx.
0 commit comments