Skip to content

Commit

Permalink
Merge pull request #91 from bigs/feat/superclasses
Browse files Browse the repository at this point in the history
Add TTL and Transactional interfaces
  • Loading branch information
bigs committed Aug 14, 2018
2 parents 42d1e12 + 7db32f2 commit af96e51
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .gx/lastpubver
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.0.0: QmVG5gxteQNEMhrS8prJSmU2C9rebtFuTd3SYZ5kE3YZ5k
3.1.0: QmSpg1CvpXQQow5ernt1gNBXaXV6yxyNqi7XoeerWfzB5w
37 changes: 37 additions & 0 deletions datastore.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package datastore

import (
"errors"
"time"

query "github.com/ipfs/go-datastore/query"
)
Expand Down Expand Up @@ -130,6 +131,42 @@ func DiskUsage(d Datastore) (uint64, error) {
return persDs.DiskUsage()
}

// TTLDatastore is an interface that should be implemented by datastores that
// support expiring entries.
type TTLDatastore interface {
Datastore

PutWithTTL(key Key, value []byte, ttl time.Duration) error
SetTTL(key Key, ttl time.Duration) error
}

// Txn extends the Datastore type. Txns allow users to batch queries and
// mutations to the Datastore into atomic groups, or transactions. Actions
// performed on a transaction will not take hold until a successful call to
// Commit has been made. Likewise, transactions can be aborted by calling
// Discard before a successful Commit has been made.
type Txn interface {
Datastore

// Commit finalizes a transaction, attempting to commit it to the Datastore.
// May return an error if the transaction has gone stale. The presence of an
// error is an indication that the data was not committed to the Datastore.
Commit() error
// Discard throws away changes recorded in a transaction without committing
// them to the underlying Datastore. Any calls made to Discard after Commit
// has been successfully called will have no effect on the transaction and
// state of the Datastore, making it safe to defer.
Discard()
}

// TxnDatastore is an interface that should be implemented by datastores that
// support transactions.
type TxnDatastore interface {
Datastore

NewTransaction(readOnly bool) Txn
}

// Errors

// ErrNotFound is returned by Get, Has, and Delete when a datastore does not
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@
"license": "MIT",
"name": "go-datastore",
"releaseCmd": "git commit -a -m \"gx publish $VERSION\"",
"version": "3.0.0"
"version": "3.1.0"
}

0 comments on commit af96e51

Please sign in to comment.