[wip] impove filter interfaces
Signed-off-by: Anton Nesterov <anton@demiurg.io>
This commit is contained in:
parent
4198ec4c75
commit
9fae95b906
|
@ -1,21 +1,19 @@
|
||||||
package dal
|
package dal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
filters "l12.xyz/dal/filters"
|
filters "l12.xyz/dal/filters"
|
||||||
)
|
)
|
||||||
|
|
||||||
func CovertFind(find filters.Find, ctx filters.Context) string {
|
func CovertFind(find Find, ctx Context) string {
|
||||||
expressions := []string{}
|
expressions := []string{}
|
||||||
for key, value := range find {
|
for key, value := range find {
|
||||||
values, err := filters.Convert(ctx.New(map[string]string{
|
context := ctx.New(CtxOpts{
|
||||||
"FieldName": key,
|
"FieldName": key,
|
||||||
}), value)
|
})
|
||||||
|
values, _ := filters.Convert(context, value)
|
||||||
expressions = append(expressions, values)
|
expressions = append(expressions, values)
|
||||||
fmt.Println(err)
|
|
||||||
|
|
||||||
}
|
}
|
||||||
return strings.Join(expressions, " AND ")
|
return strings.Join(expressions, " AND ")
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,10 +7,10 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestConvertFind(t *testing.T) {
|
func TestConvertFind(t *testing.T) {
|
||||||
find := f.Find{
|
find := Find{
|
||||||
"test": "1",
|
"test": "1",
|
||||||
"test2": "2",
|
"test2": "2",
|
||||||
"test3": f.Filter{
|
"test3": Filter{
|
||||||
"$ne": 1,
|
"$ne": 1,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
10
pkg/dal/types.go
Normal file
10
pkg/dal/types.go
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
package dal
|
||||||
|
|
||||||
|
import (
|
||||||
|
filters "l12.xyz/dal/filters"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Find = filters.Find
|
||||||
|
type Filter = filters.Filter
|
||||||
|
type Context = filters.Context
|
||||||
|
type CtxOpts = filters.CtxOpts
|
|
@ -14,7 +14,7 @@ type SQLiteContext struct {
|
||||||
FieldName string
|
FieldName string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c SQLiteContext) New(opts map[string]string) Context {
|
func (c SQLiteContext) New(opts CtxOpts) Context {
|
||||||
ta := opts["TableAlias"]
|
ta := opts["TableAlias"]
|
||||||
if ta == "" {
|
if ta == "" {
|
||||||
ta = c.TableAlias
|
ta = c.TableAlias
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
package filters
|
package filters
|
||||||
|
|
||||||
|
type CtxOpts map[string]string
|
||||||
type Context interface {
|
type Context interface {
|
||||||
New(opts map[string]string) Context
|
New(opts CtxOpts) Context
|
||||||
GetFieldName() string
|
GetFieldName() string
|
||||||
NormalizeValue(interface{}) interface{}
|
NormalizeValue(interface{}) interface{}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue