This repository has been archived by the owner on Jan 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdatabase.go
123 lines (105 loc) · 3.11 KB
/
database.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
// Kiebitz - Privacy-Friendly Appointment Scheduling
// Copyright (C) 2021-2021 The Kiebitz Authors
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version. Additional terms
// as defined in section 7 of the license (e.g. regarding attribution)
// are specified at https://kiebitz.eu/en/docs/open-source/additional-terms.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
package services
import (
"time"
)
type DatabaseDefinition struct {
Name string `json:"name"`
Description string `json:"description"`
Maker DatabaseMaker `json:"-"`
SettingsValidator SettingsValidator `json:"-"`
}
type SettingsValidator func(settings map[string]interface{}) (interface{}, error)
type DatabaseDefinitions map[string]DatabaseDefinition
type DatabaseMaker func(settings interface{}) (Database, error)
type DatabaseOps interface {
Expire(table string, key []byte, ttl time.Duration) error
ExpireAt(table string, key []byte, tm time.Time) error
Integer(table string, key []byte) Integer
List(table string, key []byte) List
Map(table string, key []byte) Map
Set(table string, key []byte) Set
SortedSet(table string, key []byte) SortedSet
Value(table string, key []byte) Value
}
type Lock interface {
Release() error
}
// A database can deliver and accept message
type Database interface {
Close() error
Open() error
Reset() error
Lock(key string, lockWait, ttl time.Duration) (Lock, error)
LockDefault(key string) (Lock, error)
DatabaseOps
}
type Object interface {
}
type Set interface {
Add([]byte) error
Has([]byte) (bool, error)
Del(key []byte) error
Members() ([]*SetEntry, error)
Object
}
type SetEntry struct {
Data []byte
}
type SortedSetEntry struct {
Score int64
Data []byte
}
type SortedSet interface {
Object
Del([]byte) (bool, error)
Add([]byte, int64) error
Range(int64, int64) ([]*SortedSetEntry, error)
RangeByScore(int64, int64) ([]*SortedSetEntry, error)
At(int64) (*SortedSetEntry, error)
Score([]byte) (int64, error)
PopMin(int64) ([]*SortedSetEntry, error)
RemoveRangeByScore(int64, int64) error
}
type List interface {
Object
}
type Map interface {
GetAll() (map[string][]byte, error)
Get(key []byte) ([]byte, error)
Del(key []byte) error
Set(key []byte, value []byte) error
Object
}
type Integer interface {
Object
Set(value int64, ttl time.Duration) error
IncrBy(int64) (int64, error)
DecrBy(int64) (int64, error)
Get() (int64, error)
Del() error
}
type Value interface {
Object
Set(value []byte, ttl time.Duration) error
Get() ([]byte, error)
Del() error
}
type BaseDatabase struct {
}