Skip to content

Commit

Permalink
Updated version and test
Browse files Browse the repository at this point in the history
  • Loading branch information
d.mandrika committed May 31, 2024
1 parent 5d02b1e commit e20fe1d
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 30 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/censync/go-squirrel-querytool
go 1.14

require (
github.com/Masterminds/squirrel v1.4.0
github.com/Masterminds/squirrel v1.5.4
github.com/friendsofgo/errors v0.9.2
github.com/lib/pq v1.7.0
github.com/lib/pq v1.10.9
)
6 changes: 5 additions & 1 deletion query_tool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ func TestApplyQuery(t *testing.T) {
jsonQuery := `{
"filters": {
"user_id": 123,
"name": {"in": ["sdf", "fdsg"]}
"name": {"in": ["sdf", "fdsg"]},
"flag": true,
"balance": {"gte": 4.3242}
},
"sorting": ["user_id"],
"offset": 1000
Expand All @@ -29,6 +31,8 @@ func TestApplyQuery(t *testing.T) {
Resolvers: map[string]FilterResolver{
"user_id": Int,
"name": String,
"flag": Boolean,
"balance": Float,
},
DefaultLimit: 321,
}
Expand Down
54 changes: 27 additions & 27 deletions resolvers.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (ir IntResolver) ToExpr(arg interface{}, label string) (string, []interface
return "", nil, ErrWrongType
}

if _, ok := m["="]; ok {
if _, ok = m["="]; ok {
sl, ok := m["="].(float64)
if !ok {
return "", nil, ErrWrongType
Expand All @@ -48,7 +48,7 @@ func (ir IntResolver) ToExpr(arg interface{}, label string) (string, []interface
and = append(and, squirrel.Eq{label: sl})
}

if _, ok := m["!="]; ok {
if _, ok = m["!="]; ok {
sl, ok := m["!="].(float64)
if !ok {
return "", nil, ErrWrongType
Expand All @@ -57,7 +57,7 @@ func (ir IntResolver) ToExpr(arg interface{}, label string) (string, []interface
and = append(and, squirrel.NotEq{label: sl})
}

if _, ok := m["in"]; ok {
if _, ok = m["in"]; ok {
sl, ok := m["in"].([]interface{})
if !ok {
return "", nil, ErrWrongType
Expand All @@ -75,7 +75,7 @@ func (ir IntResolver) ToExpr(arg interface{}, label string) (string, []interface
and = append(and, squirrel.Eq{label: arr})
}

if _, ok := m["gt"]; ok {
if _, ok = m["gt"]; ok {
sl, ok := m["gt"].(float64)
if !ok {
return "", nil, ErrWrongType
Expand All @@ -84,7 +84,7 @@ func (ir IntResolver) ToExpr(arg interface{}, label string) (string, []interface
and = append(and, squirrel.Gt{label: sl})
}

if _, ok := m["gte"]; ok {
if _, ok = m["gte"]; ok {
sl, ok := m["gte"].(float64)
if !ok {
return "", nil, ErrWrongType
Expand All @@ -93,7 +93,7 @@ func (ir IntResolver) ToExpr(arg interface{}, label string) (string, []interface
and = append(and, squirrel.GtOrEq{label: sl})
}

if _, ok := m["lt"]; ok {
if _, ok = m["lt"]; ok {
sl, ok := m["lt"].(float64)
if !ok {
return "", nil, ErrWrongType
Expand All @@ -102,7 +102,7 @@ func (ir IntResolver) ToExpr(arg interface{}, label string) (string, []interface
and = append(and, squirrel.Lt{label: sl})
}

if _, ok := m["lte"]; ok {
if _, ok = m["lte"]; ok {
sl, ok := m["lte"].(float64)
if !ok {
return "", nil, ErrWrongType
Expand Down Expand Up @@ -133,7 +133,7 @@ func (fr FloatResolver) ToExpr(arg interface{}, label string) (string, []interfa
return "", nil, ErrWrongType
}

if _, ok := m["in"]; ok {
if _, ok = m["in"]; ok {
sl, ok := m["in"].([]interface{})
if !ok {
return "", nil, ErrWrongType
Expand All @@ -151,7 +151,7 @@ func (fr FloatResolver) ToExpr(arg interface{}, label string) (string, []interfa
and = append(and, squirrel.Eq{label: arr})
}

if _, ok := m["="]; ok {
if _, ok = m["="]; ok {
sl, ok := m["="].(float64)
if !ok {
return "", nil, ErrWrongType
Expand All @@ -160,7 +160,7 @@ func (fr FloatResolver) ToExpr(arg interface{}, label string) (string, []interfa
and = append(and, squirrel.Eq{label: sl})
}

if _, ok := m["not in"]; ok {
if _, ok = m["not in"]; ok {
sl, ok := m["not in"].([]interface{})
if !ok {
return "", nil, ErrWrongType
Expand All @@ -169,7 +169,7 @@ func (fr FloatResolver) ToExpr(arg interface{}, label string) (string, []interfa
and = append(and, squirrel.NotEq{label: sl})
}

if _, ok := m["!="]; ok {
if _, ok = m["!="]; ok {
sl, ok := m["!="].(float64)
if !ok {
return "", nil, ErrWrongType
Expand All @@ -178,7 +178,7 @@ func (fr FloatResolver) ToExpr(arg interface{}, label string) (string, []interfa
and = append(and, squirrel.NotEq{label: sl})
}

if _, ok := m["gt"]; ok {
if _, ok = m["gt"]; ok {
sl, ok := m["gt"].(float64)
if !ok {
return "", nil, ErrWrongType
Expand All @@ -187,7 +187,7 @@ func (fr FloatResolver) ToExpr(arg interface{}, label string) (string, []interfa
and = append(and, squirrel.Gt{label: sl})
}

if _, ok := m["gte"]; ok {
if _, ok = m["gte"]; ok {
sl, ok := m["gte"].(float64)
if !ok {
return "", nil, ErrWrongType
Expand All @@ -196,7 +196,7 @@ func (fr FloatResolver) ToExpr(arg interface{}, label string) (string, []interfa
and = append(and, squirrel.GtOrEq{label: sl})
}

if _, ok := m["lt"]; ok {
if _, ok = m["lt"]; ok {
sl, ok := m["lt"].(float64)
if !ok {
return "", nil, ErrWrongType
Expand All @@ -205,7 +205,7 @@ func (fr FloatResolver) ToExpr(arg interface{}, label string) (string, []interfa
and = append(and, squirrel.Lt{label: sl})
}

if _, ok := m["lte"]; ok {
if _, ok = m["lte"]; ok {
sl, ok := m["lte"].(float64)
if !ok {
return "", nil, ErrWrongType
Expand Down Expand Up @@ -238,7 +238,7 @@ func (sr StringResolver) ToExpr(arg interface{}, label string) (string, []interf
return squirrel.Expr(fmt.Sprintf("%s LIKE ?", label), i).ToSql()
}

if _, ok := m["in"]; ok {
if _, ok = m["in"]; ok {
sl, ok := m["in"].([]interface{})
if !ok {
return "", nil, ErrWrongType
Expand All @@ -256,7 +256,7 @@ func (sr StringResolver) ToExpr(arg interface{}, label string) (string, []interf
return squirrel.Eq{label: pq.StringArray(arr)}.ToSql()
}

if _, ok := m["="]; ok {
if _, ok = m["="]; ok {
sl, ok := m["="].(string)
if !ok {
return "", nil, ErrWrongType
Expand All @@ -265,7 +265,7 @@ func (sr StringResolver) ToExpr(arg interface{}, label string) (string, []interf
return squirrel.Eq{label: sl}.ToSql()
}

if _, ok := m["!="]; ok {
if _, ok = m["!="]; ok {
sl, ok := m["!="].(string)
if !ok {
return "", nil, ErrWrongType
Expand All @@ -274,7 +274,7 @@ func (sr StringResolver) ToExpr(arg interface{}, label string) (string, []interf
return squirrel.NotEq{label: sl}.ToSql()
}

if _, ok := m["not in"]; ok {
if _, ok = m["not in"]; ok {
sl, ok := m["not in"].([]interface{})
if !ok {
return "", nil, ErrWrongType
Expand Down Expand Up @@ -305,7 +305,7 @@ func (fr BoolResolver) ToExpr(arg interface{}, label string) (string, []interfac
return "", nil, ErrWrongType
}

if _, ok := m["="]; ok {
if _, ok = m["="]; ok {
sl, ok := m["="].(bool)
if !ok {
return "", nil, ErrWrongType
Expand All @@ -314,7 +314,7 @@ func (fr BoolResolver) ToExpr(arg interface{}, label string) (string, []interfac
and = append(and, squirrel.Eq{label: sl})
}

if _, ok := m["!="]; ok {
if _, ok = m["!="]; ok {
sl, ok := m["!="].(bool)
if !ok {
return "", nil, ErrWrongType
Expand Down Expand Up @@ -345,7 +345,7 @@ func (ir TimestampResolver) ToExpr(arg interface{}, label string) (string, []int
return "", nil, ErrWrongType
}

if _, ok := m["="]; ok {
if _, ok = m["="]; ok {
sl, ok := m["="].(string)
if !ok {
return "", nil, ErrWrongType
Expand All @@ -354,7 +354,7 @@ func (ir TimestampResolver) ToExpr(arg interface{}, label string) (string, []int
and = append(and, squirrel.Eq{label: sl})
}

if _, ok := m["!="]; ok {
if _, ok = m["!="]; ok {
sl, ok := m["!="].(string)
if !ok {
return "", nil, ErrWrongType
Expand All @@ -363,7 +363,7 @@ func (ir TimestampResolver) ToExpr(arg interface{}, label string) (string, []int
and = append(and, squirrel.NotEq{label: sl})
}

if _, ok := m["in"]; ok {
if _, ok = m["in"]; ok {
sl, ok := m["in"].([]interface{})
if !ok {
return "", nil, ErrWrongType
Expand All @@ -381,7 +381,7 @@ func (ir TimestampResolver) ToExpr(arg interface{}, label string) (string, []int
and = append(and, squirrel.Eq{label: pq.StringArray(arr)})
}

if _, ok := m["gt"]; ok {
if _, ok = m["gt"]; ok {
sl, ok := m["gt"].(string)
if !ok {
return "", nil, ErrWrongType
Expand All @@ -390,7 +390,7 @@ func (ir TimestampResolver) ToExpr(arg interface{}, label string) (string, []int
and = append(and, squirrel.Gt{label: sl})
}

if _, ok := m["gte"]; ok {
if _, ok = m["gte"]; ok {
sl, ok := m["gte"].(string)
if !ok {
return "", nil, ErrWrongType
Expand All @@ -399,7 +399,7 @@ func (ir TimestampResolver) ToExpr(arg interface{}, label string) (string, []int
and = append(and, squirrel.GtOrEq{label: sl})
}

if _, ok := m["lt"]; ok {
if _, ok = m["lt"]; ok {
sl, ok := m["lt"].(string)
if !ok {
return "", nil, ErrWrongType
Expand Down

0 comments on commit e20fe1d

Please sign in to comment.