Skip to content
New issue

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

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

Already on GitHub? # to your account

Add Type-safe Kotlin query extension #1491

Open
kihwankim opened this issue Apr 9, 2023 · 5 comments
Open

Add Type-safe Kotlin query extension #1491

kihwankim opened this issue Apr 9, 2023 · 5 comments
Labels
in: kotlin Kotlin support type: enhancement A general enhancement

Comments

@kihwankim
Copy link

kihwankim commented Apr 9, 2023

I am useing R2dbcEntityTemplate. and I try to create dynamic where sql using kotlin but there are not util function
and I would like to get column name using kotlin KProperty.

can I make this one and contribute this repo?

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Apr 9, 2023
@mp911de
Copy link
Member

mp911de commented Apr 11, 2023

Let's take a step back here before proposing code changes. Kotlin provides a lot of exciting opportunities to create a DSL for querying. Please also look at MongoDB first, where we have a similar approach.

We should clarify the goal first before proceeding here.

@mp911de mp911de added status: waiting-for-feedback We need additional information before we can continue in: kotlin Kotlin support labels Apr 11, 2023
@kihwankim
Copy link
Author

kihwankim commented Apr 12, 2023

Hello @mp911de
Sorry I didn't notice that one I can not find r2dbc mongodb project can you let me know which repo is that?
then I will research about that one show you what I will do!

And I'll write down what I want to do as a PR

  1. I would like to create dynamic sql where stmt function
  2. I want to use reflection to get column names when I use R2dbcEntityTemplate. Because when I use R2dbcEntityTemplate I always use String type for putting the column name. so I always got a runtime exception when a column was changed. so I want to identify errors at compile time.
    example
// code
R2dbcEntityTemplate<Person, String>.column(Person::name); 
R2dbcEntityTemplate<Person, Long>.column(Person::roleId); 

// result: "name", "role_id"

this is the goal I would like to do. and if you have any opinion please let me know!

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Apr 12, 2023
@mp911de
Copy link
Member

mp911de commented Apr 12, 2023

The code I was referring to is at:

https://github.com/spring-projects/spring-data-mongodb/blob/main/spring-data-mongodb/src/test/kotlin/org/springframework/data/mongodb/core/query/TypedCriteriaExtensionsTests.kt

Our extension provides then a criteria along the lines of:

val typed = Book::price gte 100
val criteria = Criteria("price").gte(100)

See also spring-projects/spring-data-mongodb#622

@mp911de mp911de added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged status: feedback-provided Feedback has been provided labels Apr 12, 2023
@mp911de mp911de changed the title kotlin dynamic query until function Add Type-safe Kotlin query extension Apr 12, 2023
@kihwankim
Copy link
Author

@mp911de

image

I wonder one stuff how to get column name?? because in R2dbcEntityTemplate you used DefaultNamingStrategy.INSTANCE for default.
But if people used different type of strategy then kotlin extension can not use like this Book::price gte 100
what about creating new R2dbcEntityTemplate function for creating column name in String type

this is the link: acbc814

@mp911de
Copy link
Member

mp911de commented Nov 14, 2024

Column names are not related at all as the Kotlin extensions work on the property level, effectively creating a Criteria that is getting mapped against the domain object metadata for column name resolution.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
in: kotlin Kotlin support type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants