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

Another global source code improvement #22

Open
wants to merge 26 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
4cc6f21
Append "_test" in package name
0uep Apr 26, 2022
3432fd1
Rearrange struct fields to reduce memory footprint
0uep Apr 26, 2022
d057ebe
Rename "t" to "tb" for testing.TB
0uep Apr 26, 2022
013c190
Rename "t" to "b" for testing.B
0uep Apr 26, 2022
c56850f
Rename types treePool and enumPool
0uep Apr 26, 2022
b770175
Use local "ok" variable
0uep Apr 26, 2022
4322d64
Simplify Next() and Prev()
0uep Apr 26, 2022
41c9988
Simplify if blocks
0uep Apr 26, 2022
c1b1725
Simplify FilterOp.String()
0uep Apr 26, 2022
e992b9c
Do not assign when not neccessary
0uep Apr 26, 2022
62d66f4
Simplify incrementing
0uep Apr 26, 2022
a0c708e
Return error from db.sess.Disconnect()
0uep Apr 26, 2022
d7b7b25
Uppercase "id" in objidString -> objIDString
0uep Apr 26, 2022
8d13172
Use "_" for unused func. parameters
0uep Apr 26, 2022
084fc18
Use "_" for intentionnally unchecked returned errors
0uep Apr 26, 2022
68cb595
Use errors.Is(err,X)
0uep Apr 26, 2022
dbde172
Use fmt.Errorf("%w",err)
0uep Apr 26, 2022
4882c63
Replace incorrect err check by TODO FIXME comment
0uep Apr 26, 2022
f4d1c5a
Preallocate slides
0uep Apr 26, 2022
aedff3c
Simplify DB.EnsureIndex()
0uep Apr 26, 2022
e721d54
Unshadow "err" variables by renaming it to "er"
0uep Apr 26, 2022
67b8fb5
Nest "err" varible within if condition
0uep Apr 26, 2022
ca24be5
Simplify code of datastore
0uep Apr 26, 2022
3f6c5fc
Replace strings.Replace() by ReplaceAll() when possible
0uep Apr 26, 2022
12e5283
Reuse the wider scope variable "conn"
0uep Apr 26, 2022
9afa72c
Avoid returning an interface when possible
0uep Mar 22, 2022
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 filter/filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (Any) ValuesRange() *Range {
}

