-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearcher.go
26 lines (22 loc) · 973 Bytes
/
searcher.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package cassandra
import (
"context"
"github.com/apache/cassandra-gocql-driver"
"reflect"
)
type Searcher struct {
search func(ctx context.Context, searchModel interface{}, results interface{}, limit int64, nextPageToken string) (string, error)
}
func NewSearcher(search func(context.Context, interface{}, interface{}, int64, string) (string, error)) *Searcher {
return &Searcher{search: search}
}
func (s *Searcher) Search(ctx context.Context, m interface{}, results interface{}, limit int64, nextPageToken string) (string, error) {
return s.search(ctx, m, results, limit, nextPageToken)
}
func NewSearcherWithQuery(db *gocql.ClusterConfig, modelType reflect.Type, buildQuery func(interface{}) (string, []interface{}), options ...func(context.Context, interface{}) (interface{}, error)) (*Searcher, error) {
builder, err := NewSearchBuilder(db, modelType, buildQuery, options...)
if err != nil {
return nil, err
}
return NewSearcher(builder.Search), nil
}