https://kotlinlang.org logo
Title
p

Prateek Kumar

05/08/2023, 7:08 AM
Hello… If you already have “room” added as dependency and are using it across app, is it worth migrating to Datastore to save key-value pairs? It is just one table in my database “vs” one extra dependency and more learning curve as everyone is already familiar to room, and the room setup is hardly 30 lines for that extra table. Even room has “suspend” support and other things.
a

a_duck

05/08/2023, 7:22 AM
Based on this article, datastore is aimed to replace sharedpreferences, not Room database
p

Prateek Kumar

05/08/2023, 8:43 AM
Yes but just that would u use it if u already had a working room setup for key value pair?
f

Francesc

05/08/2023, 3:07 PM
room and datastore serve different purposes, not using the right tool now will only lead to pain in the future
p

Pablichjenkov

05/08/2023, 3:13 PM
I have been using SQDelight to save key/value pairs in multiplatform projects. It's been good so far.
f

Francesc

05/08/2023, 3:53 PM
yes, that's the same as saying "I've been using my hammer to insert my screws, it's been good so far"
p

Pablichjenkov

05/08/2023, 4:39 PM
Anything in particular Francesc, what could make the difference? Or what advantages could have one approach over the other?
f

Francesc

05/08/2023, 4:47 PM
it's just a matter of using the right tool for the right job. Datastore is meant for small set of key/value pairs (or small data objects with protobuf), while Room or SQLDelight are relational databases that serve different purposes, they can handle large data sets, filtering, and much more. While you can use Room to store your key/value pairs, it's just not the right tool for the job, datastore has been optimized for this kind of persistent storage and is a fetter fit
p

Pablichjenkov

05/08/2023, 5:25 PM
Gotcha, makes sense