Documentation
¶
Overview ¶
Package db defines a standard interface for interaction with the FluidFS cache, implemented as an embedded key/value store. This package also provides driver implementations for BoltDB and LevelDB.
Index ¶
- Constants
- Variables
- type BoltDB
- func (bdb *BoltDB) Batch(keys [][]byte, values [][]byte, bucket string) error
- func (bdb *BoltDB) Close() error
- func (bdb *BoltDB) Delete(key []byte, bucket string) error
- func (bdb *BoltDB) Get(key []byte, bucket string) ([]byte, error)
- func (bdb *BoltDB) Init(path string) error
- func (bdb *BoltDB) Keys(bucket string) (*Cursor, error)
- func (bdb *BoltDB) Put(key []byte, value []byte, bucket string) error
- func (bdb *BoltDB) Scan(prefix []byte, bucket string) (*Cursor, error)
- type Config
- type Cursor
- type Database
- type LevelDB
- func (ldb *LevelDB) Batch(keys [][]byte, values [][]byte, bucket string) error
- func (ldb *LevelDB) Close() error
- func (ldb *LevelDB) CreateBucket(bucket string, key []byte) []byte
- func (ldb *LevelDB) Delete(key []byte, bucket string) error
- func (ldb *LevelDB) Get(key []byte, bucket string) ([]byte, error)
- func (ldb *LevelDB) Init(path string) error
- func (ldb *LevelDB) Keys(bucket string) (*Cursor, error)
- func (ldb *LevelDB) Put(key []byte, value []byte, bucket string) error
- func (ldb *LevelDB) Scan(prefix []byte, bucket string) (*Cursor, error)
Constants ¶
const ( NamesBucket = "names" VersionsBucket = "versions" PrefixesBucket = "prefixes" )
Bucket names or prefixes used in the FluidFS application
const ( BoltDBDriver = "boltdb" LevelDBDriver = "leveldb" )
Driver names for quick lookups and references
Variables ¶
var DriverNames = []string{BoltDBDriver, LevelDBDriver}
DriverNames of available drivers for validation
Functions ¶
This section is empty.
Types ¶
type BoltDB ¶
type BoltDB struct {
// contains filtered or unexported fields
}
BoltDB implements the Database interface, wrapping the BoltDB library.
func (*BoltDB) Batch ¶
Batch insert key/value pairs into a bucket using BoltDB batch transactions. Wanted the input to be a mapping, but you can't use a slice as a map key.
func (*BoltDB) Init ¶
Init opens a BoltDB file (creating the file if it doesn't already exist) and initializes the buckets if they haven't already been created.
type Config ¶
type Config interface {
GetDriver() string // Return a string representing a driver
GetPath() string // Return the path to the database on disk
}
Config defines a methods that a struct should provide to be considered a database configuration, and to pass options to initialization.
type Cursor ¶
type Cursor interface {
Next() ([]byte, []byte) // Returns the next key/value pair
Error() error // Returns any errors on the cursor
}
Cursor is an interator interface that enables iteration/search over multiple key/value pairs with a single query.
type Database ¶
type Database interface {
Init(path string) error // Open a connection to the database and configure
Close() error // Close the connection to the database
Get(key []byte, bucket string) ([]byte, error) // Get a value for a key from a bucket
Put(key []byte, value []byte, bucket string) error // Put a key/value pair into the bucket
Delete(key []byte, bucket string) error // Delete a key from a bucket
Batch(keys [][]byte, values [][]byte, bucket string) error // Batch insert key/value pairs into a bucket
Scan(prefix []byte, bucket string) (*Cursor, error) // Scan a group of keys with a particular prefix
Keys(bucket string) (*Cursor, error) // Returns all the keys for a bucket
}
Database defines the methods required by a key/value store to be used by the fluid API. We use a general key/value framework with buckets.
func InitDatabase ¶
InitDatabase uses a database configuration object to select an appropriate driver that implements the Database interface and initializes it.
type LevelDB ¶
type LevelDB struct {
// contains filtered or unexported fields
}
LevelDB implements the Database interface, wrapping the LevelDB library.
func (*LevelDB) CreateBucket ¶
CreateBucket modifies a key using the bucket name as a prefix.
func (*LevelDB) Get ¶
Get a value for a key from a bucket using the LevelDB API NOTE: To maintain compatibility with the BoltDB API this function does not return an error on NotFound but rather returns nil value and nil error.
func (*LevelDB) Init ¶
Init opens a LevelDB file (creating the file if it doesn't already exist) and initializes the buckets if they haven't already been created.