55
66` import "git.tcp.direct/tcp.direct/database" `
77
8- ## Documentation
9-
10- #### func AllKeepers
11-
12- ``` go
13- func AllKeepers () map [string ]KeeperCreator
14- ```
8+ > [ !WARNING]
9+ > This package is pre-v1 and the API is NOT stable!
1510
16- #### func RegisterKeeper
11+ ## Documentation
1712
1813``` go
19- func RegisterKeeper(name string, keeper KeeperCreator )
14+ var ErrKeyNotFound = errors. New ( " key not found " )
2015```
2116
2217#### type Filer
@@ -60,18 +55,28 @@ store to satisfy an overencompassing interface.
6055type Keeper interface {
6156 // Path should return the base path where all stores should be stored under. (likely as subdirectories)
6257 Path () string
58+
6359 // Init should initialize our Filer at the given path, to be referenced and called by dataStore.
6460 Init (name string , options ...any ) error
6561 // With provides access to the given dataStore by providing a pointer to the related Filer.
66- With (name string ) Store
67-
68- // WithNew should initialize a new Filer at the given path.
62+ With (name string ) Filer
63+ // WithNew should initialize a new Filer at the given path and return a pointer to it.
6964 WithNew (name string , options ...any ) Filer
7065
66+ // Destroy should remove the Filer by the given name.
67+ // It is up to the implementation to decide if the data should be removed or not.
68+ Destroy (name string ) error
69+
7170 Discover () ([]string , error )
7271
7372 AllStores () map [string ]Filer
7473
74+ // BackupAll should create a backup of all [Filer] instances in the [Keeper].
75+ BackupAll (archivePath string ) (models.Backup , error )
76+
77+ // RestoreAll should restore all [Filer] instances from the given archive.
78+ RestoreAll (archivePath string ) error
79+
7580 Meta () models.Metadata
7681
7782 Close (name string ) error
@@ -96,20 +101,174 @@ type KeeperCreator func(path string) (Keeper, error)
96101```
97102
98103
99- #### func GetKeeper
104+ #### type MockFiler
105+
106+ ```go
107+ type MockFiler struct {
108+ }
109+ ```
110+
111+
112+ #### func (* MockFiler) Backend
113+
114+ ``` go
115+ func (m *MockFiler ) Backend () any
116+ ```
117+
118+ #### func (*MockFiler) Close
119+
120+ ```go
121+ func (m *MockFiler) Close() error
122+ ```
123+
124+ #### func (*MockFiler) Delete
125+
126+ ```go
127+ func (m *MockFiler) Delete(key []byte) error
128+ ```
129+
130+ #### func (*MockFiler) Get
131+
132+ ```go
133+ func (m *MockFiler) Get(key []byte) ([]byte, error)
134+ ```
135+
136+ #### func (*MockFiler) Has
137+
138+ ```go
139+ func (m *MockFiler) Has(key []byte) bool
140+ ```
141+
142+ #### func (*MockFiler) Keys
143+
144+ ```go
145+ func (m *MockFiler) Keys() [][]byte
146+ ```
147+
148+ #### func (*MockFiler) Len
149+
150+ ```go
151+ func (m *MockFiler) Len() int
152+ ```
153+
154+ #### func (*MockFiler) Put
155+
156+ ```go
157+ func (m *MockFiler) Put(key []byte, value []byte) error
158+ ```
159+
160+ #### func (*MockFiler) Sync
161+
162+ ```go
163+ func (m *MockFiler) Sync() error
164+ ```
165+
166+ #### type MockKeeper
167+
168+ ```go
169+ type MockKeeper struct {
170+ }
171+ ```
172+
173+
174+ #### func NewMockKeeper
175+
176+ ``` go
177+ func NewMockKeeper (name string ) *MockKeeper
178+ ```
179+
180+ #### func (*MockKeeper) AllStores
181+
182+ ```go
183+ func (m *MockKeeper) AllStores() map[string]Filer
184+ ```
185+
186+ #### func (*MockKeeper) BackupAll
187+
188+ ```go
189+ func (m *MockKeeper) BackupAll(archivePath string) (models.Backup, error)
190+ ```
191+
192+ #### func (*MockKeeper) Close
193+
194+ ```go
195+ func (m *MockKeeper) Close(name string) error
196+ ```
197+
198+ #### func (*MockKeeper) CloseAll
199+
200+ ```go
201+ func (m *MockKeeper) CloseAll() error
202+ ```
203+
204+ #### func (*MockKeeper) Destroy
205+
206+ ```go
207+ func (m *MockKeeper) Destroy(name string) error
208+ ```
209+
210+ #### func (*MockKeeper) Discover
211+
212+ ```go
213+ func (m *MockKeeper) Discover() ([]string, error)
214+ ```
215+
216+ #### func (*MockKeeper) Init
217+
218+ ```go
219+ func (m *MockKeeper) Init(name string, options ...any) error
220+ ```
221+
222+ #### func (*MockKeeper) Meta
223+
224+ ```go
225+ func (m *MockKeeper) Meta() models.Metadata
226+ ```
227+
228+ #### func (*MockKeeper) Path
229+
230+ ```go
231+ func (m *MockKeeper) Path() string
232+ ```
233+
234+ #### func (*MockKeeper) RestoreAll
235+
236+ ```go
237+ func (m *MockKeeper) RestoreAll(archivePath string) error
238+ ```
239+
240+ #### func (*MockKeeper) SyncAll
241+
242+ ```go
243+ func (m *MockKeeper) SyncAll() error
244+ ```
245+
246+ #### func (*MockKeeper) SyncAndCloseAll
247+
248+ ```go
249+ func (m *MockKeeper) SyncAndCloseAll() error
250+ ```
251+
252+ #### func (*MockKeeper) With
253+
254+ ```go
255+ func (m *MockKeeper) With(name string) Filer
256+ ```
257+
258+ #### func (*MockKeeper) WithNew
100259
101260```go
102- func GetKeeper( name string) KeeperCreator
261+ func (m *MockKeeper) WithNew( name string, options ...any) Filer
103262```
104263
105264#### type Searcher
106265
107266```go
108267type Searcher interface {
109268 // PrefixScan must retrieve all keys in the datastore and stream them to the given channel.
110- PrefixScan (prefix string ) (<- chan * kv.KeyValue , chan error )
269+ PrefixScan (prefix string ) (<- chan kv.KeyValue , chan error )
111270 // Search must be able to search through the value contents of our database and stream the results to the given channel.
112- Search (query string ) (<- chan * kv.KeyValue , chan error )
271+ Search (query string ) (<- chan kv.KeyValue , chan error )
113272 // ValueExists searches for an exact match of the given value and returns the key that contains it.
114273 ValueExists (value []byte ) (key []byte , ok bool )
115274}
0 commit comments