"Is there any short hand to no .of rows in a database against a where condition" if we have a criteria definition present against which want number of rows present in database. is is any function in r2dbc that give that?
"Is there any short hand to no .of rows in a database against a where condition" if we have a criteria definition present against which want number of rows present in database. is is any function in r2dbc that give that?
You can have something like this:
@Repository
public class MyCustomRepositoryImpl {
private final R2dbcEntityTemplate r2dbcEntityTemplate;
@Autowired
public MyCustomRepositoryImpl(DatabaseClient databaseClient) {
this.r2dbcEntityTemplate = new R2dbcEntityTemplate(databaseClient);
}
public Mono<Long> getCountOfAllRows() {
return r2dbcEntityTemplate.count(query(Criteria.empty()),MyEntity.class);
}
public Mono<Long> getCountOfRowsForACondition(String myVal) {
return r2dbcEntityTemplate.select(query(Criteria.where("mycolumn").is(myVal)),MyEntity.class);
}
}
Note here query is the static method of org.springframework.data.relational.core.query.Query