add badger

This commit is contained in:
Gitea
2024-01-24 16:17:28 +03:00
parent 5b5dc2165c
commit f94d39b124
5 changed files with 535 additions and 1 deletions

View File

@ -0,0 +1,47 @@
package badger
import (
"git.loyso.art/frx/eway/internal/entity"
badger "github.com/dgraph-io/badger/v4"
)
var (
categorySequenceIDKey = []byte("cat:")
)
type client struct {
db *badger.DB
// nextCategoryIDSeq *badger.Sequence
}
func NewClient(db *badger.DB) (*client, error) {
// categorySeqGen, err := db.GetSequence(categorySequenceIDKey, 10)
// if err != nil {
// return nil, fmt.Errorf("getting sequence for categories: %w", err)
// }
//
return &client{
db: db,
// nextCategoryIDSeq: categorySeqGen,
}, nil
}
// Close closes the underlying sequences in the client. Should be called right before
// underlying *badger.DB closed.
func (c *client) Close() error {
// err := c.nextCategoryIDSeq.Release()
// if err != nil {
// return fmt.Errorf("releasing next_category_sequence: %w", err)
// }
return nil
}
func (c *client) Category() entity.CategoryRepository {
return newCategoryClient(c.db, nil)
}
func (c *client) GoodsItem() entity.GoodsItemRepository {
return newGoodsItemClient(c.db)
}