Reputation: 660
As I am new to Quarkus, I am stuck at once place and it would be great, if anyone can help me out. I am creating a application with Quarkus reactive PgPool (basically of vertx), and I have to inset records in table which have columns more than 6
import io.smallrye.mutiny.Uni;
import io.vertx.mutiny.sqlclient.Tuple;
import io.vertx.mutiny.pgclient.PgPool;
public Uni<Long> addRequest(PgPool client) {
String sql = "Insert into request (column1, column2, column3, column4, column5, column6, column7, column8, column9"
+", column10, column11, column12, column13, column14, column15)"+
" values ($1, $2, $3, $4, $5, $6, $7, $8, $9"
+", $10, $11, $12, $13, $14, $15) RETURNING id";
**//Here I am adding 15 columns to Tuple but it's allowing**
Tuple t = Tuple.of(column1, column2, column3, column4, column5, column6, column7, column8, column9
, column10, column11, column12, column13, column14, column15);
return client.preparedQuery(sql).execute(t).onItem().transform(pgRowSet -> pgRowSet.iterator().next().getLong("id"));
}
Please let me know how to do it, correctly or if there is any better way to do it like directly passing POJO class instance or using NamedJdbcTemplate because some of my table contains above 50 columns and to maintain number not so good?
Upvotes: 5
Views: 1448
Reputation: 345
I'm using quarkus 2.0.2.Final:
<quarkus.platform.version>2.0.2.Final</quarkus.platform.version>
And seems only wrap()
method works for me:
The Tuple
source code shows that the wrap
method accept List
type:
Upvotes: 0
Reputation: 11890
You could store all columns into a List and pass it as argument, using this Tuple.tuple(List)
method.
List<Column> columns = new ArrayList<>();
columns.add(column1);
//...
Tuple t = Tuple.tuple(columns);
Do not confuse with Tuple.of(), the method is Tuple.tuple()!
Upvotes: 3