aboutsummaryrefslogtreecommitdiff
path: root/db.go
diff options
context:
space:
mode:
Diffstat (limited to 'db.go')
-rw-r--r--db.go19
1 files changed, 15 insertions, 4 deletions
diff --git a/db.go b/db.go
index 99cc9ca..ec049dd 100644
--- a/db.go
+++ b/db.go
@@ -1,6 +1,7 @@
package bolt
import (
+ "fmt"
"io"
"os"
"sync"
@@ -16,7 +17,7 @@ const maxMmapStep = 1 << 30 // 1GB
// DB represents a collection of buckets persisted to a file on disk.
// All data access is performed through transactions which can be obtained through the DB.
-// All the functions on DB will return a DatabaseNotOpenError if accessed before Open() is called.
+// All the functions on DB will return a ErrDatabaseNotOpen if accessed before Open() is called.
type DB struct {
os _os
syscall _syscall
@@ -42,6 +43,16 @@ func (db *DB) Path() string {
return db.path
}
+// GoString returns the Go string representation of the database.
+func (db *DB) GoString() string {
+ return fmt.Sprintf("bolt.DB{path:%q}", db.path)
+}
+
+// String returns the string representation of the database.
+func (db *DB) String() string {
+ return fmt.Sprintf("DB<%q>", db.path)
+}
+
// Open opens a data file at the given path and initializes the database.
// If the file does not exist then it will be created automatically.
func (db *DB) Open(path string, mode os.FileMode) error {
@@ -60,7 +71,7 @@ func (db *DB) Open(path string, mode os.FileMode) error {
// Exit if the database is currently open.
if db.opened {
- return DatabaseOpenError
+ return ErrDatabaseOpen
}
// Open data file and separate sync handler for metadata writes.
@@ -263,7 +274,7 @@ func (db *DB) Transaction() (*Transaction, error) {
// Exit if the database is not open yet.
if !db.opened {
- return nil, DatabaseNotOpenError
+ return nil, ErrDatabaseNotOpen
}
// Create a transaction associated with the database.
@@ -289,7 +300,7 @@ func (db *DB) RWTransaction() (*RWTransaction, error) {
// Exit if the database is not open yet.
if !db.opened {
db.rwlock.Unlock()
- return nil, DatabaseNotOpenError
+ return nil, ErrDatabaseNotOpen
}
// Create a transaction associated with the database.