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:
commit
32ea7840ac
1 changed files with 16 additions and 16 deletions
|
@ -1,14 +1,15 @@
|
||||||
package z
|
package z
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"log"
|
|
||||||
"errors"
|
|
||||||
"encoding/json"
|
|
||||||
"github.com/tidwall/buntdb"
|
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
|
"github.com/tidwall/buntdb"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Database struct {
|
type Database struct {
|
||||||
|
@ -71,14 +72,13 @@ func (database *Database) GetEntry(user string, entryId string) (Entry, error) {
|
||||||
var entry Entry
|
var entry Entry
|
||||||
|
|
||||||
dberr := database.DB.View(func(tx *buntdb.Tx) error {
|
dberr := database.DB.View(func(tx *buntdb.Tx) error {
|
||||||
tx.AscendKeys(user + ":entry:" + entryId, func(key, value string) bool {
|
value, err := tx.Get(user + ":entry:" + entryId)
|
||||||
json.Unmarshal([]byte(value), &entry)
|
if err != nil {
|
||||||
|
return err
|
||||||
entry.SetIDFromDatabaseKey(key)
|
}
|
||||||
|
json.Unmarshal([]byte(value), &entry)
|
||||||
return true
|
|
||||||
})
|
|
||||||
|
|
||||||
|
entry.ID = entryId
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -164,11 +164,11 @@ func (database *Database) GetRunningEntryId(user string) (string, error) {
|
||||||
var runningId string = ""
|
var runningId string = ""
|
||||||
|
|
||||||
dberr := database.DB.View(func(tx *buntdb.Tx) error {
|
dberr := database.DB.View(func(tx *buntdb.Tx) error {
|
||||||
tx.AscendKeys(user + ":status:running", func(key, value string) bool {
|
value, err := tx.Get(user + ":status:running")
|
||||||
runningId = value
|
if err != nil {
|
||||||
return true
|
return err
|
||||||
})
|
}
|
||||||
|
runningId = value
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue