2020-11-17 12:23:15 +00:00
|
|
|
package shard
|
|
|
|
|
|
|
|
import (
|
|
|
|
objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object"
|
2020-11-17 17:39:43 +00:00
|
|
|
"github.com/pkg/errors"
|
2020-11-17 12:23:15 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// SelectPrm groups the parameters of Select operation.
|
|
|
|
type SelectPrm struct {
|
|
|
|
filters objectSDK.SearchFilters
|
|
|
|
}
|
|
|
|
|
|
|
|
// SelectRes groups resulting values of Select operation.
|
|
|
|
type SelectRes struct {
|
|
|
|
addrList []*objectSDK.Address
|
|
|
|
}
|
|
|
|
|
|
|
|
// WithFilters is a Select option to set the object filters.
|
|
|
|
func (p *SelectPrm) WithFilters(fs objectSDK.SearchFilters) *SelectPrm {
|
|
|
|
if p != nil {
|
|
|
|
p.filters = fs
|
|
|
|
}
|
|
|
|
|
|
|
|
return p
|
|
|
|
}
|
|
|
|
|
|
|
|
// AddressList returns list of addresses of the selected objects.
|
|
|
|
func (r *SelectRes) AddressList() []*objectSDK.Address {
|
|
|
|
return r.addrList
|
|
|
|
}
|
|
|
|
|
|
|
|
// Select selects the objects from shard that match select parameters.
|
|
|
|
//
|
|
|
|
// Returns any error encountered that
|
|
|
|
// did not allow to completely select the objects.
|
|
|
|
func (s *Shard) Select(prm *SelectPrm) (*SelectRes, error) {
|
2020-11-17 17:39:43 +00:00
|
|
|
addrList, err := s.metaBase.Select(prm.filters)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "could not select objects from metabase")
|
|
|
|
}
|
2020-11-17 12:23:15 +00:00
|
|
|
|
2020-11-17 17:39:43 +00:00
|
|
|
return &SelectRes{
|
|
|
|
addrList: addrList,
|
|
|
|
}, nil
|
2020-11-17 12:23:15 +00:00
|
|
|
}
|