db

package
v0.0.0-...-d698e09 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 20, 2017 License: MIT Imports: 5 Imported by: 0

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

View Source
const (
	NamesBucket    = "names"
	VersionsBucket = "versions"
	PrefixesBucket = "prefixes"
)

Bucket names or prefixes used in the FluidFS application

View Source
const (
	BoltDBDriver  = "boltdb"
	LevelDBDriver = "leveldb"
)

Driver names for quick lookups and references

Variables

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

func (bdb *BoltDB) Batch(keys [][]byte, values [][]byte, bucket string) error

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) Close

func (bdb *BoltDB) Close() error

Close the connection to the BoltDB

func (*BoltDB) Delete

func (bdb *BoltDB) Delete(key []byte, bucket string) error

Delete a key from a bucket using BoltDB transaction

func (*BoltDB) Get

func (bdb *BoltDB) Get(key []byte, bucket string) ([]byte, error)

Get a value for a key from a bucket using BoltDB transactions

func (*BoltDB) Init

func (bdb *BoltDB) Init(path string) error

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.

func (*BoltDB) Keys

func (bdb *BoltDB) Keys(bucket string) (*Cursor, error)

Keys gets all the keys for a bucket using BoltDB for each.

func (*BoltDB) Put

func (bdb *BoltDB) Put(key []byte, value []byte, bucket string) error

Put a key/value pair into the bucket using BoltDB transactions

func (*BoltDB) Scan

func (bdb *BoltDB) Scan(prefix []byte, bucket string) (*Cursor, error)

Scan a group of keys with a particular prefix using BoltDB prefix seek.

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

func InitDatabase(config Config) (Database, error)

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) Batch

func (ldb *LevelDB) Batch(keys [][]byte, values [][]byte, bucket string) error

Batch insert key/value pairs into a bucket using the LevelDB Batch writes.

func (*LevelDB) Close

func (ldb *LevelDB) Close() error

Close the connection to the LevelDB

func (*LevelDB) CreateBucket

func (ldb *LevelDB) CreateBucket(bucket string, key []byte) []byte

CreateBucket modifies a key using the bucket name as a prefix.

func (*LevelDB) Delete

func (ldb *LevelDB) Delete(key []byte, bucket string) error

Delete a key from a bucket using the LevelDB API

func (*LevelDB) Get

func (ldb *LevelDB) Get(key []byte, bucket string) ([]byte, error)

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

func (ldb *LevelDB) Init(path string) error

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.

func (*LevelDB) Keys

func (ldb *LevelDB) Keys(bucket string) (*Cursor, error)

Keys gets all the keys for a bucket using the LevelDB API

func (*LevelDB) Put

func (ldb *LevelDB) Put(key []byte, value []byte, bucket string) error

Put a key/value pair into the bucket using the LevelDB API

func (*LevelDB) Scan

func (ldb *LevelDB) Scan(prefix []byte, bucket string) (*Cursor, error)

Scan a group of keys with a particular prefix using LevelDB prefix seek.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址