I try to perform a batch insert using r2dbc.
I have see that with DatabaseClient from spring boot, it's not yet possible.
I have try to do that using R2DBC SPI Statement
and the and
method, like that:
Mono.from(this.factory.create())
.map(connection -> connection.createStatement(insertSQL))
.map(statement -> {
lines.forEach(line -> {
statement
.add()
.bind(0, line.getId())
;
});
return statement;
})
.flatMap(statement -> Mono.from(statement.execute()));
I have see on the log that two insert request are done.
2019-12-18 16:27:36.092 DEBUG [] 4133 --- [tor-tcp-epoll-1] io.r2dbc.postgresql.QUERY : Executing query: insert into table(id) values ($1)
2019-12-18 16:27:36.116 DEBUG [] 4133 --- [tor-tcp-epoll-1] i.r.p.client.ReactorNettyClient : Request: Bind{}
2019-12-18 16:27:36.126 DEBUG [] 4133 --- [tor-tcp-epoll-1] io.r2dbc.postgresql.QUERY : Executing query: insert into table(id) values ($1)
2019-12-18 16:27:36.130 DEBUG [] 4133 --- [tor-tcp-epoll-1] i.r.p.client.ReactorNettyClient : Request: Bind{}
Is add
perform a batch update or just run two requests?
Thanks.