fix(storage,sqlite): in operator sqlite translation
This commit is contained in:
@ -102,6 +102,7 @@ func (s *DocumentStore) Query(ctx context.Context, collection string, filter *fi
|
||||
criteria, args, err = filterSQL.ToSQL(
|
||||
filter.Root(),
|
||||
filterSQL.WithPreparedParameter("$", 2),
|
||||
filterSQL.WithTransform(transformOperator),
|
||||
filterSQL.WithKeyTransform(func(key string) string {
|
||||
return fmt.Sprintf("json_extract(data, '$.%s')", key)
|
||||
}),
|
||||
|
24
pkg/storage/sqlite/filter.go
Normal file
24
pkg/storage/sqlite/filter.go
Normal file
@ -0,0 +1,24 @@
|
||||
package sqlite
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"forge.cadoles.com/arcad/edge/pkg/storage/filter/sql"
|
||||
)
|
||||
|
||||
func transformOperator(operator string, invert bool, key string, value any, option *sql.Option) (string, any, error) {
|
||||
switch operator {
|
||||
case sql.OpIn:
|
||||
return transformInOperator(key, value, option)
|
||||
default:
|
||||
return sql.DefaultTransform(operator, invert, key, value, option)
|
||||
}
|
||||
}
|
||||
|
||||
func transformInOperator(key string, value any, option *sql.Option) (string, any, error) {
|
||||
return fmt.Sprintf(
|
||||
"EXISTS (SELECT 1 FROM json_each(json_extract(data, \"$.%v\")) WHERE value = %v)",
|
||||
key,
|
||||
option.PreparedParameter(),
|
||||
), option.ValueTransform(value), nil
|
||||
}
|
Reference in New Issue
Block a user