-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstore.go
74 lines (60 loc) · 1.93 KB
/
store.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package godata
import (
"errors"
"github.com/beranek1/godatainterface"
)
// Wrapper for DataManager to support godatainterface definitions
type DataStore struct {
manager *DataManager
}
func Create(path string) (*DataStore, error) {
manager, err := Manage(path)
if err != nil {
return &DataStore{}, err
}
return &DataStore{manager: manager}, nil
}
func (ds DataStore) Put(key string, value any) error {
if ds.manager.InsertData(key, value) {
return nil
}
return errors.New("inserting data unsuccesful")
}
func (ds DataStore) PutAt(key string, value any, timestamp int64) error {
if ds.manager.InsertDataAt(key, value, timestamp) {
return nil
}
return errors.New("inserting data unsuccesful")
}
func (ds DataStore) Get(key string) (any, error) {
value := ds.manager.GetData(key)
if value == nil {
return value, errors.New("data not found")
}
return value, nil
}
func (ds DataStore) GetAt(key string, timestamp int64) (any, error) {
value := ds.manager.GetDataAt(key, timestamp)
if value == nil {
return value, errors.New("data not found")
}
return value, nil
}
func (ds DataStore) Range(key string, start int64, end int64) (godatainterface.DataVersionLinked, error) {
return ds.manager.GetDataRange(key, start, end), nil
}
func (ds DataStore) From(key string, start int64) (godatainterface.DataVersionLinked, error) {
return ds.manager.GetDataFrom(key, start), nil
}
func (ds DataStore) RangeInterval(key string, start int64, end int64, interval int64) (godatainterface.DataVersionLinked, error) {
return ds.manager.GetDataRangeInterval(key, start, end, interval), nil
}
func (ds DataStore) FromInterval(key string, start int64, interval int64) (godatainterface.DataVersionLinked, error) {
return ds.manager.GetDataFromInterval(key, start, interval), nil
}
func (ds DataStore) DeleteVersionsAt(timestamp int64) {
ds.manager.DeleteVersionsAt(timestamp)
}
func (ds DataStore) PersistChanges() {
ds.manager.PersistChanges()
}