Эх сурвалжийг харах

revert experimental package split

Aneurin Barker Snook 11 сар өмнө
parent
commit
a190ad8ca9
8 өөрчлөгдсөн 25 нэмэгдсэн , 48 устгасан
  1. 2 5
      README.md
  2. 0 10
      ezleveldb/go.mod
  3. 4 0
      go.mod
  4. 1 4
      go.sum
  5. 5 6
      leveldb.go
  6. 9 12
      leveldb_iter.go
  7. 1 1
      leveldb_options.go
  8. 3 10
      leveldb_test.go

+ 2 - 5
README.md

@@ -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)

+ 0 - 10
ezleveldb/go.mod

@@ -1,10 +0,0 @@
-module github.com/annybs/ezdb/ezleveldb
-
-go 1.21.4
-
-require (
-	github.com/annybs/ezdb v0.0.0-20240709224005-e48c3d80e0cc
-	github.com/syndtr/goleveldb v1.0.0
-)
-
-require github.com/golang/snappy v0.0.4 // indirect

+ 4 - 0
go.mod

@@ -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

+ 1 - 4
ezleveldb/go.sum → go.sum

@@ -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=

+ 5 - 6
ezleveldb/leveldb.go → leveldb.go

@@ -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"
 )
@@ -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
@@ -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,
@@ -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
 	}
 
@@ -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,
 

+ 9 - 12
ezleveldb/leveldb_iter.go → leveldb_iter.go

@@ -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 {
@@ -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() {
@@ -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 {
@@ -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)
 }
 

+ 1 - 1
ezleveldb/leveldb_options.go → leveldb_options.go

@@ -1,4 +1,4 @@
-package ezleveldb
+package ezdb
 
 import "github.com/syndtr/goleveldb/leveldb/opt"
 

+ 3 - 10
ezleveldb/leveldb_test.go → leveldb_test.go

@@ -1,10 +1,8 @@
-package ezleveldb
+package ezdb
 
 import (
 	"fmt"
 	"testing"
-
-	"github.com/annybs/ezdb"
 )
 
 func TestLevelDB(t *testing.T) {
@@ -15,7 +13,7 @@ func TestLevelDB(t *testing.T) {
 
 	path := ".leveldb/test_json"
 
-	marshaler := ezdb.JSON(func() *Student {
+	marshaler := JSON(func() *Student {
 		return &Student{}
 	})
 
@@ -35,7 +33,7 @@ func TestLevelDB(t *testing.T) {
 		return nil
 	}
 
-	tester := &ezdb.CollectionTester[*Student]{
+	tester := &CollectionTester[*Student]{
 		C: collection,
 
 		Cmp: cmp,
@@ -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),
@@ -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()