Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for querying entry expiration #96

Merged
merged 2 commits into from
Sep 14, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions datastore.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ type TTLDatastore interface {

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

// Txn extends the Datastore type. Txns allow users to batch queries and
Expand Down
20 changes: 12 additions & 8 deletions query/query.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package query

import (
"time"

goprocess "github.com/jbenet/goprocess"
)

Expand Down Expand Up @@ -56,18 +58,20 @@ cost of the layer of abstraction.

*/
type Query struct {
Prefix string // namespaces the query to results whose keys have Prefix
Filters []Filter // filter results. apply sequentially
Orders []Order // order results. apply sequentially
Limit int // maximum number of results
Offset int // skip given number of results
KeysOnly bool // return only keys.
Prefix string // namespaces the query to results whose keys have Prefix
Filters []Filter // filter results. apply sequentially
Orders []Order // order results. apply sequentially
Limit int // maximum number of results
Offset int // skip given number of results
KeysOnly bool // return only keys.
ReturnExpirations bool // return expirations (see TTLDatastore)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe GetExpirations?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@magik6k I considered GetExpirations, but discarded it because it implies that the impl may perform an extra lookup to populate the field, when in reality the spirit is to allow returning this value if its available in the iterator.

}

// Entry is a query result entry.
type Entry struct {
Key string // cant be ds.Key because circular imports ...!!!
Value []byte // Will be nil if KeysOnly has been passed.
Key string // cant be ds.Key because circular imports ...!!!
Value []byte // Will be nil if KeysOnly has been passed.
Expiration time.Time // Entry expiration timestamp if requested and supported (see TTLDatastore).
}

// Result is a special entry that includes an error, so that the client
Expand Down