appview: db: add FilterBetween #520

closed
opened by ptr.pet targeting master from [deleted fork]: pipeline-paginated
Changed files
+7
appview
db
+7
appview/db/db.go
··· 939 939 func FilterIs(key string, arg any) filter { return newFilter(key, "is", arg) } 940 940 func FilterIsNot(key string, arg any) filter { return newFilter(key, "is not", arg) } 941 941 func FilterIn(key string, arg any) filter { return newFilter(key, "in", arg) } 942 + func FilterBetween(key string, arg1, arg2 any) filter { 943 + return newFilter(key, "between", []any{arg1, arg2}) 944 + } 942 945 943 946 func (f filter) Condition() string { 944 947 rv := reflect.ValueOf(f.arg) 945 948 kind := rv.Kind() 946 949 950 + if f.cmp == "between" { 951 + return fmt.Sprintf("%s %s ? and ?", f.key, f.cmp) 952 + } 953 + 947 954 // if we have `FilterIn(k, [1, 2, 3])`, compile it down to `k in (?, ?, ?)` 948 955 if (kind == reflect.Slice && rv.Type().Elem().Kind() != reflect.Uint8) || kind == reflect.Array { 949 956 if rv.Len() == 0 {