As I am new to quarkus, I have been stuck at place, here I am fetching all the ids from database but I am not able to return it as Uni<int[]>, please help me out.
public Uni<int[]> getRun(String owner, Date dateIN) {
try{
sql="select r.id from tabel r where r.userName=$1 AND (r.endDate IS NULL OR r.endDate >=$2)";
return client.preparedQuery(sql).execute(Tuple.of(owner,dateIN)).onItem().transform(pgRowSet -> pgRowSet.iterator())
.onItem().transform(ro -> ro.hasNext() ? Integer.parseInt(ro.next().toString()) : 0);
}
catch(Exception e){
return null;
}
}
Here I am not able to return it as Uni<int[]>, query other things are working properly.
Try this:
public Uni<int[]> getRun(String owner, Date dateIN) {
String sql = "select r.id from tabel r where r.userName=$1 AND (r.endDate IS NULL OR r.endDate >=$2)";
return client.preparedQuery(sql).execute(Tuple.of(owner, dateIN)).onItem().transform(rows -> {
return StreamSupport.stream(rows.spliterator(), false).mapToInt(row -> row.getInteger(0)).toArray();
});
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.