use of org.jdbi.v3.sqlobject.customizer.Bind in project jdbi by jdbi.
the class TestCollectorFactory method testExists.
@Test
public void testExists() throws Exception {
Handle h = dbRule.getSharedHandle();
h.execute("insert into something (id, name) values (1, 'Coda')");
Optional<String> rs = h.createQuery("select name from something where id = :id").bind("id", 1).mapTo(String.class).collect(GuavaCollectors.toOptional());
assertThat(rs).contains("Coda");
}
use of org.jdbi.v3.sqlobject.customizer.Bind in project jdbi by jdbi.
the class TestCollectorFactory method testDoesNotExist.
@Test
public void testDoesNotExist() throws Exception {
Handle h = dbRule.getSharedHandle();
h.execute("insert into something (id, name) values (1, 'Coda')");
Optional<String> rs = h.createQuery("select name from something where id = :id").bind("id", 2).mapTo(String.class).collect(GuavaCollectors.toOptional());
assertThat(rs).isAbsent();
}
use of org.jdbi.v3.sqlobject.customizer.Bind in project jdbi by jdbi.
the class TestDocumentation method testSomeQueriesWorkCorrectly.
@Test
public void testSomeQueriesWorkCorrectly() throws Exception {
try (Handle h = dbRule.openHandle()) {
h.prepareBatch("insert into something (id, name) values (:id, :name)").bind("id", 1).bind("name", "Brian").add().bind("id", 2).bind("name", "Robert").add().bind("id", 3).bind("name", "Patrick").add().bind("id", 4).bind("name", "Maniax").add().execute();
SomeQueries sq = h.attach(SomeQueries.class);
assertThat(sq.findName(2)).isEqualTo("Robert");
assertThat(sq.findNamesBetween(1, 4)).containsExactly("Robert", "Patrick");
Iterator<String> names = sq.findAllNames();
assertThat(names).containsExactly("Brian", "Robert", "Patrick", "Maniax");
}
}
use of org.jdbi.v3.sqlobject.customizer.Bind in project jdbi by jdbi.
the class TestVavrValueArgumentFactoryWithDB method testGetEitherRight_shouldReturnCorrectRow.
@Test
public void testGetEitherRight_shouldReturnCorrectRow() {
Something result = dbRule.getSharedHandle().createQuery(SELECT_BY_NAME).bind("name", Either.right("brian")).mapToBean(Something.class).findOnly();
assertThat(result).isEqualTo(BRIAN_SOMETHING);
}
use of org.jdbi.v3.sqlobject.customizer.Bind in project jdbi by jdbi.
the class TestVavrValueArgumentFactoryWithDB method testGetLazy_shouldReturnCorrectRow.
@Test
public void testGetLazy_shouldReturnCorrectRow() {
Something result = dbRule.getSharedHandle().createQuery(SELECT_BY_NAME).bind("name", Lazy.of(() -> "brian")).mapToBean(Something.class).findOnly();
assertThat(result).isEqualTo(BRIAN_SOMETHING);
}
Aggregations