Skip to content
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

Migration 1.2.0 DatabaseClient.sql #500

Closed
Camsteack opened this issue Nov 13, 2020 · 4 comments
Closed

Migration 1.2.0 DatabaseClient.sql #500

Camsteack opened this issue Nov 13, 2020 · 4 comments
Labels
for: external-project For an external project and not something we can fix status: duplicate A duplicate of another issue

Comments

@Camsteack
Copy link

Hi,

I am trying to migrate my application to 1.2.1 and I am having trouble with the new database client DSL to execute SQL statements. With the previous DatabaseClient you could do

databaseClient.execute(someSql).as(Type.class).fetch().all()

But now the GenericExecuteSpec doesn't provide an as method. What would be the way to achieve the same result now without having to have a custom mapper for each type ?

Thanks a lot

@tomas-c
Copy link

tomas-c commented Nov 18, 2020

Just had to do a migration myself, the upgrade guide was a good starting point.

Seems the options are:

  • Rewrite with Spring Data Repositories (you can use @Query annotation for custom SQL)
  • Rewrite with R2dbcEntityTemplate
  • Use the GenericExecuteSpe.map() method with MappingR2dbcConverter

For the last option in Kotlin:

databaseClient
    .execute(someSql)
    .`as`(Type::class.java)
    .fetch()
    .all()

becomes

databaseClient
    .sql(someSql)
    .map{ row, meta -> mappingR2dbcConverter.read(Type::class.java, row, meta)}
    .all()

@MuizMahdi
Copy link

MuizMahdi commented Dec 12, 2020

Isn't the .map() synchronous?

Also, I couldn't find any example on using the MappingR2dbcConverter in the docs.

  1. Do we need to map the row to object manually?
  2. Wasn't it more convenient to use .as(Type.class)?

@rjaros
Copy link

rjaros commented Dec 21, 2020

I have created a small Kotlin project, which addresses this issue:
https://github.com/rjaros/r2dbc-e4k

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

mp911de commented Apr 8, 2021

DatabaseClient is now part of Spring Framework and there's already a ticket for this topic with spring-projects/spring-framework#26021 so closing this one as duplicate.

@mp911de mp911de closed this as completed Apr 8, 2021
@mp911de mp911de added for: external-project For an external project and not something we can fix status: duplicate A duplicate of another issue and removed status: waiting-for-triage An issue we've not yet triaged labels Apr 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
for: external-project For an external project and not something we can fix status: duplicate A duplicate of another issue
Projects
None yet
Development

No branches or pull requests

6 participants