Skip to content

Commit

Permalink
Merge pull request #634 from upper/feature/add-any-of
Browse files Browse the repository at this point in the history
Add AnyOf and NotAnyOf
  • Loading branch information
xiam authored Jul 12, 2021
2 parents 2158231 + 8c188b4 commit 4a5e6d2
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
4 changes: 0 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,5 @@ jobs:
echo "DB_HOST=127.0.0.1" >> $GITHUB_ENV
echo "UPPER_DB_LOG=ERROR" >> $GITHUB_ENV
- name: Get requisites
run: |
go get -v modernc.org/ql/ql
- name: Execute main task
run: make ${{ matrix.target }}
5 changes: 5 additions & 0 deletions adapter/mysql/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,11 @@ func TestTemplateSelect(t *testing.T) {
"SELECT * FROM `artist` WHERE (`id` IN ($1, $2) AND `name` LIKE $3)",
b.SelectFrom("artist").Where(db.Cond{"name LIKE": "%foo", "id": db.In(1, 2)}).String(),
)

assert.Equal(
"SELECT * FROM `artist` WHERE (`id` IN ($1, $2) AND `name` LIKE $3)",
b.SelectFrom("artist").Where(db.Cond{"name LIKE": "%foo", "id": db.AnyOf([]int{1, 2})}).String(),
)
}
}

Expand Down
10 changes: 10 additions & 0 deletions comparison.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,21 @@ func In(value ...interface{}) *Comparison {
return &Comparison{adapter.NewComparisonOperator(adapter.ComparisonOperatorIn, toInterfaceArray(value))}
}

// AnyOf is a comparison that means: is any of the values of the slice.
func AnyOf(value interface{}) *Comparison {
return &Comparison{adapter.NewComparisonOperator(adapter.ComparisonOperatorIn, toInterfaceArray(value))}
}

// NotIn is a comparison that means: is none of the values.
func NotIn(value ...interface{}) *Comparison {
return &Comparison{adapter.NewComparisonOperator(adapter.ComparisonOperatorNotIn, toInterfaceArray(value))}
}

// NotAnyOf is a comparison that means: is none of the values of the slice.
func NotAnyOf(value interface{}) *Comparison {
return &Comparison{adapter.NewComparisonOperator(adapter.ComparisonOperatorNotIn, toInterfaceArray(value))}
}

// After is a comparison that means: is after the (time.Time) value.
func After(value time.Time) *Comparison {
return &Comparison{adapter.NewComparisonOperator(adapter.ComparisonOperatorGreaterThan, value)}
Expand Down

0 comments on commit 4a5e6d2

Please sign in to comment.