Commit a7c8d614 authored by Steven Allen's avatar Steven Allen

split the datastore into a read and a write interface

This way, we can abstract over transactions, datastores, and batches when we
just need to write to the datastore.
parent 277eeb2f
......@@ -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,
......@@ -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)
......@@ -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:
//
......@@ -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
......@@ -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
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment