use of jakarta.nosql.document.DocumentQuery in project jnosql-diana-driver by eclipse.
the class QueryAQLConverterTest method shouldRunEqualsQueryLimit.
@Test
public void shouldRunEqualsQueryLimit() {
DocumentQuery query = select().from("collection").where("name").eq("value").limit(5).build();
AQLQueryResult convert = QueryAQLConverter.select(query);
String aql = convert.getQuery();
Map<String, Object> values = convert.getValues();
assertEquals("value", values.get("name"));
assertEquals("FOR c IN collection FILTER c.name == @name LIMIT 5 RETURN c", aql);
}
use of jakarta.nosql.document.DocumentQuery in project jnosql-diana-driver by eclipse.
the class CouchbaseDocumentCollectionManagerTest method shouldSaveSubDocument.
@Test
public void shouldSaveSubDocument() throws InterruptedException {
DocumentEntity entity = getEntity();
entity.add(Document.of("phones", Document.of("mobile", "1231231")));
DocumentEntity entitySaved = entityManager.insert(entity);
Thread.sleep(5_00L);
Document id = entitySaved.find("_id").get();
DocumentQuery query = select().from(COLLECTION_NAME).where(id.getName()).eq(id.get()).build();
DocumentEntity entityFound = entityManager.select(query).collect(Collectors.toList()).get(0);
Document subDocument = entityFound.find("phones").get();
List<Document> documents = subDocument.get(new TypeReference<List<Document>>() {
});
assertThat(documents, contains(Document.of("mobile", "1231231")));
}
use of jakarta.nosql.document.DocumentQuery in project jnosql-diana-driver by eclipse.
the class CouchbaseDocumentCollectionManagerTest method shouldRetrieveListSubdocumentList.
@Test
public void shouldRetrieveListSubdocumentList() {
DocumentEntity entity = entityManager.insert(createSubdocumentList());
Document key = entity.find("_id").get();
DocumentQuery query = select().from("AppointmentBook").where(key.getName()).eq(key.get()).build();
DocumentEntity documentEntity = entityManager.singleResult(query).get();
assertNotNull(documentEntity);
List<List<Document>> contacts = (List<List<Document>>) documentEntity.find("contacts").get().get();
assertEquals(3, contacts.size());
assertTrue(contacts.stream().allMatch(d -> d.size() == 3));
}
use of jakarta.nosql.document.DocumentQuery in project jnosql-diana-driver by eclipse.
the class CouchbaseDocumentCollectionManagerTest method shouldRemoveEntityByName.
@Test
public void shouldRemoveEntityByName() {
DocumentEntity documentEntity = entityManager.insert(getEntity());
Document name = documentEntity.find("name").get();
DocumentQuery query = select().from(COLLECTION_NAME).where(name.getName()).eq(name.get()).build();
DocumentDeleteQuery deleteQuery = delete().from(COLLECTION_NAME).where(name.getName()).eq(name.get()).build();
entityManager.delete(deleteQuery);
assertTrue(entityManager.select(query).collect(Collectors.toList()).isEmpty());
}
use of jakarta.nosql.document.DocumentQuery in project jnosql-diana-driver by eclipse.
the class DocumentQueryTest method shouldShouldDefineLimit.
@Test
public void shouldShouldDefineLimit() {
DocumentEntity entity = DocumentEntity.of("person", asList(Document.of("_id", "id"), Document.of("name", "name")));
Document name = entity.find("name").get();
DocumentQuery query = select().from(COLLECTION_NAME).where(name.getName()).eq(name.get()).limit(2L).build();
List<DocumentEntity> entities = entityManager.select(query).collect(Collectors.toList());
assertEquals(2, entities.size());
}
Aggregations