Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion datastore.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ var ErrNotFound error = &dsError{error: errors.New("datastore: key not found"),
func GetBackedHas(ctx context.Context, ds Read, key Key) (bool, error) {
_, err := ds.Get(ctx, key)
if err != nil {
if err == ErrNotFound {
if errors.Is(err, ErrNotFound) {
return false, nil
}
return false, err
Expand Down
10 changes: 5 additions & 5 deletions fuzz/go.mod
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
module github.com/ipfs/go-datastore/fuzz

go 1.25
go 1.25.0

require (
github.com/ipfs/go-datastore v0.9.0
github.com/ipfs/go-datastore v0.9.1
github.com/ipfs/go-ds-flatfs v0.6.0
github.com/spf13/pflag v1.0.10
)

require (
github.com/alexbrainman/goissue34681 v0.0.0-20191006012335-3fc7a47baff5 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/ipfs/go-log/v2 v2.9.0 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/ipfs/go-log/v2 v2.9.2 // indirect
github.com/mattn/go-isatty v0.0.22 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.27.0 // indirect
go.uber.org/zap v1.28.0 // indirect
golang.org/x/sys v0.35.0 // indirect
)

Expand Down
15 changes: 8 additions & 7 deletions fuzz/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ github.com/ipfs/go-detect-race v0.0.1 h1:qX/xay2W3E4Q1U7d9lNs1sU9nvguX0a7319XbyQ
github.com/ipfs/go-detect-race v0.0.1/go.mod h1:8BNT7shDZPo99Q74BpGMK+4D8Mn4j46UU0LZ723meps=
github.com/ipfs/go-ds-flatfs v0.6.0 h1:olAEnDNBK1VMoTRZvfzgo90H5kBP4qIZPpYMtNlBBws=
github.com/ipfs/go-ds-flatfs v0.6.0/go.mod h1:p8a/YhmAFYyuonxDbvuIANlDCgS69uqVv+iH5f8fAxY=
github.com/ipfs/go-log/v2 v2.9.0 h1:l4b06AwVXwldIzbVPZy5z7sKp9lHFTX0KWfTBCtHaOk=
github.com/ipfs/go-log/v2 v2.9.0/go.mod h1:UhIYAwMV7Nb4ZmihUxfIRM2Istw/y9cAk3xaK+4Zs2c=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/ipfs/go-log/v2 v2.9.2 h1:O/5BB0elpkRILvT24rCJ5976wWd7u0nJ436T3rdYdc4=
github.com/ipfs/go-log/v2 v2.9.2/go.mod h1:RziRwwXWhndlk8L75RnEe0zeAYaq2heKtEMc3jqUov0=
github.com/mattn/go-isatty v0.0.22 h1:j8l17JJ9i6VGPUFUYoTUKPSgKe/83EYU2zBC7YNKMw4=
github.com/mattn/go-isatty v0.0.22/go.mod h1:ZXfXG4SQHsB/w3ZeOYbR0PrPwLy+n6xiMrJlRFqopa4=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/spf13/pflag v1.0.10 h1:4EBh2KAYBwaONj6b2Ye1GiHfwjqyROoF4RwYO+vPwFk=
Expand All @@ -22,9 +22,10 @@ go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8=
go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
go.uber.org/zap v1.28.0 h1:IZzaP1Fv73/T/pBMLk4VutPl36uNC+OSUh3JLG3FIjo=
go.uber.org/zap v1.28.0/go.mod h1:rDLpOi171uODNm/mxFcuYWxDsqWSAVkFdX4XojSKg/Q=
go.yaml.in/yaml/v3 v3.0.4 h1:tfq32ie2Jv2UxXFdLJdh3jXuOzWiL1fo0bu/FbuKpbc=
go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg=
golang.org/x/sys v0.35.0 h1:vz1N37gP5bs89s7He8XuIYXpyY0+QlsKmzipCbUtyxI=
golang.org/x/sys v0.35.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
Expand Down
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
module github.com/ipfs/go-datastore

go 1.25
go 1.25.0

require (
github.com/google/uuid v1.6.0
github.com/ipfs/go-detect-race v0.0.1
github.com/ipfs/go-ipfs-delay v0.0.1
github.com/stretchr/testify v1.11.1
go.opentelemetry.io/otel v1.40.0
go.opentelemetry.io/otel/trace v1.40.0
go.opentelemetry.io/otel v1.44.0
go.opentelemetry.io/otel/trace v1.44.0
)

require (
Expand All @@ -18,6 +18,6 @@ require (
github.com/go-logr/stdr v1.2.2 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
go.opentelemetry.io/auto/sdk v1.2.1 // indirect
go.opentelemetry.io/otel/metric v1.40.0 // indirect
go.opentelemetry.io/otel/metric v1.44.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
go.opentelemetry.io/auto/sdk v1.2.1 h1:jXsnJ4Lmnqd11kwkBV2LgLoFMZKizbCi5fNZ/ipaZ64=
go.opentelemetry.io/auto/sdk v1.2.1/go.mod h1:KRTj+aOaElaLi+wW1kO/DZRXwkF4C5xPbEe3ZiIhN7Y=
go.opentelemetry.io/otel v1.40.0 h1:oA5YeOcpRTXq6NN7frwmwFR0Cn3RhTVZvXsP4duvCms=
go.opentelemetry.io/otel v1.40.0/go.mod h1:IMb+uXZUKkMXdPddhwAHm6UfOwJyh4ct1ybIlV14J0g=
go.opentelemetry.io/otel/metric v1.40.0 h1:rcZe317KPftE2rstWIBitCdVp89A2HqjkxR3c11+p9g=
go.opentelemetry.io/otel/metric v1.40.0/go.mod h1:ib/crwQH7N3r5kfiBZQbwrTge743UDc7DTFVZrrXnqc=
go.opentelemetry.io/otel/trace v1.40.0 h1:WA4etStDttCSYuhwvEa8OP8I5EWu24lkOzp+ZYblVjw=
go.opentelemetry.io/otel/trace v1.40.0/go.mod h1:zeAhriXecNGP/s2SEG3+Y8X9ujcJOTqQ5RgdEJcawiA=
go.opentelemetry.io/otel v1.44.0 h1:JjwHmHpA4iZ3wBxluu2fbbE7j4kqlE8jXyAyPXH7HqU=
go.opentelemetry.io/otel v1.44.0/go.mod h1:BMgjTHL9WPRlRjL2oZCBTL4whCGtXch2H4BhOPIAyYc=
go.opentelemetry.io/otel/metric v1.44.0 h1:1w0gILTcHdr3YI+ixLyjemwrVnsMURbTZFrSYCdDdmc=
go.opentelemetry.io/otel/metric v1.44.0/go.mod h1:8O7hanEPBNgEMmybD3s2VBKcgWOCsA6tzHBPODAiquo=
go.opentelemetry.io/otel/trace v1.44.0 h1:jxF5CsGYCe74MCRx2X4g7WsY/VBKRqqpNvXlX/6gtIk=
go.opentelemetry.io/otel/trace v1.44.0/go.mod h1:oLl1jrMQAVo6v3GAggN+1VH9VIz9iUSvW53sW1Q8PIE=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
Expand Down
30 changes: 16 additions & 14 deletions query/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package query
import (
"context"
"fmt"
"strings"
"time"
)

Expand Down Expand Up @@ -69,45 +70,46 @@ type Query struct {
// String returns a string representation of the Query for debugging/validation
// purposes. Do not use it for SQL queries.
func (q Query) String() string {
s := "SELECT keys"
var s strings.Builder
s.WriteString("SELECT keys")
if !q.KeysOnly {
s += ",vals"
s.WriteString(",vals")
}
if q.ReturnExpirations {
s += ",exps"
s.WriteString(",exps")
}

s += " "
s.WriteString(" ")

if q.Prefix != "" {
s += fmt.Sprintf("FROM %q ", q.Prefix)
s.WriteString(fmt.Sprintf("FROM %q ", q.Prefix))
}

if len(q.Filters) > 0 {
s += fmt.Sprintf("FILTER [%s", q.Filters[0])
s.WriteString(fmt.Sprintf("FILTER [%s", q.Filters[0]))
for _, f := range q.Filters[1:] {
s += fmt.Sprintf(", %s", f)
s.WriteString(fmt.Sprintf(", %s", f))
}
s += "] "
s.WriteString("] ")
}

if len(q.Orders) > 0 {
s += fmt.Sprintf("ORDER [%s", q.Orders[0])
s.WriteString(fmt.Sprintf("ORDER [%s", q.Orders[0]))
for _, f := range q.Orders[1:] {
s += fmt.Sprintf(", %s", f)
s.WriteString(fmt.Sprintf(", %s", f))
}
s += "] "
s.WriteString("] ")
}

if q.Offset > 0 {
s += fmt.Sprintf("OFFSET %d ", q.Offset)
s.WriteString(fmt.Sprintf("OFFSET %d ", q.Offset))
}

if q.Limit > 0 {
s += fmt.Sprintf("LIMIT %d ", q.Limit)
s.WriteString(fmt.Sprintf("LIMIT %d ", q.Limit))
}
// Will always end with a space, strip it.
return s[:len(s)-1]
return s.String()[:len(s.String())-1]
}

// Entry is a query result entry.
Expand Down
5 changes: 2 additions & 3 deletions query/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ func TestLimit(t *testing.T) {
}

func TestOffset(t *testing.T) {

testOffset := func(t *testing.T, offset int, keys []string, expect []string) {
t.Helper()
e := make([]Entry, len(keys))
Expand Down Expand Up @@ -244,15 +243,15 @@ func getKeysViaNextSync(rs Results) []string {

func getKeysViaRest(rs Results) []string {
rest, _ := rs.Rest()
ret := make([]string, 0)
ret := make([]string, 0, len(rest))
for _, e := range rest {
ret = append(ret, e.Key)
}
return ret
}

func getKeysViaChan(rs Results) []string {
ret := make([]string, 0)
var ret []string
for r := range rs.Next() {
ret = append(ret, r.Key)
}
Expand Down
30 changes: 14 additions & 16 deletions test/basic_tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func TestElemCount(t *testing.T) {
}

func SubtestBasicPutGet(t *testing.T, ds dstore.Datastore) {
ctx := context.Background()
ctx := t.Context()

k := dstore.NewKey("foo")
val := []byte("Hello Datastore!")
Expand Down Expand Up @@ -103,11 +103,10 @@ func SubtestBasicPutGet(t *testing.T, ds dstore.Datastore) {
}

size, err = ds.GetSize(ctx, k)
switch err {
case dstore.ErrNotFound:
case nil:
if err == nil {
t.Fatal("expected error getting size after delete")
default:
}
if !errors.Is(err, dstore.ErrNotFound) {
t.Fatal("wrong error getting size after delete: ", err)
}
if size != -1 {
Expand All @@ -116,7 +115,7 @@ func SubtestBasicPutGet(t *testing.T, ds dstore.Datastore) {
}

func SubtestNotFounds(t *testing.T, ds dstore.Datastore) {
ctx := context.Background()
ctx := t.Context()

badk := dstore.NewKey("notreal")

Expand All @@ -138,11 +137,10 @@ func SubtestNotFounds(t *testing.T, ds dstore.Datastore) {
}

size, err := ds.GetSize(ctx, badk)
switch err {
case dstore.ErrNotFound:
case nil:
if err == nil {
t.Fatal("expected error getting size of not found key")
default:
}
if !errors.Is(err, dstore.ErrNotFound) {
t.Fatal("wrong error getting size of not found key", err)
}
if size != -1 {
Expand Down Expand Up @@ -181,7 +179,7 @@ func SubtestLimit(t *testing.T, ds dstore.Datastore) {

func SubtestOrder(t *testing.T, ds dstore.Datastore) {
test := func(orders ...dsq.Order) {
var types []string
types := make([]string, 0, len(orders))
for _, o := range orders {
types = append(types, fmt.Sprintf("%T", o))
}
Expand All @@ -208,7 +206,7 @@ func SubtestManyKeysAndQuery(t *testing.T, ds dstore.Datastore) {
}

func SubtestBasicSync(t *testing.T, ds dstore.Datastore) {
ctx := context.Background()
ctx := t.Context()

if err := ds.Sync(ctx, dstore.NewKey("prefix")); err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -404,10 +402,10 @@ func randValue() []byte {
}

func subtestQuery(t *testing.T, ds dstore.Datastore, q dsq.Query, count int) {
ctx, cancel := context.WithCancel(context.Background())
ctx, cancel := context.WithCancel(t.Context())
defer cancel()

var input []dsq.Entry
input := make([]dsq.Entry, 0, 4*count)
for i := range count {
s := fmt.Sprintf("%dkey%d", i, i)
key := dstore.NewKey(s).String()
Expand Down Expand Up @@ -566,10 +564,10 @@ func subtestQuery(t *testing.T, ds dstore.Datastore, q dsq.Query, count int) {
}

// use a new context, since previous was cancelled.
ctx = context.Background()
ctx = t.Context()
t.Log("deleting all keys")
for _, e := range input {
if err := ds.Delete(ctx, dstore.RawKey(e.Key)); err != nil {
if err = ds.Delete(ctx, dstore.RawKey(e.Key)); err != nil {
t.Fatal(err)
}
}
Expand Down
3 changes: 1 addition & 2 deletions test/suite.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package dstest

import (
"context"
"reflect"
"runtime"
"testing"
Expand Down Expand Up @@ -43,7 +42,7 @@ func getFunctionName(i any) string {
}

func clearDs(t *testing.T, ds dstore.Datastore) {
ctx := context.Background()
ctx := t.Context()

q, err := ds.Query(ctx, query.Query{KeysOnly: true})
if err != nil {
Expand Down
Loading
Loading