2022-01-01 21:22:09 +00:00
|
|
|
# database
|
2022-01-01 22:45:15 +00:00
|
|
|
|
2022-08-29 06:44:32 +00:00
|
|
|
[![Coverage](https://codecov.io/gh/tcp-direct/database/branch/master/graph/badge.svg)](https://codecov.io/gh/tcp-direct/database)
|
|
|
|
[![Build Status](https://github.com/tcp-direct/database/actions/workflows/go.yml/badge.svg?branch=master)](https://github.com/tcp-direct/database/actions/workflows/go.yml)
|
2022-01-09 01:49:06 +00:00
|
|
|
|
2022-02-23 15:53:55 +00:00
|
|
|
`import "git.tcp.direct/tcp.direct/database"`
|
2022-02-12 08:11:09 +00:00
|
|
|
|
|
|
|
## Documentation
|
2022-01-01 22:45:15 +00:00
|
|
|
|
|
|
|
#### type Filer
|
|
|
|
|
|
|
|
```go
|
|
|
|
type Filer interface {
|
|
|
|
|
2022-07-26 04:57:01 +00:00
|
|
|
// Backend returns the underlying key/value store.
|
|
|
|
Backend() any
|
|
|
|
|
2022-01-01 22:45:15 +00:00
|
|
|
// Has should return true if the given key has an associated value.
|
|
|
|
Has(key []byte) bool
|
|
|
|
// Get should retrieve the byte slice corresponding to the given key, and any associated errors upon failure.
|
|
|
|
Get(key []byte) ([]byte, error)
|
|
|
|
// Put should insert the value data in a way that is associated and can be retrieved by the given key data.
|
|
|
|
Put(key []byte, value []byte) error
|
|
|
|
// Delete should delete the key and the value associated with the given key, and return an error upon failure.
|
|
|
|
Delete(key []byte) error
|
2022-07-26 04:57:01 +00:00
|
|
|
// Close should safely end any Filer operations of the given dataStore and close any relevant handlers.
|
|
|
|
Close() error
|
|
|
|
// Sync should take any volatile data and solidify it somehow if relevant. (ram to disk in most cases)
|
|
|
|
Sync() error
|
2022-08-29 06:44:32 +00:00
|
|
|
|
|
|
|
Keys() [][]byte
|
|
|
|
Len() int
|
2022-01-01 22:45:15 +00:00
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
Filer is is a way to implement any generic key/value store. These functions
|
|
|
|
should be plug and play with most of the popular key/value store golang
|
|
|
|
libraries.
|
|
|
|
|
2022-01-09 06:09:53 +00:00
|
|
|
NOTE: Many key/value golang libraries will already implement this interface
|
|
|
|
already. This exists for more potential granular control in the case that they
|
|
|
|
don't. Otherwise you'd have to build a wrapper around an existing key/value
|
|
|
|
store to satisfy an overencompassing interface.
|
|
|
|
|
2022-01-01 22:45:15 +00:00
|
|
|
#### type Keeper
|
|
|
|
|
|
|
|
```go
|
|
|
|
type Keeper interface {
|
2022-01-19 09:46:51 +00:00
|
|
|
// Path should return the base path where all stores should be stored under. (likely as subdirectories)
|
2022-01-01 22:45:15 +00:00
|
|
|
Path() string
|
2022-02-12 08:11:09 +00:00
|
|
|
// Init should initialize our Filer at the given path, to be referenced and called by dataStore.
|
2022-07-26 04:57:01 +00:00
|
|
|
Init(name string, options ...any) error
|
2022-02-12 08:11:09 +00:00
|
|
|
// With provides access to the given dataStore by providing a pointer to the related Filer.
|
2022-07-26 04:57:01 +00:00
|
|
|
With(name string) Store
|
|
|
|
|
2022-08-29 07:44:21 +00:00
|
|
|
AllStores() map[string]Filer
|
2022-01-01 22:45:15 +00:00
|
|
|
|
|
|
|
CloseAll() error
|
|
|
|
SyncAll() error
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
Keeper will be in charge of the more meta operations involving Filers. This
|
|
|
|
includes operations like initialization, syncing to disk if applicable, and
|
|
|
|
backing up.
|
|
|
|
|
|
|
|
#### type Searcher
|
|
|
|
|
|
|
|
```go
|
|
|
|
type Searcher interface {
|
2022-07-26 04:57:01 +00:00
|
|
|
// PrefixScan must retrieve all keys in the datastore and stream them to the given channel.
|
|
|
|
PrefixScan(prefix string) (<-chan *kv.KeyValue, chan error)
|
|
|
|
// Search must be able to search through the value contents of our database and stream the results to the given channel.
|
|
|
|
Search(query string) (<-chan *kv.KeyValue, chan error)
|
2022-01-01 22:45:15 +00:00
|
|
|
// ValueExists searches for an exact match of the given value and returns the key that contains it.
|
|
|
|
ValueExists(value []byte) (key []byte, ok bool)
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
Searcher must be able to search through our datastore(s) with strings.
|
2022-01-09 05:54:44 +00:00
|
|
|
|
2022-07-26 04:57:01 +00:00
|
|
|
#### type Store
|
2022-01-09 05:54:44 +00:00
|
|
|
|
|
|
|
```go
|
2022-07-26 04:57:01 +00:00
|
|
|
type Store interface {
|
|
|
|
Filer
|
|
|
|
Searcher
|
2022-01-09 05:54:44 +00:00
|
|
|
}
|
|
|
|
```
|
2022-08-29 06:44:32 +00:00
|
|
|
|
|
|
|
Store is an implementation of a Filer and a Searcher.
|