diff --git a/.gx/lastpubver b/.gx/lastpubver index 5b19ae3..58002c6 100644 --- a/.gx/lastpubver +++ b/.gx/lastpubver @@ -1 +1 @@ -1.8.0: QmaUU1Hu8pbR2NiTJ1NHVBcNTQR499AJVMkkAoRqhdxbgz +1.9.0: Qmd1Zxnuj9puWCPS7DV1YVw1RM478NqyZmf1X5nsgjp6fQ diff --git a/datastore.go b/datastore.go index a0c5904..456960c 100644 --- a/datastore.go +++ b/datastore.go @@ -42,6 +42,10 @@ var DefaultOptions = Options{ Options: badger.DefaultOptions, } +var _ ds.Datastore = (*Datastore)(nil) +var _ ds.TxnDatastore = (*Datastore)(nil) +var _ ds.TTLDatastore = (*Datastore)(nil) + // NewDatastore creates a new badger datastore. // // DO NOT set the Dir and/or ValuePath fields of opt, they will be set for you. @@ -81,8 +85,8 @@ func NewDatastore(path string, options *Options) (*Datastore, error) { // NewTransaction starts a new transaction. The resulting transaction object // can be mutated without incurring changes to the underlying Datastore until // the transaction is Committed. -func (d *Datastore) NewTransaction(readOnly bool) ds.Txn { - return &txn{d.DB.NewTransaction(!readOnly), false} +func (d *Datastore) NewTransaction(readOnly bool) (ds.Txn, error) { + return &txn{d.DB.NewTransaction(!readOnly), false}, nil } // newImplicitTransaction creates a transaction marked as 'implicit'. @@ -179,7 +183,8 @@ func (d *Datastore) Close() error { func (d *Datastore) IsThreadSafe() {} func (d *Datastore) Batch() (ds.Batch, error) { - return d.NewTransaction(false), nil + tx, _ := d.NewTransaction(false) + return tx, nil } func (d *Datastore) CollectGarbage() error { diff --git a/ds_test.go b/ds_test.go index d7ad71c..f0abd81 100644 --- a/ds_test.go +++ b/ds_test.go @@ -529,7 +529,10 @@ func TestTxnDiscard(t *testing.T) { t.Fatal(err) } - txn := d.NewTransaction(false) + txn, err := d.NewTransaction(false) + if err != nil { + t.Fatal(err) + } key := ds.NewKey("/test/thing") if err := txn.Put(key, []byte{1, 2, 3}); err != nil { t.Fatal(err) @@ -553,7 +556,10 @@ func TestTxnCommit(t *testing.T) { t.Fatal(err) } - txn := d.NewTransaction(false) + txn, err := d.NewTransaction(false) + if err != nil { + t.Fatal(err) + } key := ds.NewKey("/test/thing") if err := txn.Put(key, []byte{1, 2, 3}); err != nil { t.Fatal(err) @@ -577,8 +583,10 @@ func TestTxnBatch(t *testing.T) { t.Fatal(err) } - txn := d.NewTransaction(false) - + txn, err := d.NewTransaction(false) + if err != nil { + t.Fatal(err) + } data := make(map[ds.Key][]byte) for i := 0; i < 10; i++ { key := ds.NewKey(fmt.Sprintf("/test/%d", i)) @@ -624,7 +632,10 @@ func TestTTL(t *testing.T) { t.Fatal(err) } - txn := d.NewTransaction(false) + txn, err := d.NewTransaction(false) + if err != nil { + t.Fatal(err) + } data := make(map[ds.Key][]byte) for i := 0; i < 10; i++ { @@ -649,7 +660,10 @@ func TestTTL(t *testing.T) { t.Fatal(err) } - txn = d.NewTransaction(true) + txn, err = d.NewTransaction(true) + if err != nil { + t.Fatal(err) + } for key := range data { _, err := txn.Get(key) if err != nil { @@ -679,7 +693,10 @@ func TestExpirations(t *testing.T) { d, done := newDS(t) defer done() - txn := d.NewTransaction(false) + txn, err := d.NewTransaction(false) + if err != nil { + t.Fatal(err) + } ttltxn := txn.(ds.TTLDatastore) defer txn.Discard() @@ -702,7 +719,10 @@ func TestExpirations(t *testing.T) { } // Second transaction to retrieve expirations. - txn = d.NewTransaction(true) + txn, err = d.NewTransaction(true) + if err != nil { + t.Fatal(err) + } ttltxn = txn.(ds.TTLDatastore) defer txn.Discard() diff --git a/package.json b/package.json index 3a0d81a..d9f10a9 100644 --- a/package.json +++ b/package.json @@ -15,9 +15,9 @@ }, { "author": "jbenet", - "hash": "QmUyz7JTJzgegC6tiJrfby3mPhzcdswVtG4x58TQ6pq8jV", + "hash": "QmbQshXLNcCPRUGZv4sBGxnZNAHREA6MKeomkwihNXPZWP", "name": "go-datastore", - "version": "3.2.0" + "version": "3.3.0" }, { "author": "dgraph-io", @@ -37,6 +37,6 @@ "license": "", "name": "go-ds-badger", "releaseCmd": "git commit -a -m \"gx publish $VERSION\"", - "version": "1.8.0" + "version": "1.9.0" }