Skip to content

Commit ecf2b18

Browse files
committed
feat: add count method to QueryAQLConverter
Implemented a count method that constructs an AQL query to return the length of results based on a given SelectQuery. Signed-off-by: Maximillian Arruda <[email protected]>
1 parent e6b8fc0 commit ecf2b18

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

jnosql-arangodb/src/main/java/org/eclipse/jnosql/databases/arangodb/communication/QueryAQLConverter.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,23 @@ public static AQLQueryResult select(SelectQuery query) throws NullPointerExcepti
7777

7878
}
7979

80+
public static AQLQueryResult count(SelectQuery query) throws NullPointerException {
81+
82+
AQLQueryResult q = convert(query.name(),
83+
query.condition().orElse(null),
84+
Collections.emptyList(),
85+
0L,
86+
0L,
87+
RETURN, false);
88+
89+
StringBuilder aql = new StringBuilder();
90+
91+
aql.append("RETURN LENGTH(")
92+
.append(q.query())
93+
.append(")");
94+
return new AQLQueryResult(aql.toString(), q.values());
95+
}
96+
8097

8198
private static AQLQueryResult convert(String documentCollection,
8299
CriteriaCondition documentCondition,

jnosql-arangodb/src/test/java/org/eclipse/jnosql/databases/arangodb/communication/QueryAQLConverterTest.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,4 +155,18 @@ public void shouldNegate() {
155155

156156
}
157157

158+
@Test
159+
public void shouldRunEqualsCountQuery() {
160+
SelectQuery query = select().from("collection")
161+
.where("name").eq("value").build();
162+
163+
AQLQueryResult convert = QueryAQLConverter.count(query);
164+
String aql = convert.query();
165+
Map<String, Object> values = convert.values();
166+
assertEquals("value", values.get("name"));
167+
assertEquals("RETURN LENGTH(FOR c IN collection FILTER c.name == @name RETURN c)", aql);
168+
169+
}
170+
171+
158172
}

0 commit comments

Comments
 (0)