Skip to content

Commit

Permalink
Merge pull request #107 from ipfs/feat/read-write
Browse files Browse the repository at this point in the history
split the datastore into a read and a write interface
  • Loading branch information
Stebalien authored Dec 11, 2018
2 parents 277eeb2 + a7c8d61 commit 27c8307
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions datastore.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ proper error reporting. Thus, all Datastore calls may return errors, which
should be checked by callers.
*/
type Datastore interface {
Read
Write
}

// Write is the write-side of the Datastore interface.
type Write interface {
// Put stores the object `value` named by `key`.
//
// The generalized Datastore interface does not impose a value type,
Expand All @@ -42,6 +48,12 @@ type Datastore interface {
// type-safe interface to your application, and do the checking up-front.
Put(key Key, value []byte) error

// Delete removes the value for given `key`.
Delete(key Key) error
}

// Read is the read-side of the Datastore interface.
type Read interface {
// Get retrieves the object `value` named by `key`.
// Get will return ErrNotFound if the key is not mapped to a value.
Get(key Key) (value []byte, err error)
Expand All @@ -57,9 +69,6 @@ type Datastore interface {
// value rather than retrieving the value itself.
GetSize(key Key) (size int, err error)

// Delete removes the value for given `key`.
Delete(key Key) error

// Query searches the datastore and returns a query result. This function
// may return before the query actually runs. To wait for the query:
//
Expand Down Expand Up @@ -87,6 +96,8 @@ type Batching interface {
Batch() (Batch, error)
}

// ErrBatchUnsupported is returned if the by Batch if the Datastore doesn't
// actually support batching.
var ErrBatchUnsupported = errors.New("this datastore does not support batching")

// ThreadSafeDatastore is an interface that all threadsafe datastore should
Expand Down Expand Up @@ -223,9 +234,7 @@ func GetBackedSize(ds Datastore, key Key) (int, error) {
}

type Batch interface {
Put(key Key, val []byte) error

Delete(key Key) error
Write

Commit() error
}

0 comments on commit 27c8307

Please sign in to comment.