Skip to content

Commit 27c8307

Browse files
authored
Merge pull request #107 from ipfs/feat/read-write
split the datastore into a read and a write interface
2 parents 277eeb2 + a7c8d61 commit 27c8307

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

datastore.go

+15-6
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ proper error reporting. Thus, all Datastore calls may return errors, which
3131
should be checked by callers.
3232
*/
3333
type Datastore interface {
34+
Read
35+
Write
36+
}
37+
38+
// Write is the write-side of the Datastore interface.
39+
type Write interface {
3440
// Put stores the object `value` named by `key`.
3541
//
3642
// The generalized Datastore interface does not impose a value type,
@@ -42,6 +48,12 @@ type Datastore interface {
4248
// type-safe interface to your application, and do the checking up-front.
4349
Put(key Key, value []byte) error
4450

51+
// Delete removes the value for given `key`.
52+
Delete(key Key) error
53+
}
54+
55+
// Read is the read-side of the Datastore interface.
56+
type Read interface {
4557
// Get retrieves the object `value` named by `key`.
4658
// Get will return ErrNotFound if the key is not mapped to a value.
4759
Get(key Key) (value []byte, err error)
@@ -57,9 +69,6 @@ type Datastore interface {
5769
// value rather than retrieving the value itself.
5870
GetSize(key Key) (size int, err error)
5971

60-
// Delete removes the value for given `key`.
61-
Delete(key Key) error
62-
6372
// Query searches the datastore and returns a query result. This function
6473
// may return before the query actually runs. To wait for the query:
6574
//
@@ -87,6 +96,8 @@ type Batching interface {
8796
Batch() (Batch, error)
8897
}
8998

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

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

225236
type Batch interface {
226-
Put(key Key, val []byte) error
227-
228-
Delete(key Key) error
237+
Write
229238

230239
Commit() error
231240
}

0 commit comments

Comments
 (0)