We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
package tech.amikos.chromadb; import com.google.gson.JsonArray; import com.google.gson.JsonObject; import java.util.List; public class WhereBuilder { private final JsonObject filter = new JsonObject(); private WhereBuilder() { } public static WhereBuilder create() { return new WhereBuilder(); } public WhereBuilder eq(String field, Object value) { return operation("$eq", field, value); } public WhereBuilder gt(String field, Object value) { return operation("$gt", field, value); } public WhereBuilder gte(String field, Object value) { return operation("$gte", field, value); } public WhereBuilder lt(String field, Object value) { return operation("$lt", field, value); } public WhereBuilder lte(String field, Object value) { return operation("$lte", field, value); } public WhereBuilder ne(String field, Object value) { return operation("$ne", field, value); } public WhereBuilder in(String field, List<Object> value) { return operation("$in", field, value); } public WhereBuilder nin(String field, List<Object> value) { return operation("$nin", field, value); } public WhereBuilder and(WhereBuilder... builders) { JsonArray jsonArray = new JsonArray(); for (WhereBuilder builder : builders) { jsonArray.add(builder.filter); } filter.add("$and", jsonArray); return this; } public WhereBuilder or(WhereBuilder... builders) { JsonArray jsonArray = new JsonArray(); for (WhereBuilder builder : builders) { jsonArray.add(builder.filter); } filter.add("$or", jsonArray); return this; } private WhereBuilder operation(String operation, String field, Object value) { JsonObject innerFilter = new JsonObject(); if (value instanceof List<?>) { JsonArray jsonArray = new JsonArray(); for (Object o : (List<?>) value) { if (o instanceof String) jsonArray.add(o.toString()); else if (o instanceof Integer) jsonArray.add((Integer) o); else if (o instanceof Float) jsonArray.add((Float) o); else if (o instanceof Boolean) jsonArray.add((Boolean) o); else { throw new IllegalArgumentException("Unsupported type: " + o.getClass().getName()); } } innerFilter.add(operation, jsonArray); } else { innerFilter.addProperty(operation, value.toString()); } filter.add(field, innerFilter); // Gson handles various value types return this; } public JsonObject build() { return filter; } }
package tech.amikos.chromadb; import com.google.gson.JsonArray; import com.google.gson.JsonObject; import java.util.List; public class WhereDocumentBuilder { private final JsonObject filter = new JsonObject(); private WhereDocumentBuilder() { } public static WhereDocumentBuilder create() { return new WhereDocumentBuilder(); } public WhereDocumentBuilder contains(String value) { return operation("$contains", value); } public WhereDocumentBuilder notContains(String value) { return operation("$not_contains", value); } public WhereDocumentBuilder and(WhereDocumentBuilder... builders) { JsonArray jsonArray = new JsonArray(); for (WhereDocumentBuilder builder : builders) { jsonArray.add(builder.filter); } filter.add("$and", jsonArray); return this; } public WhereDocumentBuilder or(WhereDocumentBuilder... builders) { JsonArray jsonArray = new JsonArray(); for (WhereDocumentBuilder builder : builders) { jsonArray.add(builder.filter); } filter.add("$or", jsonArray); return this; } private WhereDocumentBuilder operation(String operation, Object value) { filter.addProperty(operation, value.toString()); // Gson handles various value types return this; } public JsonObject build() { return filter; } }
The text was updated successfully, but these errors were encountered:
tazarov
No branches or pull requests
Where
WhereDocument
The text was updated successfully, but these errors were encountered: