diff options
author | Jakob Borg <jakob@kastelo.net> | 2018-10-10 11:34:24 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-10 11:34:24 +0200 |
commit | b50d57b7fd84fc767661c60bb3ab53d0d3582d05 (patch) | |
tree | 1bf9702ef77eee3f9a279f9975c59117bfb56805 /lib/db/namespaced.go | |
parent | 8e645ab7829c22a3a7168e4ab10c1fb3c59fa5ea (diff) |
lib/db: Refactor: use a Lowlevel type underneath Instance (ref #5198) (#5212)
This adds a thin type that holds the state associated with the
leveldb.DB, leaving the huge Instance type more or less stateless. Also
moves some keying stuff into the DB package so that other packages need
not know the keying specifics.
(This does not, yet, fix the cmd/stindex program, in order to keep the
diff size down. Hence the keying constants are still exported.)
Diffstat (limited to 'lib/db/namespaced.go')
-rw-r--r-- | lib/db/namespaced.go | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/lib/db/namespaced.go b/lib/db/namespaced.go index edbdd127c8..7a26bdff52 100644 --- a/lib/db/namespaced.go +++ b/lib/db/namespaced.go @@ -17,13 +17,13 @@ import ( // NamespacedKV is a simple key-value store using a specific namespace within // a leveldb. type NamespacedKV struct { - db *Instance + db *Lowlevel prefix []byte } // NewNamespacedKV returns a new NamespacedKV that lives in the namespace // specified by the prefix. -func NewNamespacedKV(db *Instance, prefix string) *NamespacedKV { +func NewNamespacedKV(db *Lowlevel, prefix string) *NamespacedKV { return &NamespacedKV{ db: db, prefix: []byte(prefix), @@ -157,3 +157,23 @@ func (n NamespacedKV) Delete(key string) { keyBs := append(n.prefix, []byte(key)...) n.db.Delete(keyBs, nil) } + +// Well known namespaces that can be instantiated without knowing the key +// details. + +// NewDeviceStatisticsNamespace creates a KV namespace for device statistics +// for the given device. +func NewDeviceStatisticsNamespace(db *Lowlevel, device string) *NamespacedKV { + return NewNamespacedKV(db, string(KeyTypeDeviceStatistic)+device) +} + +// NewFolderStatisticsNamespace creates a KV namespace for folder statistics +// for the given folder. +func NewFolderStatisticsNamespace(db *Lowlevel, folder string) *NamespacedKV { + return NewNamespacedKV(db, string(KeyTypeFolderStatistic)+folder) +} + +// NewMiscDateNamespace creates a KV namespace for miscellaneous metadata. +func NewMiscDataNamespace(db *Lowlevel) *NamespacedKV { + return NewNamespacedKV(db, string(KeyTypeMiscData)) +} |