https://kotlinlang.org logo
#compose-desktop
Title
# compose-desktop
s

Samson Jisso

12/06/2023, 8:00 AM
hello @here, i am new to compose desktop, i wanted to add database functionality using SQLDelight, but i couldn't figure it out, i need help, templates would be helpful,
s

sasikanth

12/06/2023, 9:44 AM
There are SQLDelight samples in the repo itself. Hopefully that's useful https://github.com/cashapp/sqldelight/tree/master/sample
p

Pablichjenkov

12/06/2023, 9:57 AM
m

Michael Paus

12/06/2023, 11:51 AM
@hfhbd Using JDBC is not such a good idea because it is not a multiplatform solution. It binds you to Java.
j

jw

12/06/2023, 11:59 AM
So does Compose Desktop
m

Michael Paus

12/06/2023, 12:03 PM
The OP asked for Compose Desktop but this does not exclude the possibility to later extend that to, e.g., iOS. I just wanted to make him aware of the fact that he is leaving the multiplatform ground by using JDBC.
h

hfhbd

12/06/2023, 12:05 PM
Sqldelight is multiplatform, but each platform needs a specific driver, like you need a platform runtime/window management. So I don’t get your point.
m

Michael Paus

12/06/2023, 12:07 PM
Yes, but that is just adding one platform specific dependency. How would you get a solution based on JDBC running on iOS?
j

jw

12/06/2023, 3:10 PM
You wouldn't, the same way you wouldn't expect a Compose Desktop app to just work on iOS either.
The driver is the variance mechanism that allows the rest of SQL delight to be multiplatform. So you'd vary that with expect/actual or inversion of control. There's no point in pre-engineering some indirection here because the driver already provides it.
m

Michael Paus

12/07/2023, 3:55 PM
You’re comparing apples with oranges. The SQLDelight API is multiplatform and JDBC is not. Of course you can try to re-invent something like SQLDelight but I don’t see why anybody should do that.
j

jw

12/07/2023, 3:59 PM
I'm not sure what I'm comparing
Why would you reinvent SQL delight when it's already multiplatform?
Why would you worry about using JDBC when you're on the JVM?
m

Michael Paus

12/08/2023, 9:17 AM
1. You are comparing one API which is multiplatform (SQLDelight) against another one (JDBC) which is not. 2. I am of course not proposing to reinvent SQLDelight. I said that when you use JDBC directly and you wrap your code, which is written agains its API, in expect/actual pairs to make it multiplatform, you basically are already creating some minimalistic reinvention of SQLDelight because you duplicate some of its functionality. 3. That’s a matter of opinion, of course but in the light of recent developments at the WASM front it is quite likely that in a not so distance future you might want to switch from JVM to WASM and then it would have been a good idea to have programmed agains a multiplatform API right from the beginning.
h

hfhbd

12/08/2023, 10:43 AM
We always talk about using SqlDelight with the JdBC driver, not plain JDBC.
m

Michael Paus

12/08/2023, 11:54 AM
Ok, that makes sense then but you should have made that clearer. I am actually using that myself too.
Copy code
implementation("app.cash.sqldelight:sqlite-driver:$sqldelightVersion")
I thought you where proposing to directly use JDBC instead of SQLDelight.
5 Views