-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from sunesimonsen/ssimonsen/refactor-transacti…
…on-for-type-safety Introduce generic helper functions to make transaction type safe
- Loading branch information
Showing
8 changed files
with
63 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package blobs | ||
|
||
import "github.com/apple/foundationdb/bindings/go/src/fdb" | ||
|
||
func transact[T any](db fdb.Transactor, cb func(tr fdb.Transaction) (T, error)) (T, error) { | ||
result, err := db.Transact(func(tr fdb.Transaction) (any, error) { | ||
return cb(tr) | ||
}) | ||
|
||
return result.(T), err | ||
} | ||
|
||
func readTransact[T any](db fdb.ReadTransactor, cb func(tr fdb.ReadTransaction) (T, error)) (T, error) { | ||
result, err := db.ReadTransact(func(tr fdb.ReadTransaction) (any, error) { | ||
return cb(tr) | ||
}) | ||
|
||
return result.(T), err | ||
} | ||
|
||
func updateTransact(db fdb.Transactor, cb func(tr fdb.Transaction) error) error { | ||
_, err := db.Transact(func(tr fdb.Transaction) (any, error) { | ||
return nil, cb(tr) | ||
}) | ||
|
||
return err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters