Add QueryCriteria arrayContaining.
Add QueryCriteria arrayContaining which maps to n1ql array_containing. Closes #1073. Original pull request: #1109. Co-authored-by: mikereiche <michael.reiche@couchbase.com>
This commit is contained in:
committed by
mikereiche
parent
4c428c5351
commit
fe8d3feb48
@@ -192,6 +192,13 @@ public class QueryCriteria implements QueryCriteriaDefinition {
|
||||
return this;
|
||||
}
|
||||
|
||||
public QueryCriteria arrayContaining(@Nullable Object o) {
|
||||
operator = "ARRAY_CONTAINING";
|
||||
value = new Object[] { o };
|
||||
format = "array_containing(%1$s, %3$s)";
|
||||
return this;
|
||||
}
|
||||
|
||||
public QueryCriteria notContaining(@Nullable Object o) {
|
||||
value = new QueryCriteria[] { wrap(containing(o)) };
|
||||
operator = "NOT";
|
||||
|
||||
@@ -123,14 +123,11 @@ class QueryCriteriaTests {
|
||||
assertEquals("`name` like (\"Cou\"||\"%\")", c.export());
|
||||
}
|
||||
|
||||
/* cannot do this properly yet because in arg to when() in
|
||||
* startingWith() cannot be a QueryCriteria
|
||||
@Test
|
||||
void testStartingWithExpr() {
|
||||
QueryCriteria c = where(i("name")).startingWith(where(i("name")).plus("xxx"));
|
||||
assertEquals("`name` like (((`name` || "xxx") || ""%""))", c.export());
|
||||
assertEquals("`name` like (((`name` || \"xxx\"))||\"%\")", c.export());
|
||||
}
|
||||
*/
|
||||
|
||||
@Test
|
||||
void testEndingWith() {
|
||||
@@ -162,6 +159,12 @@ class QueryCriteriaTests {
|
||||
assertEquals("not( (contains(`name`, \"Elvis\")) )", c.export());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testArrayContaining() {
|
||||
QueryCriteria c = where(i("name")).arrayContaining("Elvis");
|
||||
assertEquals("array_containing(`name`, \"Elvis\")", c.export());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testLike() {
|
||||
QueryCriteria c = where(i("name")).like("%ouch%");
|
||||
|
||||
Reference in New Issue
Block a user