Java Code Examples for io.vertx.mutiny.sqlclient.Tuple

The following examples show how to use io.vertx.mutiny.sqlclient.Tuple. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: quarkus   Source File: HibernateReactiveDB2TestEndpoint.java    License: Apache License 2.0 7 votes vote down vote up
private Uni<String> selectNameFromId(Integer id) {
    return db2Pool.preparedQuery("SELECT name FROM Pig WHERE id = ?").execute(Tuple.of(id)).map(rowSet -> {
        if (rowSet.size() == 1) {
            return rowSet.iterator().next().getString(0);
        } else if (rowSet.size() > 1) {
            throw new AssertionError("More than one result returned: " + rowSet.size());
        } else {
            return null; // Size 0
        }
    });
}
 
Example 2
Source Project: quarkus   Source File: HibernateReactiveTestEndpoint.java    License: Apache License 2.0 5 votes vote down vote up
private Uni<String> selectNameFromId(Integer id) {
    return pgPool.preparedQuery("SELECT name FROM Pig WHERE id = $1").execute(Tuple.of(id)).map(rowSet -> {
        if (rowSet.size() == 1) {
            return rowSet.iterator().next().getString(0);
        } else if (rowSet.size() > 1) {
            throw new AssertionError("More than one result returned: " + rowSet.size());
        } else {
            return null; // Size 0
        }
    });
}
 
Example 3
private Uni<String> selectNameFromId(Integer id) {
    return mysqlPool.preparedQuery("SELECT name FROM Pig WHERE id = ?").execute(Tuple.of(id)).map(rowSet -> {
        if (rowSet.size() == 1) {
            return rowSet.iterator().next().getString(0);
        } else if (rowSet.size() > 1) {
            throw new AssertionError("More than one result returned: " + rowSet.size());
        } else {
            return null; // Size 0
        }
    });
}
 
Example 4
public Uni<World> find(int id) {
    return clients.getClient().preparedQuery("SELECT id, randomNumber FROM World WHERE id = $1")
            .execute(Tuple.of(id))
            .map(rowset -> {
                Row row = rowset.iterator().next();
                return new World(row.getInteger(0), row.getInteger(1));
            });
}
 
Example 5
public Uni<Void> update(World[] worlds) {
    Arrays.sort(worlds);
    List<Tuple> args = new ArrayList<>(worlds.length);
    for (World world : worlds) {
        args.add(Tuple.of(world.getId(), world.getRandomNumber()));
    }
    return clients.getPool().preparedQuery("UPDATE World SET randomNumber = $2 WHERE id = $1")
            .executeBatch(args)
            .map(v -> null);
}
 
Example 6
Source Project: quarkus-quickstarts   Source File: Fruit.java    License: Apache License 2.0 4 votes vote down vote up
public static Uni<Fruit> findById(PgPool client, Long id) {
    return client.preparedQuery("SELECT id, name FROM fruits WHERE id = $1").execute(Tuple.of(id))
            .onItem().apply(RowSet::iterator)
            .onItem().apply(iterator -> iterator.hasNext() ? from(iterator.next()) : null);
}
 
Example 7
Source Project: quarkus-quickstarts   Source File: Fruit.java    License: Apache License 2.0 4 votes vote down vote up
public Uni<Long> save(PgPool client) {
    return client.preparedQuery("INSERT INTO fruits (name) VALUES ($1) RETURNING (id)").execute(Tuple.of(name))
            .onItem().apply(pgRowSet -> pgRowSet.iterator().next().getLong("id"));
}
 
Example 8
Source Project: quarkus-quickstarts   Source File: Fruit.java    License: Apache License 2.0 4 votes vote down vote up
public Uni<Boolean> update(PgPool client) {
    return client.preparedQuery("UPDATE fruits SET name = $1 WHERE id = $2").execute(Tuple.of(name, id))
            .onItem().apply(pgRowSet -> pgRowSet.rowCount() == 1);
}
 
Example 9
Source Project: quarkus-quickstarts   Source File: Fruit.java    License: Apache License 2.0 4 votes vote down vote up
public static Uni<Boolean> delete(PgPool client, Long id) {
    return client.preparedQuery("DELETE FROM fruits WHERE id = $1").execute(Tuple.of(id))
            .onItem().apply(pgRowSet -> pgRowSet.rowCount() == 1);
}
 
Example 10
Source Project: quarkus-quickstarts   Source File: Fruit.java    License: Apache License 2.0 4 votes vote down vote up
public static Uni<Fruit> findById(PgPool client, Long id) {
    return client.preparedQuery("SELECT id, name FROM fruits WHERE id = $1").execute(Tuple.of(id))
            .onItem().apply(RowSet::iterator)
            .onItem().apply(iterator -> iterator.hasNext() ? from(iterator.next()) : null);
}
 
Example 11
Source Project: quarkus-quickstarts   Source File: Fruit.java    License: Apache License 2.0 4 votes vote down vote up
public Uni<Long> save(PgPool client) {
    return client.preparedQuery("INSERT INTO fruits (name) VALUES ($1) RETURNING (id)").execute(Tuple.of(name))
            .onItem().apply(pgRowSet -> pgRowSet.iterator().next().getLong("id"));
}
 
Example 12
Source Project: quarkus-quickstarts   Source File: Fruit.java    License: Apache License 2.0 4 votes vote down vote up
public Uni<Boolean> update(PgPool client) {
    return client.preparedQuery("UPDATE fruits SET name = $1 WHERE id = $2").execute(Tuple.of(name, id))
            .onItem().apply(pgRowSet -> pgRowSet.rowCount() == 1);
}
 
Example 13
Source Project: quarkus-quickstarts   Source File: Fruit.java    License: Apache License 2.0 4 votes vote down vote up
public static Uni<Boolean> delete(PgPool client, Long id) {
    return client.preparedQuery("DELETE FROM fruits WHERE id = $1").execute(Tuple.of(id))
            .onItem().apply(pgRowSet -> pgRowSet.rowCount() == 1);
}