Skip to content

Commit af96e51

Browse files
authored
Merge pull request #91 from bigs/feat/superclasses
Add TTL and Transactional interfaces
2 parents 42d1e12 + 7db32f2 commit af96e51

File tree

3 files changed

+39
-2
lines changed

3 files changed

+39
-2
lines changed

.gx/lastpubver

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.0.0: QmVG5gxteQNEMhrS8prJSmU2C9rebtFuTd3SYZ5kE3YZ5k
1+
3.1.0: QmSpg1CvpXQQow5ernt1gNBXaXV6yxyNqi7XoeerWfzB5w

datastore.go

+37
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package datastore
22

33
import (
44
"errors"
5+
"time"
56

67
query "github.com/ipfs/go-datastore/query"
78
)
@@ -130,6 +131,42 @@ func DiskUsage(d Datastore) (uint64, error) {
130131
return persDs.DiskUsage()
131132
}
132133

134+
// TTLDatastore is an interface that should be implemented by datastores that
135+
// support expiring entries.
136+
type TTLDatastore interface {
137+
Datastore
138+
139+
PutWithTTL(key Key, value []byte, ttl time.Duration) error
140+
SetTTL(key Key, ttl time.Duration) error
141+
}
142+
143+
// Txn extends the Datastore type. Txns allow users to batch queries and
144+
// mutations to the Datastore into atomic groups, or transactions. Actions
145+
// performed on a transaction will not take hold until a successful call to
146+
// Commit has been made. Likewise, transactions can be aborted by calling
147+
// Discard before a successful Commit has been made.
148+
type Txn interface {
149+
Datastore
150+
151+
// Commit finalizes a transaction, attempting to commit it to the Datastore.
152+
// May return an error if the transaction has gone stale. The presence of an
153+
// error is an indication that the data was not committed to the Datastore.
154+
Commit() error
155+
// Discard throws away changes recorded in a transaction without committing
156+
// them to the underlying Datastore. Any calls made to Discard after Commit
157+
// has been successfully called will have no effect on the transaction and
158+
// state of the Datastore, making it safe to defer.
159+
Discard()
160+
}
161+
162+
// TxnDatastore is an interface that should be implemented by datastores that
163+
// support transactions.
164+
type TxnDatastore interface {
165+
Datastore
166+
167+
NewTransaction(readOnly bool) Txn
168+
}
169+
133170
// Errors
134171

135172
// ErrNotFound is returned by Get, Has, and Delete when a datastore does not

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,6 @@
3737
"license": "MIT",
3838
"name": "go-datastore",
3939
"releaseCmd": "git commit -a -m \"gx publish $VERSION\"",
40-
"version": "3.0.0"
40+
"version": "3.1.0"
4141
}
4242

0 commit comments

Comments
 (0)