Documentation
¶
Overview ¶
Package db provides a generic interface around key/value databases.
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrDataExist = util.Error("数据已存在") ErrDataNotExist = util.Error("数据不存在") ErrBucketExist = util.Error("数据集已存在") ErrBucketNotExist = util.Error("数据集不存在") ErrStopEach = errors.New("db: stop each") )
Errors.
Functions ¶
This section is empty.
Types ¶
type Bucket ¶
type Bucket interface {
// IsEmpty checks if the bucket is empty.
IsEmpty() (bool, error)
// Has checks if the bucket has the key.
Has(key []byte) (bool, error)
// Get retrieves the value for a key in the bucket.
Get(key []byte, value interface{}) error
// Put sets the value for a key in the bucket.
Put(key []byte, value interface{}) error
// Create creates a new value.
Create(key []byte, value interface{}) error
// Update updates the value.
Update(key []byte, value interface{}) error
// Delete removes the key from the bucket.
Delete(key []byte) error
// Each applies the function f to each values.
Each(f interface{}, min, max []byte) error
// Bucket retrieves a bucket by key.
Bucket(key []byte) Bucket
// CreateBucket creates a new bucket.
CreateBucket(key []byte) (Bucket, error)
// DeleteBucket deletes the bucket by key.
DeleteBucket(key []byte) error
// RequireBucket creates a new bucket if it doesn't already exist and returns a reference to it.
RequireBucket(key []byte) (Bucket, error)
}
Bucket represents a collection of items inside the database.
type DB ¶
type DB interface {
// Close closes the database.
Close() error
// Begin starts a new transaction.
Begin(writable bool) (Tx, error)
}
DB represents a database.
type Tx ¶
type Tx interface {
// Rollback closes the transaction and ignores all previous updates.
Rollback() error
// Commit writes all changes to database.
Commit() error
// Bucket retrieves a bucket by key.
Bucket(key []byte) Bucket
// CreateBucket creates a new bucket.
CreateBucket(key []byte) (Bucket, error)
// DeleteBucket deletes the bucket by key.
DeleteBucket(key []byte) error
// RequireBucket creates a new bucket if it doesn't already exist and returns a reference to it.
RequireBucket(key []byte) (Bucket, error)
}
Tx represents a transaction on the database.
Click to show internal directories.
Click to hide internal directories.