-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch_load.go
24 lines (21 loc) · 981 Bytes
/
search_load.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
package cassandra
import (
"context"
"github.com/apache/cassandra-gocql-driver"
"reflect"
)
func NewSearchLoader(db *gocql.ClusterConfig, tableName string, modelType reflect.Type, buildQuery func(interface{}) (string, []interface{}), options ...func(context.Context, interface{}) (interface{}, error)) (*Searcher, *Loader, error) {
return NewSqlSearchLoader(db, tableName, modelType, buildQuery, options...)
}
func NewSqlSearchLoader(db *gocql.ClusterConfig, tableName string, modelType reflect.Type, buildQuery func(interface{}) (string, []interface{}), options ...func(context.Context, interface{}) (interface{}, error)) (*Searcher, *Loader, error) {
var mp func(context.Context, interface{}) (interface{}, error)
if len(options) >= 1 {
mp = options[0]
}
loader, er0 := NewLoader(db, tableName, modelType, mp)
if er0 != nil {
return nil, loader, er0
}
searcher, er1 := NewSearcherWithQuery(db, modelType, buildQuery, options...)
return searcher, loader, er1
}