quarkusio / quarkus

Quarkus: Supersonic Subatomic Java.
https://quarkus.io
Apache License 2.0
13.8k stars 2.68k forks source link

Offer coroutine support in `quarkus-mongodb-panache-kotlin` #34624

Open hantsy opened 1 year ago

hantsy commented 1 year ago

Description

To use the Repository pattern and Kotlin Coroutines, I would like there is Coroutines variant and return Coroutines flavor result directly(no transform in the codes).

interface CoroutinePanacheRepositoryBase<E, ID> {

   suspend findById(ID): T?
   findAll():Flow<E>
}

In Spring and Micronaut, the basic Kotlin support just uses some Kotlin extensions to extend the functionality on the existing Java API, only Coroutines used standalone API for it.

Implementation ideas

No response

quarkus-bot[bot] commented 1 year ago

/cc @FroMage (panache), @evanchooly (kotlin), @geoand (kotlin), @loicmathieu (panache)

geoand commented 1 year ago

I am pretty sure we already have an issue for this, but I'm on a phone now so it's hard to check

geoand commented 1 year ago

We already have this in the quarkus-hibernate-reactive-panache-kotlin

hantsy commented 1 year ago

@geoand I do not find this in mongo kotlin support. https://github.com/hantsy/quarkus-sandbox/blob/master/mongodb-kotlin-co/src/main/kotlin/com/example/PostRepository.kt

geoand commented 1 year ago

The issue never mentioned Mongo to begin with, but yeah, good point.

I'll reopen the issue and fix the title.

hantsy commented 1 year ago

@geoand Why the common Repository interfaces are not shared in all data storage solutions? like Spring Data and Micronaut Data.

loicmathieu commented 1 year ago

@hantsy this was a choice we made a long time ago when building MongoDB With Panache. At the time, we was not sure that the two implementations will offers the same methods, and in fact some methods are different on MongoDB with Panache than Hibernate with Panache. At Quarkus, we also don't like to have too many abstraction (do you already try to browse the code of Spring Data ... you'll know what I means ...). We also fear that it will give the false impression that MongoDB With Panache is an ODM or even worth a JPA implementation ...

hantsy commented 1 year ago

We already have this in the quarkus-hibernate-reactive-panache-kotlin

@geoand I can not find the Coroutines repository support here, https://github.com/quarkusio/quarkus/tree/3.2.2.Final/extensions/panache/hibernate-reactive-panache-kotlin/runtime/src/main/kotlin/io/quarkus/hibernate/reactive/panache/kotlin

geoand commented 1 year ago

You are right... I thought I saw some Kotlin suspend functions, but I can't find them know... @evanchooly what's the status of Hibernate Reactive + Kotlin Coroutines?

evanchooly commented 1 year ago

I don't know that any work has been done on HR and kotlin. HR was pretty new last time I did any such work and I just haven't gotten around to it. Reactive isn't really my forte so I'd have to do a bit of research. It's probably as much as work as the others, though, so we have a pretty solid game plan for such things.

hantsy commented 1 year ago

@geoand BTW, why we need a kotlin variant of PanacheRepository?

In a Kotlin code project, we can use the Java interface directly. And in Spring Data/Micronaut Data for this case, only adding some extension functions to these Java interfaces.

hantsy commented 1 year ago

@evanchooly Have a look at Micronaut Data Kotlin coroutines repository implementations, it also used a build time enhancement, right?