Skip to content

Custom comparators for R2dbcRepository in Spring Data #263

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
IvanKonevJr opened this issue Dec 27, 2019 · 12 comments
Closed

Custom comparators for R2dbcRepository in Spring Data #263

IvanKonevJr opened this issue Dec 27, 2019 · 12 comments
Labels
status: duplicate A duplicate of another issue

Comments

@IvanKonevJr
Copy link

IvanKonevJr commented Dec 27, 2019

Feature Request
Needed custom comparators for supporting special iLike, Jsonb, Arrays, Ranges and Full Text Search of PostgreSQL inline querying in Criteria builder (do not custom, only inline)

Describe the solution you'd like
As solution may be create comparators as bean and dynamic extending collection:

enum Comparator { EQ, NEQ, LT, LTE, GT, GTE, IS_NULL, IS_NOT_NULL, LIKE, NOT_IN, IN, }

@carhartl
Copy link

carhartl commented Jan 29, 2020

I was also facing the issue that I wanted to use a jsonb operator in a condition, such as data ? foo, which doesn't seem to be possible usingCriteria at the moment. I had to resort to go lower level...

@carhartl
Copy link

carhartl commented Jan 29, 2020

E.g. I would see some value in enhancing the Criteria builder one way or the other... I noticed there's Conditions.just(), so could there be something like a Criteria.just()?

@mp911de mp911de added the status: duplicate A duplicate of another issue label Jan 29, 2020
@mp911de
Copy link
Member

mp911de commented Jan 29, 2020

This ticket isn't an exact duplicate of #289 but the referenced ticket contains a few details on why this enhancement isn't really going to work. We recommend using the execute() API for more flexibility.

@carhartl
Copy link

Hi @mp911de, understood, I had to resort to the execute() api :)

Though if you don't know upfront which conditions there are going to be (think: taking filters from http request params) I found it difficult because having to bind() values individually. For this Criteria was really convenient... could there be an alternative bind() taking a map, or an array? Or am I overlooking something?

@mp911de
Copy link
Member

mp911de commented Jan 29, 2020

DatabaseClient's API is comparable to what JdbcTemplate provides though it has a tiny POJO-mapping-based API. I suggest using something like jOOQ to generate dynamic SQL statements. We do not plan to evolve the Criteria API too much. There are all sorts of ways to express the WHERE clause or the functionality around Postgres' Fulltext-search or any JSON query predicates so that we would end up with a massive pile of functionality and a very broad API to cater for the individual things one might want to achieve with Criteria.

@IvanKonevJr
Copy link
Author

Criteria API it is a high level and provides a certain level of security, if we move to a lower level as jOOQ, then we will have to write a bunch of code to fully repeat the Criteria API functionality with only possibility of custom comparators )))

@mp911de
Copy link
Member

mp911de commented Jan 29, 2020

In #265, we provide two rather simple examples. Without introducing another abstraction level we cannot infer type and parameter binding information that would be required to render proper criteria. Spring Data's support for relational databases is primary a library to implement the repository pattern and to aid common use-cases. It's by no means an exhaustive library that supports all types of features that are provided by the underlying databases.

@IvanKonevJr
Copy link
Author

@mp911de
criterial.and("score").has("<@ int4range(1,7)")

has function is planed?

@IvanKonevJr
Copy link
Author

Hi @carhartl, you wrote:

Hi @mp911de, understood, I had to resort to the execute() api :)

Can you show of use execute() api for jsonb?

@IvanKonevJr
Copy link
Author

In #265, we provide two rather simple examples. Without introducing another abstraction level we cannot infer type and parameter binding information that would be required to render proper criteria. Spring Data's support for relational databases is primary a library to implement the repository pattern and to aid common use-cases. It's by no means an exhaustive library that supports all types of features that are provided by the underlying databases.

yes, but Hibernate support custom operators

@carhartl
Copy link

@LaoTsing

Can you show of use execute() api for jsonb?

To give you an idea:

databaseClient.execute("SELECT data FROM things WHERE data ? $1").bind(0, "foo");

@IvanKonevJr
Copy link
Author

Thank you, but i think to as clean is supporting custom operators in Criteria API, because each database have a lot inline operators

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: duplicate A duplicate of another issue
Projects
None yet
Development

No branches or pull requests

3 participants