Documentation ¶
Index ¶
- Variables
- func CopyKey(db Database, src, dst []string) error
- type BadgerDatabase
- func (db *BadgerDatabase) Batch() Batch
- func (db *BadgerDatabase) Clear(key ...string) error
- func (db *BadgerDatabase) Close() error
- func (db *BadgerDatabase) Erase(key ...string)
- func (db *BadgerDatabase) Export(w io.Writer) error
- func (db *BadgerDatabase) Flush() error
- func (db *BadgerDatabase) Get(key ...string) ([]byte, error)
- func (db *BadgerDatabase) Glob(prefix []string) ([][]string, error)
- func (db *BadgerDatabase) HaveWrites() bool
- func (db *BadgerDatabase) Import(r io.Reader) error
- func (db *BadgerDatabase) Keys(fn func(key []string) error, prefix ...string) error
- func (db *BadgerDatabase) Put(val []byte, key ...string)
- func (db *BadgerDatabase) Rollback()
- type Batch
- type Database
- type DiskDatabase
- func (db *DiskDatabase) Batch() Batch
- func (db *DiskDatabase) Clear(key ...string) error
- func (db *DiskDatabase) Close() error
- func (db *DiskDatabase) Erase(key ...string)
- func (db *DiskDatabase) Export(w io.Writer) error
- func (db *DiskDatabase) Flush() error
- func (db *DiskDatabase) Get(key ...string) ([]byte, error)
- func (db *DiskDatabase) Glob(prefix []string) ([][]string, error)
- func (db *DiskDatabase) HaveWrites() bool
- func (db *DiskDatabase) Import(r io.Reader) error
- func (db *DiskDatabase) Keys(fn func(key []string) error, prefix ...string) error
- func (db *DiskDatabase) Put(val []byte, key ...string)
- func (db *DiskDatabase) Rollback()
- type MemoryDatabase
- func (mdb *MemoryDatabase) Batch() Batch
- func (mdb *MemoryDatabase) Clear(key ...string) error
- func (mdb *MemoryDatabase) Close() error
- func (mdb *MemoryDatabase) Erase(key ...string)
- func (mdb *MemoryDatabase) Export(w io.Writer) error
- func (mdb *MemoryDatabase) Flush() error
- func (mdb *MemoryDatabase) Get(key ...string) ([]byte, error)
- func (mdb *MemoryDatabase) Glob(prefix []string) ([][]string, error)
- func (mdb *MemoryDatabase) HaveWrites() bool
- func (mdb *MemoryDatabase) Import(r io.Reader) error
- func (mdb *MemoryDatabase) Keys(fn func(key []string) error, prefix ...string) error
- func (mdb *MemoryDatabase) Put(data []byte, key ...string)
- func (mdb *MemoryDatabase) Rollback()
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNoSuchKey is returned when Get() was passed a non-existent key ErrNoSuchKey = errors.New("This key does not exist") )
Functions ¶
Types ¶
type BadgerDatabase ¶ added in v0.2.0
type BadgerDatabase struct {
// contains filtered or unexported fields
}
BadgerDatabase is a database implementation based on BadgerDB
func NewBadgerDatabase ¶ added in v0.2.0
func NewBadgerDatabase(path string) (*BadgerDatabase, error)
NewBadgerDatabase creates a new badger database.
func (*BadgerDatabase) Batch ¶ added in v0.2.0
func (db *BadgerDatabase) Batch() Batch
Batch is the badger implementation of Database.Batch
func (*BadgerDatabase) Clear ¶ added in v0.2.0
func (db *BadgerDatabase) Clear(key ...string) error
Clear is the badger implementation of Database.Clear
func (*BadgerDatabase) Close ¶ added in v0.2.0
func (db *BadgerDatabase) Close() error
Close is the badger implementation of Database.Close
func (*BadgerDatabase) Erase ¶ added in v0.2.0
func (db *BadgerDatabase) Erase(key ...string)
Erase is the badger implementation of Database.Erase
func (*BadgerDatabase) Export ¶ added in v0.2.0
func (db *BadgerDatabase) Export(w io.Writer) error
Export is the badger implementation of Database.Export.
func (*BadgerDatabase) Flush ¶ added in v0.2.0
func (db *BadgerDatabase) Flush() error
Flush is the badger implementation of Database.Flush
func (*BadgerDatabase) Get ¶ added in v0.2.0
func (db *BadgerDatabase) Get(key ...string) ([]byte, error)
Get is the badger implementation of Database.Get.
func (*BadgerDatabase) Glob ¶ added in v0.2.0
func (db *BadgerDatabase) Glob(prefix []string) ([][]string, error)
Glob is the badger implementation of Database.Glob
func (*BadgerDatabase) HaveWrites ¶ added in v0.2.0
func (db *BadgerDatabase) HaveWrites() bool
HaveWrites is the badger implementation of Database.HaveWrites
func (*BadgerDatabase) Import ¶ added in v0.2.0
func (db *BadgerDatabase) Import(r io.Reader) error
Import is the badger implementation of Database.Import.
func (*BadgerDatabase) Keys ¶ added in v0.2.0
func (db *BadgerDatabase) Keys(fn func(key []string) error, prefix ...string) error
Keys is the badger implementation of Database.Keys.
func (*BadgerDatabase) Put ¶ added in v0.2.0
func (db *BadgerDatabase) Put(val []byte, key ...string)
Put is the badger implementation of Database.Put
func (*BadgerDatabase) Rollback ¶ added in v0.2.0
func (db *BadgerDatabase) Rollback()
Rollback is the badger implementation of Database.Rollback
type Batch ¶
type Batch interface { // Put sets `val` at `key`. Put(val []byte, key ...string) // Clear all contents below and including `key`. Clear(key ...string) error // Erase a key from the database. Erase(key ...string) // Flush the batch to the database. // Only now, all changes will be written to disk. Flush() error // Rollback will forget all changes without executing them. Rollback() // HaveWrites returns true when the batch contains something // we can write to the disk on Flush(). HaveWrites() bool }
Batch is an API object used to model a transaction.
type Database ¶
type Database interface { // Get retrievies the key `key` out of bucket. // If no such key exists, it will return (nil, ErrNoSuchKey) // If a badge is currently open, Get() shall still return the // most current value currently set by the last Put() call // to `key`. Get(key ...string) ([]byte, error) // Keys iterates over all keys in the database If the error is returned by // `fn` the iteration stops and the error value is returned. // The keys are returned in lexical ordering. Keys(fn func(key []string) error, prefix ...string) error // Batch returns a new Batch object, that will allow modifications // of the state. Batch() can be called recursive: The changes will // only be flushed to disk if batch.Flush() was called equal times // to the number Batch() was called. Batch() Batch // Export backups all database content to `w` in // an implemenation specific format that can be read by Import. Export(w io.Writer) error // Import reads a previously exported db dump by Export from `r`. // Existing keys might be overwritten if the dump also contains them. Import(r io.Reader) error // Close closes the database. Since I/O may happen, an error is returned. Close() error // Glob finds all existing keys in the store, starting with prefix. Glob(prefix []string) ([][]string, error) }
Database is a key/value store that offers different buckets for storage. Keys are strings, values are arbitrary untyped data.
type DiskDatabase ¶
type DiskDatabase struct {
// contains filtered or unexported fields
}
DiskDatabase is a database that simply uses the filesystem as storage. Each bucket is one directory. Leaf keys are simple files. The exported form of the database is simply a gzipped .tar of the directory.
Note that this database backends was written for easy debugging. It is currently by no means optimized for fast reads and writes and could be probably made a lot faster if we ever need that.
func NewDiskDatabase ¶
func NewDiskDatabase(basePath string) (*DiskDatabase, error)
NewDiskDatabase creates a new database at `basePath`.
func (*DiskDatabase) Batch ¶
func (db *DiskDatabase) Batch() Batch
Batch is the disk implementation of Database.Batch
func (*DiskDatabase) Clear ¶
func (db *DiskDatabase) Clear(key ...string) error
Clear removes all keys below and including `key`.
func (*DiskDatabase) Erase ¶
func (db *DiskDatabase) Erase(key ...string)
Erase is the disk implementation of Database.Erase
func (*DiskDatabase) Export ¶
func (db *DiskDatabase) Export(w io.Writer) error
Export writes all key/values into a gzipped .tar that is written to `w`.
func (*DiskDatabase) Flush ¶
func (db *DiskDatabase) Flush() error
Flush is the disk implementation of Database.Flush
func (*DiskDatabase) Get ¶
func (db *DiskDatabase) Get(key ...string) ([]byte, error)
Get a single value from `bucket` by `key`.
func (*DiskDatabase) Glob ¶
func (db *DiskDatabase) Glob(prefix []string) ([][]string, error)
Glob is the disk implementation of Database.Glob
func (*DiskDatabase) HaveWrites ¶
func (db *DiskDatabase) HaveWrites() bool
HaveWrites is the disk implementation of Database.HaveWrites
func (*DiskDatabase) Import ¶
func (db *DiskDatabase) Import(r io.Reader) error
Import a gzipped tar from `r` into the current database.
func (*DiskDatabase) Keys ¶
func (db *DiskDatabase) Keys(fn func(key []string) error, prefix ...string) error
Keys is the disk implementation of Database.Keys
func (*DiskDatabase) Put ¶
func (db *DiskDatabase) Put(val []byte, key ...string)
Put stores a new `val` under `key` at `bucket`. Implementation detail: `key` may contain slashes (/). If used, those keys will result in a nested directory structure.
func (*DiskDatabase) Rollback ¶
func (db *DiskDatabase) Rollback()
Rollback is the disk implementation of Database.Rollback
type MemoryDatabase ¶
type MemoryDatabase struct {
// contains filtered or unexported fields
}
MemoryDatabase is a purely in memory database.
func NewMemoryDatabase ¶
func NewMemoryDatabase() *MemoryDatabase
NewMemoryDatabase allocates a new empty MemoryDatabase
func (*MemoryDatabase) Batch ¶
func (mdb *MemoryDatabase) Batch() Batch
Batch is a no-op for a memory database.
func (*MemoryDatabase) Clear ¶
func (mdb *MemoryDatabase) Clear(key ...string) error
Clear removes all keys includin and below `key`.
func (*MemoryDatabase) Export ¶
func (mdb *MemoryDatabase) Export(w io.Writer) error
Export encodes the internal memory map to a gob structure, and writes it to `w`.
func (*MemoryDatabase) Flush ¶
func (mdb *MemoryDatabase) Flush() error
Flush is a no-op for a memory database.
func (*MemoryDatabase) Get ¶
func (mdb *MemoryDatabase) Get(key ...string) ([]byte, error)
Get returns `key` of `bucket`.
func (*MemoryDatabase) Glob ¶
func (mdb *MemoryDatabase) Glob(prefix []string) ([][]string, error)
Glob returns all keys starting with `prefix`.
func (*MemoryDatabase) HaveWrites ¶
func (mdb *MemoryDatabase) HaveWrites() bool
HaveWrites returns true if there are any open writes.
func (*MemoryDatabase) Import ¶
func (mdb *MemoryDatabase) Import(r io.Reader) error
Import imports a previously exported dump and decodes the gob structure.
func (*MemoryDatabase) Keys ¶
func (mdb *MemoryDatabase) Keys(fn func(key []string) error, prefix ...string) error
Keys will return all keys currently stored in the memory map
func (*MemoryDatabase) Put ¶
func (mdb *MemoryDatabase) Put(data []byte, key ...string)
Put sets `key` in `bucket` to `data`.
func (*MemoryDatabase) Rollback ¶
func (mdb *MemoryDatabase) Rollback()
Rollback is a no-op for a memory database