Skip to content

Commit 4a5e6d2

Browse files
authored
Merge pull request #634 from upper/feature/add-any-of
Add AnyOf and NotAnyOf
2 parents 2158231 + 8c188b4 commit 4a5e6d2

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

.github/workflows/test.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,5 @@ jobs:
2929
echo "DB_HOST=127.0.0.1" >> $GITHUB_ENV
3030
echo "UPPER_DB_LOG=ERROR" >> $GITHUB_ENV
3131
32-
- name: Get requisites
33-
run: |
34-
go get -v modernc.org/ql/ql
35-
3632
- name: Execute main task
3733
run: make ${{ matrix.target }}

adapter/mysql/template_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,11 @@ func TestTemplateSelect(t *testing.T) {
161161
"SELECT * FROM `artist` WHERE (`id` IN ($1, $2) AND `name` LIKE $3)",
162162
b.SelectFrom("artist").Where(db.Cond{"name LIKE": "%foo", "id": db.In(1, 2)}).String(),
163163
)
164+
165+
assert.Equal(
166+
"SELECT * FROM `artist` WHERE (`id` IN ($1, $2) AND `name` LIKE $3)",
167+
b.SelectFrom("artist").Where(db.Cond{"name LIKE": "%foo", "id": db.AnyOf([]int{1, 2})}).String(),
168+
)
164169
}
165170
}
166171

comparison.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,21 @@ func In(value ...interface{}) *Comparison {
6868
return &Comparison{adapter.NewComparisonOperator(adapter.ComparisonOperatorIn, toInterfaceArray(value))}
6969
}
7070

71+
// AnyOf is a comparison that means: is any of the values of the slice.
72+
func AnyOf(value interface{}) *Comparison {
73+
return &Comparison{adapter.NewComparisonOperator(adapter.ComparisonOperatorIn, toInterfaceArray(value))}
74+
}
75+
7176
// NotIn is a comparison that means: is none of the values.
7277
func NotIn(value ...interface{}) *Comparison {
7378
return &Comparison{adapter.NewComparisonOperator(adapter.ComparisonOperatorNotIn, toInterfaceArray(value))}
7479
}
7580

81+
// NotAnyOf is a comparison that means: is none of the values of the slice.
82+
func NotAnyOf(value interface{}) *Comparison {
83+
return &Comparison{adapter.NewComparisonOperator(adapter.ComparisonOperatorNotIn, toInterfaceArray(value))}
84+
}
85+
7686
// After is a comparison that means: is after the (time.Time) value.
7787
func After(value time.Time) *Comparison {
7888
return &Comparison{adapter.NewComparisonOperator(adapter.ComparisonOperatorGreaterThan, value)}

0 commit comments

Comments
 (0)