Skip to content

Commit dc8300d

Browse files
committed
[update] refactoring
1 parent 32e6af6 commit dc8300d

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

sql.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func (f *Filter) getValues() []interface{} {
3939
}
4040

4141
type CustomOperation func(string, string, []interface{}) (string, []interface{}, error)
42-
type CustomPredicate func(string, string, []interface{}) (string, []interface{}, error)
42+
type CustomPredicate func(string, string) (string, error)
4343

4444
type CheckFunction = func(string) bool
4545
type SQLConfig struct {
@@ -96,10 +96,12 @@ func GetSQL(data Filter, config *SQLConfig, dbArr ...DBDriver) (string, []interf
9696
var err error
9797
if config != nil && config.Predicates != nil {
9898
if pr, prOk := config.Predicates[data.Predicate]; prOk {
99-
name, values, err = pr(name, data.Predicate, values)
99+
name, err = pr(name, data.Predicate)
100100
if err != nil {
101101
return "", NoValues, err
102102
}
103+
} else {
104+
return "", NoValues, fmt.Errorf("unknown predicate: %s", data.Predicate)
103105
}
104106
}
105107

sql_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -497,11 +497,11 @@ func TestCustomPredicate(t *testing.T) {
497497

498498
sql, vals, err := GetSQL(format, &SQLConfig{
499499
Predicates: map[string]CustomPredicate{
500-
"month": func(n string, p string, values []interface{}) (string, []interface{}, error) {
501-
return fmt.Sprintf("month(%s)", n), values, nil
500+
"month": func(n string, p string) (string, error) {
501+
return fmt.Sprintf("month(%s)", n), nil
502502
},
503-
"year": func(n string, p string, values []interface{}) (string, []interface{}, error) {
504-
return fmt.Sprintf("year(%s)", n), values, nil
503+
"year": func(n string, p string) (string, error) {
504+
return fmt.Sprintf("year(%s)", n), nil
505505
},
506506
},
507507
})
@@ -539,11 +539,11 @@ func TestCustomPredicatePG(t *testing.T) {
539539

540540
sql, vals, err := GetSQL(format, &SQLConfig{
541541
Predicates: map[string]CustomPredicate{
542-
"month": func(n string, p string, values []interface{}) (string, []interface{}, error) {
543-
return fmt.Sprintf("date_part('month', %s)", n), values, nil
542+
"month": func(n string, p string) (string, error) {
543+
return fmt.Sprintf("date_part('month', %s)", n), nil
544544
},
545-
"year": func(n string, p string, values []interface{}) (string, []interface{}, error) {
546-
return fmt.Sprintf("date_part('year', %s)", n), values, nil
545+
"year": func(n string, p string) (string, error) {
546+
return fmt.Sprintf("date_part('year', %s)", n), nil
547547
},
548548
},
549549
}, &PostgreSQL{})

0 commit comments

Comments
 (0)