Search in sources :

Example 11 with ResultIterable

use of org.jdbi.v3.core.result.ResultIterable in project jdbi by jdbi.

the class TestDocumentation method testMappingExampleChainedIterator3.

@Test
public void testMappingExampleChainedIterator3() {
    try (Handle h = h2Extension.openHandle()) {
        h.execute("insert into something (id, name) values (1, 'Brian')");
        h.execute("insert into something (id, name) values (2, 'Keith')");
        ResultIterable<String> names = h.createQuery("select name from something order by id").mapTo(String.class);
        assertThat(names.iterator()).toIterable().containsExactly("Brian", "Keith");
    }
}
Also used : Handle(org.jdbi.v3.core.Handle) Test(org.junit.jupiter.api.Test)

Example 12 with ResultIterable

use of org.jdbi.v3.core.result.ResultIterable in project jdbi by jdbi.

the class TestQueries method testMapper.

@Test
public void testMapper() {
    Handle h = h2Extension.openHandle();
    h.execute("insert into something (id, name) values (1, 'eric')");
    h.execute("insert into something (id, name) values (2, 'brian')");
    ResultIterable<String> query = h.createQuery("select name from something order by id").map((r, ctx) -> r.getString(1));
    List<String> r = query.list();
    assertThat(r).startsWith("eric");
}
Also used : Handle(org.jdbi.v3.core.Handle) Test(org.junit.jupiter.api.Test)

Aggregations

Handle (org.jdbi.v3.core.Handle)10 Test (org.junit.jupiter.api.Test)9 Something (org.jdbi.v3.core.Something)5 Map (java.util.Map)2 Namespace (net.sourceforge.argparse4j.inf.Namespace)2 ResultIterator (org.jdbi.v3.core.result.ResultIterator)2 StatementContext (org.jdbi.v3.core.statement.StatementContext)2 Type (java.lang.reflect.Type)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 NoSuchElementException (java.util.NoSuchElementException)1 GenericTypes.getErasedType (org.jdbi.v3.core.generic.GenericTypes.getErasedType)1 QualifiedType (org.jdbi.v3.core.qualifier.QualifiedType)1 Qualifiers (org.jdbi.v3.core.qualifier.Qualifiers)1 ResultIterable (org.jdbi.v3.core.result.ResultIterable)1 PreparedBatch (org.jdbi.v3.core.statement.PreparedBatch)1 SingleValue (org.jdbi.v3.sqlobject.SingleValue)1 UseRowMapper (org.jdbi.v3.sqlobject.statement.UseRowMapper)1 UseRowReducer (org.jdbi.v3.sqlobject.statement.UseRowReducer)1