2020-10-28 14:49:30 +00:00
|
|
|
package meta
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/nspcc-dev/neofs-api-go/pkg/object"
|
2020-10-29 16:12:38 +00:00
|
|
|
v2object "github.com/nspcc-dev/neofs-api-go/v2/object"
|
2020-10-28 14:49:30 +00:00
|
|
|
"go.etcd.io/bbolt"
|
|
|
|
)
|
|
|
|
|
|
|
|
// DB represents local metabase of storage node.
|
|
|
|
type DB struct {
|
|
|
|
boltDB *bbolt.DB
|
|
|
|
|
2020-10-29 16:12:38 +00:00
|
|
|
matchers map[object.SearchMatchType]func(string, string, string) bool
|
2020-10-28 14:49:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewDB creates, initializes and returns DB instance.
|
|
|
|
func NewDB(boltDB *bbolt.DB) *DB {
|
|
|
|
return &DB{
|
|
|
|
boltDB: boltDB,
|
2020-10-29 16:12:38 +00:00
|
|
|
matchers: map[object.SearchMatchType]func(string, string, string) bool{
|
|
|
|
object.MatchStringEqual: stringEqualMatcher,
|
2020-10-28 14:49:30 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
2020-10-29 16:12:38 +00:00
|
|
|
|
2020-10-29 17:16:49 +00:00
|
|
|
func (db *DB) Close() error {
|
|
|
|
return db.boltDB.Close()
|
|
|
|
}
|
|
|
|
|
2020-10-29 16:12:38 +00:00
|
|
|
func stringEqualMatcher(key, objVal, filterVal string) bool {
|
|
|
|
switch key {
|
|
|
|
default:
|
|
|
|
return objVal == filterVal
|
|
|
|
case
|
|
|
|
v2object.FilterPropertyRoot,
|
|
|
|
v2object.FilterPropertyChildfree,
|
|
|
|
v2object.FilterPropertyLeaf:
|
|
|
|
return (filterVal == v2object.BooleanPropertyValueTrue) == (objVal == v2object.BooleanPropertyValueTrue)
|
|
|
|
}
|
|
|
|
}
|