From a3f7387ff146226f31a03906591cbb0d0e64cb44 Mon Sep 17 00:00:00 2001 From: Sida Chen Date: Fri, 19 Oct 2018 16:33:07 -0400 Subject: [PATCH] database: Add FindKeyValue function wrapper --- database/dbutil.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/database/dbutil.go b/database/dbutil.go index 9e1c753a..474c6a9e 100644 --- a/database/dbutil.go +++ b/database/dbutil.go @@ -53,6 +53,20 @@ func ConvertFeatureSetToFeatures(features mapset.Set) []Feature { return uniqueFeatures } +// FindKeyValueAndRollback wraps session FindKeyValue function with begin and +// roll back. +func FindKeyValueAndRollback(datastore Datastore, key string) (value string, ok bool, err error) { + var tx Session + tx, err = datastore.Begin() + if err != nil { + return + } + defer tx.Rollback() + + value, ok, err = tx.FindKeyValue(key) + return +} + // PersistPartialLayerAndCommit wraps session PersistLayer function with begin and // commit. func PersistPartialLayerAndCommit(datastore Datastore, layer *Layer) error {