@@ -2,6 +2,7 @@ package datastore
2
2
3
3
import (
4
4
"errors"
5
+ "time"
5
6
6
7
query "github.com/ipfs/go-datastore/query"
7
8
)
@@ -130,6 +131,42 @@ func DiskUsage(d Datastore) (uint64, error) {
130
131
return persDs .DiskUsage ()
131
132
}
132
133
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
+
133
170
// Errors
134
171
135
172
// ErrNotFound is returned by Get, Has, and Delete when a datastore does not
0 commit comments