Just curious, in compose-desktop do we have a loca...
# compose-desktop
v
Just curious, in compose-desktop do we have a local database like
room
? I think other desktop app uses remote db for their apps, no?
a
2
x
their documented implementation is a in-memory database though
🚫 1
t
it has (incubating) support for h2, which is a pure java sql database you could embed
v
what is h2?
t
look behind the comma of my sentence
😄 1
v
so we can embed this in compose desktop apps? any sample or something
h
Hmm h2 is one of the database most known around. There are plenty of examples out there. Did you do some google search?
v
I looked for local db in compsoe desktop, and looked into some repos , but was not able to find any
h
Search for kotlin H2 database
t
I’ve not personally embedded it in a Compose desktop app, also can’t vouch for the quality of the sqldelight integration (though I can certaintly vouch for sqldelight in general). but I have seen java desktop programs use it in the past as a local database (using regular jdbc), since it’s just a regular maven dependency it simplifies the distribution a lot. then recently I saw that sqldelight added support, it sounds like a good combination to me.
v
oh okay
t
however I think (? not sure) the sqlite driver, even though the example mentioned uses an in memory database, can probably also create a file based database. as in, the jdbc driver itself contains a copy of sqlite.
but this is new to me.
h
I’ve used the file based version of SQLite with sqldelight. Cause I needed persistence between restarts.
t
yeah so the example here https://cashapp.github.io/sqldelight/jvm_sqlite/ but just with a file path instead of
IN_MEMORY
should work too. interesting.
m
I also use SQLite via https://github.com/xerial/sqlite-jdbc . This way I stay compatible with all platforms because SQLite has the same file format everywhere. I haven’t yet tried that myself but you can also combine that with
sqldelight
.
e
You can use any database you'd like (and there are lots of them). Most popular would probably be SQLite, MySQL, and Postgres. You can use something like SqlDelight with all of those 3, and there are plenty of other JVM libraries that would work as well Room is an Android library that creates an ORM around SQLite that exists on all Android devices.
t
has anyone ever successfully stuffed MySQL or Postgres into their distribution through jpackage though? (genuine curiosity)
g
I wouldn't bother with embedding MySQL to desktop, it's overkill imo, SQLite or h2 is the way to go imo
Also we use sqldelight on Android and I like it more than room, it's so refreshing to work with sql directly, also no annotation processing
💯 2
e
Not sure if anyone has ever done it, but it's probably a bad idea. If you control the desktop environment you can ensure that it's installed on the local machine, otherwise you'll need something embedded line SQLite or h2.
h
If you embed the database and not use in memory to store the information between restarts how and where would you store the database?
m
@Humphrey You store it into a simple file. That’s why I wrote in my post above “This way I stay compatible with all platforms because SQLite has the same file format everywhere.”
h
That I know, but the location of it. You would like it to work on windows and Linux but what would be a good location.
m
Ah, I see. For this purpose I create an invisible folder like .MyApp in the users home directory. Some operating systems have dedicated folders where such application data is stored. When the app is launched for the first time it creates and initialises this folder. This way you can, e.g., store an initial database inside your distributable and copy it into this folder for later use and modification.
👍 1
t
also a blast from the past for me, but seems somewhat up to date still: https://github.com/harawata/appdirs
👍 3
h
Thanks that is something I really was looking for. Useful.
v
I am new to the desktop apps, so has anyone done any sample or something like local db and done simple CRUD operations in desktop ? something I can refer to, because I can't find any repo related this I have got the basic idea like we can use SQLDelight though
g
Sqldelight has simple examples how to do this on jvm: https://cashapp.github.io/sqldelight/jvm_sqlite/
and check the rest of the docs to how actually interact with db, it the same on all platforms
🙏 2
k
Thanks all for this Q&A too! Something that was going to baulk me down the track! The looks very handy.
1076 Views