Merge pull request #21 from miltkall/clean_up/use_get_db_method

cleanUp: use tx.Get for getting values from DB
This commit is contained in:
mrusme 2022-09-03 13:40:58 -05:00 committed by GitHub
commit 32ea7840ac
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,14 +1,15 @@
package z
import (
"encoding/json"
"errors"
"log"
"os"
"sort"
"strings"
"log"
"errors"
"encoding/json"
"github.com/tidwall/buntdb"
"github.com/google/uuid"
"github.com/tidwall/buntdb"
)
type Database struct {
@ -71,14 +72,13 @@ func (database *Database) GetEntry(user string, entryId string) (Entry, error) {
var entry Entry
dberr := database.DB.View(func(tx *buntdb.Tx) error {
tx.AscendKeys(user + ":entry:" + entryId, func(key, value string) bool {
json.Unmarshal([]byte(value), &entry)
entry.SetIDFromDatabaseKey(key)
return true
})
value, err := tx.Get(user + ":entry:" + entryId)
if err != nil {
return err
}
json.Unmarshal([]byte(value), &entry)
entry.ID = entryId
return nil
})
@ -164,11 +164,11 @@ func (database *Database) GetRunningEntryId(user string) (string, error) {
var runningId string = ""
dberr := database.DB.View(func(tx *buntdb.Tx) error {
tx.AscendKeys(user + ":status:running", func(key, value string) bool {
runningId = value
return true
})
value, err := tx.Get(user + ":status:running")
if err != nil {
return err
}
runningId = value
return nil
})