aboutsummaryrefslogtreecommitdiff
path: root/src/dedo.go
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/dedo.go23
1 files changed, 15 insertions, 8 deletions
diff --git a/src/dedo.go b/src/dedo.go
index acf8ef1..29cfb45 100644
--- a/src/dedo.go
+++ b/src/dedo.go
@@ -104,6 +104,13 @@ type elemRef struct {
index int
}
+type IDedo interface{
+ Close() error
+ View (func(tx *Tx) error) error
+ Update(func(tx *Tx) error) error
+ Path() string
+}
+
/// 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 ErrDatabaseNotOpen if accessed
@@ -289,7 +296,7 @@ type argsT struct{
type commandT struct{
name string
getopt func(argsT, io.Writer) (argsT, bool)
- exec func(argsT, *DB, io.Reader, io.Writer) error
+ exec func(argsT, IDedo, io.Reader, io.Writer) error
}
@@ -1619,7 +1626,7 @@ func initDB(db *DB, size int64) error {
/// Open creates and opens a database at the given path. If the file does not
/// exist then it will be created automatically.
-func OpenWith(path string, options OpenOptionsT) (*DB, error) {
+func OpenWith(path string, options OpenOptionsT) (IDedo, error) {
file, err := openFile(path)
if err != nil {
return nil, err
@@ -1666,7 +1673,7 @@ func OpenWith(path string, options OpenOptionsT) (*DB, error) {
return db, nil
}
-func Open(path string) (*DB, error) {
+func Open(path string) (IDedo, error) {
return OpenWith(path, defaultOptions)
}
@@ -3832,7 +3839,7 @@ func setGetopt(args argsT, w io.Writer) (argsT, bool) {
return args, true
}
-func checkExec(args argsT, db *DB, _r io.Reader, _w io.Writer) error {
+func checkExec(args argsT, db IDedo, _r io.Reader, _w io.Writer) error {
return db.View(func(tx *Tx) error {
var errs error
for err := range tx.Check() {
@@ -3842,7 +3849,7 @@ func checkExec(args argsT, db *DB, _r io.Reader, _w io.Writer) error {
})
}
-func getExec(args argsT, db *DB, r io.Reader, w io.Writer) error {
+func getExec(args argsT, db IDedo, r io.Reader, w io.Writer) error {
return db.View(func(tx *Tx) error {
bucket := tx.Bucket(args.bucket)
if bucket == nil {
@@ -3859,7 +3866,7 @@ func getExec(args argsT, db *DB, r io.Reader, w io.Writer) error {
})
}
-func setExec(args argsT, db *DB, r io.Reader, w io.Writer) error {
+func setExec(args argsT, db IDedo, r io.Reader, w io.Writer) error {
return db.Update(func(tx *Tx) error {
bucket, err := tx.CreateBucketIfNotExists(args.bucket)
if err != nil {
@@ -3870,7 +3877,7 @@ func setExec(args argsT, db *DB, r io.Reader, w io.Writer) error {
})
}
-func rmExec(args argsT, db *DB, r io.Reader, w io.Writer) error {
+func rmExec(args argsT, db IDedo, r io.Reader, w io.Writer) error {
return db.Update(func(tx *Tx) error {
bucket := tx.Bucket(args.bucket)
if bucket == nil {
@@ -3881,7 +3888,7 @@ func rmExec(args argsT, db *DB, r io.Reader, w io.Writer) error {
})
}
-func listExec(args argsT, db *DB, r io.Reader, w io.Writer) error {
+func listExec(args argsT, db IDedo, r io.Reader, w io.Writer) error {
return db.View(func(tx *Tx) error {
if len(args.bucket) == 0 {
return tx.ForEach(func(