aboutsummaryrefslogtreecommitdiff
path: root/db.go
diff options
context:
space:
mode:
Diffstat (limited to 'db.go')
-rw-r--r--db.go129
1 files changed, 0 insertions, 129 deletions
diff --git a/db.go b/db.go
index 6493e1b..ed6f176 100644
--- a/db.go
+++ b/db.go
@@ -372,135 +372,6 @@ func (db *DB) With(fn func(*Tx) error) error {
return fn(t)
}
-// ForEach executes a function for each key/value pair in a bucket.
-// An error is returned if the bucket cannot be found.
-func (db *DB) ForEach(name string, fn func(k, v []byte) error) error {
- return db.With(func(t *Tx) error {
- b := t.Bucket(name)
- if b == nil {
- return ErrBucketNotFound
- }
- return b.ForEach(fn)
- })
-}
-
-// Bucket retrieves a reference to a bucket.
-// This is typically useful for checking the existence of a bucket.
-func (db *DB) Bucket(name string) (*Bucket, error) {
- t, err := db.Tx()
- if err != nil {
- return nil, err
- }
- defer t.Rollback()
- return t.Bucket(name), nil
-}
-
-// Buckets retrieves a list of all buckets in the database.
-func (db *DB) Buckets() ([]*Bucket, error) {
- t, err := db.Tx()
- if err != nil {
- return nil, err
- }
- defer t.Rollback()
- return t.Buckets(), nil
-}
-
-// CreateBucket creates a new bucket with the given name.
-// This function can return an error if the bucket already exists, if the name
-// is blank, or the bucket name is too long.
-func (db *DB) CreateBucket(name string) error {
- return db.Do(func(t *Tx) error {
- return t.CreateBucket(name)
- })
-}
-
-// CreateBucketIfNotExists creates a new bucket with the given name if it doesn't already exist.
-// This function can return an error if the name is blank, or the bucket name is too long.
-func (db *DB) CreateBucketIfNotExists(name string) error {
- return db.Do(func(t *Tx) error {
- return t.CreateBucketIfNotExists(name)
- })
-}
-
-// DeleteBucket removes a bucket from the database.
-// Returns an error if the bucket does not exist.
-func (db *DB) DeleteBucket(name string) error {
- return db.Do(func(t *Tx) error {
- return t.DeleteBucket(name)
- })
-}
-
-// NextSequence returns an autoincrementing integer for the bucket.
-// This function can return an error if the bucket does not exist.
-func (db *DB) NextSequence(name string) (int, error) {
- var seq int
- err := db.Do(func(t *Tx) error {
- b := t.Bucket(name)
- if b == nil {
- return ErrBucketNotFound
- }
-
- var err error
- seq, err = b.NextSequence()
- return err
- })
- if err != nil {
- return 0, err
- }
- return seq, nil
-}
-
-// Get retrieves the value for a key in a bucket.
-// Returns an error if the key does not exist.
-func (db *DB) Get(name string, key []byte) ([]byte, error) {
- t, err := db.Tx()
- if err != nil {
- return nil, err
- }
- defer t.Rollback()
-
- // Open bucket and retrieve value for key.
- b := t.Bucket(name)
- if b == nil {
- return nil, ErrBucketNotFound
- }
- value := b.Get(key)
- if value == nil {
- return nil, nil
- }
-
- // Copy the value out since the transaction will be closed after this
- // function ends. The data can get reclaimed between now and when the
- // value is used.
- tmp := make([]byte, len(value))
- copy(tmp, value)
- return tmp, nil
-}
-
-// Put sets the value for a key in a bucket.
-// Returns an error if the bucket is not found, if key is blank, if the key is too large, or if the value is too large.
-func (db *DB) Put(name string, key []byte, value []byte) error {
- return db.Do(func(t *Tx) error {
- b := t.Bucket(name)
- if b == nil {
- return ErrBucketNotFound
- }
- return b.Put(key, value)
- })
-}
-
-// Delete removes a key from a bucket.
-// Returns an error if the bucket cannot be found.
-func (db *DB) Delete(name string, key []byte) error {
- return db.Do(func(t *Tx) error {
- b := t.Bucket(name)
- if b == nil {
- return ErrBucketNotFound
- }
- return b.Delete(key)
- })
-}
-
// Copy writes the entire database to a writer.
// A reader transaction is maintained during the copy so it is safe to continue
// using the database while a copy is in progress.