Skip to content

Commit

Permalink
revert experimental package split
Browse files Browse the repository at this point in the history
  • Loading branch information
annybs committed Jul 9, 2024
1 parent 9c13133 commit a190ad8
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 48 deletions.
7 changes: 2 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,13 @@ The following marshalers are included in EZ DB:

- `JSON[T]` marshals your data `T` to `[]byte` using [encoding/json](https://pkg.go.dev/encoding/json)

## Database backends
## Supported databases

The following databases are included in EZ DB:

- `LevelDB[T]` is [fast key-value storage](https://github.com/google/leveldb) on disk
- `Memory[T]` is essentially a wrapper for `map[string]T`. It can be provided another Collection to use as a persistence backend

## Additional databases

- [github.com/annybs/ezdb/ezleveldb](./ezleveldb) provides [fast key-value storage](https://github.com/google/leveldb) on disk

## License

See [LICENSE.md](./LICENSE.md)
10 changes: 0 additions & 10 deletions ezleveldb/go.mod

This file was deleted.

4 changes: 4 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
module github.com/annybs/ezdb

go 1.21

require github.com/syndtr/goleveldb v1.0.0

require github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db // indirect
5 changes: 1 addition & 4 deletions ezleveldb/go.sum → go.sum
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
github.com/annybs/ezdb v0.0.0-20240709224005-e48c3d80e0cc h1:hEo3EEfvXa24/1SMTgMLR1wa5hm7Riv87Sm2MXlyKoo=
github.com/annybs/ezdb v0.0.0-20240709224005-e48c3d80e0cc/go.mod h1:t/+S038qLmn01xEoVDkPsSbZTMgYYFsB4oshA2jmTdg=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db h1:woRePGFeVFfLKN/pOkfl+p/TAqKOfFu+7KPlMVpok/w=
github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM=
github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
Expand Down
11 changes: 5 additions & 6 deletions ezleveldb/leveldb.go → leveldb.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package ezleveldb
package ezdb

import (
"os"

"github.com/annybs/ezdb"
"github.com/syndtr/goleveldb/leveldb"
"github.com/syndtr/goleveldb/leveldb/opt"
)
Expand All @@ -12,7 +11,7 @@ type LevelDBCollection[T any] struct {
path string

db *leveldb.DB
m ezdb.DocumentMarshaler[T, []byte]
m DocumentMarshaler[T, []byte]

optOpen *opt.Options
optRead *opt.ReadOptions
Expand Down Expand Up @@ -94,7 +93,7 @@ func (c *LevelDBCollection[T]) Has(key string) (bool, error) {
return c.db.Has([]byte(key), c.optRead)
}

func (c *LevelDBCollection[T]) Iter() ezdb.Iterator[T] {
func (c *LevelDBCollection[T]) Iter() Iterator[T] {
i := &LevelDBIterator[T]{
i: c.db.NewIterator(nil, c.optRead),
m: c.m,
Expand All @@ -117,7 +116,7 @@ func (c *LevelDBCollection[T]) Open() error {
}

func (c *LevelDBCollection[T]) Put(key string, src T) error {
if err := ezdb.ValidateKey(key); err != nil {
if err := ValidateKey(key); err != nil {
return err
}

Expand All @@ -130,7 +129,7 @@ func (c *LevelDBCollection[T]) Put(key string, src T) error {
}

// LevelDB creates a new collection using LevelDB storage.
func LevelDB[T any](path string, m ezdb.DocumentMarshaler[T, []byte], o *LevelDBOptions) *LevelDBCollection[T] {
func LevelDB[T any](path string, m DocumentMarshaler[T, []byte], o *LevelDBOptions) *LevelDBCollection[T] {
c := &LevelDBCollection[T]{
path: path,

Expand Down
21 changes: 9 additions & 12 deletions ezleveldb/leveldb_iter.go → leveldb_iter.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
package ezleveldb
package ezdb

import (
"github.com/annybs/ezdb"
"github.com/syndtr/goleveldb/leveldb/iterator"
)
import "github.com/syndtr/goleveldb/leveldb/iterator"

type LevelDBIterator[T any] struct {
i iterator.Iterator
m ezdb.DocumentMarshaler[T, []byte]
m DocumentMarshaler[T, []byte]
}

func (i *LevelDBIterator[T]) Count() int {
Expand All @@ -24,7 +21,7 @@ func (i *LevelDBIterator[T]) Count() int {
return n
}

func (i *LevelDBIterator[T]) Filter(f ezdb.FilterFunc[T]) ezdb.Iterator[T] {
func (i *LevelDBIterator[T]) Filter(f FilterFunc[T]) Iterator[T] {
m := map[string]T{}

if i.First() {
Expand All @@ -42,7 +39,7 @@ func (i *LevelDBIterator[T]) Filter(f ezdb.FilterFunc[T]) ezdb.Iterator[T] {
m[key] = value
}

return ezdb.MemoryIter(m, nil, i)
return MemoryIter(m, nil, i)
}

func (i *LevelDBIterator[T]) First() bool {
Expand Down Expand Up @@ -110,15 +107,15 @@ func (i *LevelDBIterator[T]) Release() {
i.i.Release()
}

func (i *LevelDBIterator[T]) Sort(f ezdb.SortFunc[T]) ezdb.Iterator[T] {
func (i *LevelDBIterator[T]) Sort(f SortFunc[T]) Iterator[T] {
all, _ := i.GetAll()
m := ezdb.MemoryIter(all, nil, i)
m := MemoryIter(all, nil, i)
return m.Sort(f)
}

func (i *LevelDBIterator[T]) SortKeys(f ezdb.SortFunc[string]) ezdb.Iterator[T] {
func (i *LevelDBIterator[T]) SortKeys(f SortFunc[string]) Iterator[T] {
all, _ := i.GetAll()
m := ezdb.MemoryIter(all, nil, i)
m := MemoryIter(all, nil, i)
return m.SortKeys(f)
}

Expand Down
2 changes: 1 addition & 1 deletion ezleveldb/leveldb_options.go → leveldb_options.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ezleveldb
package ezdb

import "github.com/syndtr/goleveldb/leveldb/opt"

Expand Down
13 changes: 3 additions & 10 deletions ezleveldb/leveldb_test.go → leveldb_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package ezleveldb
package ezdb

import (
"fmt"
"testing"

"github.com/annybs/ezdb"
)

func TestLevelDB(t *testing.T) {
Expand All @@ -15,7 +13,7 @@ func TestLevelDB(t *testing.T) {

path := ".leveldb/test_json"

marshaler := ezdb.JSON(func() *Student {
marshaler := JSON(func() *Student {
return &Student{}
})

Expand All @@ -35,7 +33,7 @@ func TestLevelDB(t *testing.T) {
return nil
}

tester := &ezdb.CollectionTester[*Student]{
tester := &CollectionTester[*Student]{
C: collection,

Cmp: cmp,
Expand All @@ -56,10 +54,6 @@ func TestLevelDB(t *testing.T) {
}
}

destroy := func() error {
return collection.Destroy()
}

sequence := []func(){
named("init 1", tester.Init),
named("has", tester.Has),
Expand All @@ -75,7 +69,6 @@ func TestLevelDB(t *testing.T) {
named("iterSortKeys", tester.IterSortKeys),
named("deleteAll", tester.DeleteAll),
named("close", tester.Close),
named("destroy", destroy),
}
for _, do := range sequence {
do()
Expand Down

0 comments on commit a190ad8

Please sign in to comment.