V3 is in the works

This commit is contained in:
2022-04-20 16:22:43 -05:00
parent 7cc06eeddc
commit 492e3b9547
11 changed files with 458 additions and 32 deletions

View File

@@ -18,6 +18,12 @@ type BoltDB struct {
buckets []BoltBucket
}
func NewBoltDB(db *bolt.DB) *BoltDB {
b := &BoltDB{db: db}
b.RefreshDatabase()
return b
}
func (bd *BoltDB) RefreshDatabase() {
// Reload the database from the file
bd.buckets = []BoltBucket{}
@@ -47,6 +53,8 @@ func (bd *BoltDB) RefreshDatabase() {
})
}
func (bd *BoltDB) GetBuckets() []BoltBucket { return bd.buckets }
func (bd *BoltDB) GetGenericFromPath(path []string) (*BoltBucket, *BoltPair, error) {
// Check if 'path' leads to a pair
p, err := bd.GetPairFromPath(path)
@@ -592,3 +600,11 @@ func (bd *BoltDB) AddBucketFromBoltBucket(path []string, bb *BoltBucket) error {
}
return nil
}
func (bd BoltDB) Lines() []string {
var ret []string
for i := range bd.buckets {
ret = append(ret, bd.buckets[i].Lines()...)
}
return ret
}

View File

@@ -2,6 +2,7 @@ package models
import (
"errors"
"fmt"
"strings"
)
@@ -92,3 +93,26 @@ func (b *BoltBucket) GetPair(k string) (*BoltPair, error) {
}
return nil, errors.New("Pair Not Found")
}
func (b BoltBucket) Lines() []string {
var ret []string
bktPrefix := strings.Repeat(" ", len(b.GetPath())*2)
wrk := "+ "
if b.expanded {
wrk = "- "
}
wrk = fmt.Sprintf("%s%s%s", bktPrefix, wrk, b.name)
ret = append(ret, wrk)
if b.expanded {
for i := range b.buckets {
ret = append(ret, b.buckets[i].Lines()...)
}
for _, bp := range b.pairs {
prPrefix := strings.Repeat(" ", len(bp.GetPath())*2)
ret = append(ret, fmt.Sprintf("%s%s", prPrefix, bp.String()))
}
}
return ret
}
func (b BoltBucket) IsExpanded() bool { return b.expanded }

View File

@@ -1,5 +1,7 @@
package models
import "fmt"
/*
BoltPair is just a struct representation of a Pair in the Bolt DB
*/
@@ -15,3 +17,7 @@ GetPath Returns the path of the BoltPair
func (p *BoltPair) GetPath() []string {
return append(p.parent.GetPath(), p.key)
}
func (p BoltPair) String() string {
return fmt.Sprintf("%s: %s", p.key, p.val)
}