use of io.requery.query.Tuple in project requery by requery.
the class FunctionalTest method testQueryUnion.
@Test
public void testQueryUnion() {
Person person = randomPerson();
person.setName("Carol");
data.insert(person);
Group group = new Group();
group.setName("Hello!");
data.insert(group);
List<Tuple> result = data.select(Person.NAME.as("name")).union().select(Group.NAME.as("name")).orderBy(Group.NAME.as("name")).get().toList();
assertTrue(result.size() == 2);
assertTrue(result.get(0).get(0).equals("Carol"));
assertTrue(result.get(1).get(0).equals("Hello!"));
}
use of io.requery.query.Tuple in project requery by requery.
the class FunctionalTest method testQueryOrderByFunction.
@Test
public void testQueryOrderByFunction() {
Person person = randomPerson();
person.setName("BOBB");
data.insert(person);
person = randomPerson();
person.setName("BobA");
data.insert(person);
person = randomPerson();
person.setName("bobC");
data.insert(person);
List<Tuple> list = data.select(Person.NAME).orderBy(Upper.upper(Person.NAME).desc()).get().toList();
assertTrue(list.get(0).get(0).equals("bobC"));
assertTrue(list.get(1).get(0).equals("BOBB"));
assertTrue(list.get(2).get(0).equals("BobA"));
}
use of io.requery.query.Tuple in project requery by requery.
the class FunctionalTest method testQueryOrderBy.
@Test
public void testQueryOrderBy() {
for (int i = 0; i < 5; i++) {
Person person = randomPerson();
person.setAge(i);
data.insert(person);
}
try (Result<Tuple> query = data.select(Person.AGE).orderBy(Person.AGE.desc()).get()) {
Integer i = query.first().get(0);
assertTrue(i.equals(4));
}
}
use of io.requery.query.Tuple in project requery by requery.
the class FunctionalTest method testQuerySelectWhereIn.
@Test
public void testQuerySelectWhereIn() {
final String name = "Hello!";
Person person = randomPerson();
person.setName(name);
data.insert(person);
Group group = new Group();
group.setName("Hello!");
data.insert(group);
person.getGroups().add(group);
data.update(person);
Return<? extends Result<Tuple>> groupNames = data.select(Group.NAME).where(Group.NAME.equal(name));
Person p = data.select(Person.class).where(Person.NAME.in(groupNames)).get().first();
assertEquals(p.getName(), name);
p = data.select(Person.class).where(Person.NAME.notIn(groupNames)).get().firstOrNull();
assertNull(p);
p = data.select(Person.class).where(Person.NAME.in(Arrays.asList("Hello!", "Other"))).get().first();
assertEquals(p.getName(), name);
p = data.select(Person.class).where(Person.NAME.in(Collections.singleton("Hello!"))).get().first();
assertEquals(p.getName(), name);
assertTrue(data.select(Person.class).where(Person.NAME.notIn(Collections.singleton("Hello!"))).get().toList().isEmpty());
}
Aggregations