Skip to content

Add QueryCriteria arrayContaining. #1110

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,13 @@ public QueryCriteria containing(@Nullable Object o) {
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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,11 @@ void testStartingWith() {
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() {
Expand Down Expand Up @@ -162,6 +159,12 @@ void testNotContaining() {
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%");
Expand Down