// EQ is a shorthand for Equal.
func EQ(v values.Value) SortableFilter {
func EQ(v values.Value) Equal {
return Equal{Value: v}
}

Expand Down
7 changes: 4 additions & 3 deletions kv/bbolt/bolt.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package bbolt
import (
"bytes"
"context"
"errors"
"time"

bolt "go.etcd.io/bbolt"
Expand Down Expand Up @@ -165,7 +166,7 @@ func (tx *Tx) Put(k kv.Key, v kv.Value) error {
return nil // bucket creation, no need to put value
}
err = b.Put(k[0], v)
if err == bolt.ErrTxNotWritable {
if errors.Is(err, bolt.ErrTxNotWritable) {
err = kv.ErrReadOnly
}
return err
Expand All @@ -177,8 +178,8 @@ func (tx *Tx) Del(k kv.Key) error {
return nil
}
err := b.Delete(k[0])
if err == bolt.ErrTxNotWritable {
err = kv.ErrReadOnly
if errors.Is(err, bolt.ErrTxNotWritable) {
return kv.ErrReadOnly
}
return err
}
Expand Down
5 changes: 3 additions & 2 deletions kv/bbolt/bolt_test.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package bbolt
package bbolt_test

import (
"path/filepath"
"testing"

"github.com/hidal-go/hidalgo/kv"
"github.com/hidal-go/hidalgo/kv/bbolt"
"github.com/hidal-go/hidalgo/kv/kvtest"
)

func TestBBolt(t *testing.T) {
kvtest.RunTestLocal(t, func(path string) (kv.KV, error) {
path = filepath.Join(path, "bbolt.db")
return OpenPath(path)
return bbolt.OpenPath(path)
}, nil)
}
5 changes: 3 additions & 2 deletions kv/bolt/bolt.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package bolt
import (
"bytes"
"context"
"errors"
"time"

"github.com/boltdb/bolt"
Expand Down Expand Up @@ -165,7 +166,7 @@ func (tx *Tx) Put(k kv.Key, v kv.Value) error {
return nil // bucket creation, no need to put value
}
err = b.Put(k[0], v)
if err == bolt.ErrTxNotWritable {
if errors.Is(err, bolt.ErrTxNotWritable) {
err = kv.ErrReadOnly
}
return err
Expand All @@ -177,7 +178,7 @@ func (tx *Tx) Del(k kv.Key) error {
return nil
}
err := b.Delete(k[0])
if err == bolt.ErrTxNotWritable {
if errors.Is(err, bolt.ErrTxNotWritable) {
err = kv.ErrReadOnly
}
return err
Expand Down
5 changes: 3 additions & 2 deletions kv/bolt/bolt_test.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package bolt
package bolt_test

import (
"path/filepath"
"testing"

"github.com/hidal-go/hidalgo/kv"
"github.com/hidal-go/hidalgo/kv/bolt"
"github.com/hidal-go/hidalgo/kv/kvtest"
)

func TestBolt(t *testing.T) {
kvtest.RunTestLocal(t, func(path string) (kv.KV, error) {
path = filepath.Join(path, "bolt.db")
return OpenPath(path)
return bolt.OpenPath(path)
}, nil)
}
11 changes: 6 additions & 5 deletions kv/flat/badger/badger.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package badger

import (
"context"
"errors"

"github.com/dgraph-io/badger/v2"

Expand Down Expand Up @@ -85,7 +86,7 @@ type Tx struct {

func (tx *Tx) Commit(ctx context.Context) error {
err := tx.tx.Commit()
if err == badger.ErrConflict {
if errors.Is(err, badger.ErrConflict) {
err = flat.ErrConflict
}
return err
Expand All @@ -101,7 +102,7 @@ func (tx *Tx) Get(ctx context.Context, key flat.Key) (flat.Value, error) {
return nil, flat.ErrNotFound
}
item, err := tx.tx.Get(key)
if err == badger.ErrKeyNotFound {
if errors.Is(err, badger.ErrKeyNotFound) {
return nil, flat.ErrNotFound
} else if err != nil {
return nil, err
Expand All @@ -115,15 +116,15 @@ func (tx *Tx) GetBatch(ctx context.Context, keys []flat.Key) ([]flat.Value, erro

func (tx *Tx) Put(k flat.Key, v flat.Value) error {
err := tx.tx.Set(k, v)
if err == badger.ErrConflict {
if errors.Is(err, badger.ErrConflict) {
err = flat.ErrConflict
}
return err
}

func (tx *Tx) Del(k flat.Key) error {
err := tx.tx.Delete(k)
if err == badger.ErrConflict {
if errors.Is(err, badger.ErrConflict) {
err = flat.ErrConflict
}
return err
Expand All @@ -142,11 +143,11 @@ var (
)

type Iterator struct {
err error
it *badger.Iterator
pref flat.Key
first bool
valid bool
err error
}

func (it *Iterator) Reset() {
Expand Down
5 changes: 3 additions & 2 deletions kv/flat/badger/badger_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package badger
package badger_test

import (
"testing"

"github.com/hidal-go/hidalgo/kv/flat"
"github.com/hidal-go/hidalgo/kv/flat/badger"
"github.com/hidal-go/hidalgo/kv/kvtest"
)

func TestBadger(t *testing.T) {
kvtest.RunTestLocal(t, flat.UpgradeOpenPath(OpenPath), nil)
kvtest.RunTestLocal(t, flat.UpgradeOpenPath(badger.OpenPath), nil)
}
3 changes: 2 additions & 1 deletion kv/flat/btree/btree.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package btree
import (
"bytes"
"context"
"errors"
"io"

"github.com/hidal-go/hidalgo/base"
Expand Down Expand Up @@ -152,7 +153,7 @@ func (it *Iterator) WithPrefix(pref flat.Key) flat.Iterator {

func (it *Iterator) next() bool {
k, v, err := it.e.Next()
if err == io.EOF {
if errors.Is(err, io.EOF) {
return false
} else if !bytes.HasPrefix(k, it.pref) {
return false
Expand Down
7 changes: 4 additions & 3 deletions kv/flat/btree/btree_test.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package btree
package btree_test

import (
"testing"

"github.com/hidal-go/hidalgo/kv"
"github.com/hidal-go/hidalgo/kv/flat"
"github.com/hidal-go/hidalgo/kv/flat/btree"
"github.com/hidal-go/hidalgo/kv/kvtest"
)

func TestBtree(t *testing.T) {
kvtest.RunTest(t, func(t testing.TB) kv.KV {
return flat.Upgrade(New())
kvtest.RunTest(t, func(tb testing.TB) kv.KV {
return flat.Upgrade(btree.New())
}, nil)
}
Loading