Skip to content

split the datastore into a read and a write interface #107

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 11, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}