Hello folks, I have been exploring at different da...
# orm-help
n
Hello folks, I have been exploring at different database options from sequelize to typeorm but prisma hands down wins on almost all cases. I am trying to create an offline app that syncs with an API when there is connection and we were planning to use sqlite with Ionic. I have already tried out prisma locally on a desktop device and it has been an amazing experience but it looks like it won't work with Ionic/sqlite as it seems to require nodejs for things like running migrations and such? My use case is individual users will have their own the sqlite database and when we push for updates, if there are database changes, we will have to run the migration on each of those devices. We obviously won't be able to run the migrations like we do on a nodejs setup but I saw an example where typeorm is being used with Ionic so I was thinking it must be possible? Any resources and answers on this would be super helpful as I can't find anything about mobile support on the docs/forums. Thanks
r
@Niraj 👋 You are correct in assuming that as Prisma currently requires a server to perform migrations. This feature request is similar to your use case where Prisma can be run on different places so it would be great if you could add the above use case in that request and a 👍 as well 🙂
n
@Ryan Thanks for letting me know. Such a shame that it cannot be used already so I guess we will have to go with TypeORM for now. 😞 I will add into that issue. Thanks.
j
Can you link to the example where TypeORM is used in an Ionic context? I would love to understand that better. As @Ryan told you, Prisma was not really built for such a use case as a browser side web app yet. And Ionic is special with Capacitor/Cordova anyway, so we have minimal experience with that setup in general. The SQLite in that context is also usually different (via file or browser APIs) than the one Prisma talks to, so we might be up for an uphill battle here just figuring out all the complexities. (The same is true for using Prisma in an Electron context for example).
n
@janpio Here is one I found that I am still trying to figure out myself ... https://github.com/coturiv/ionic-typeorm-starter
j
From a quick look, they seem to be using the Cordova plugin that gives an API to a SQL database, which the TypeORM browser thing seems to be able to use - which is quite neat. (I used to contribute both to Cordova and Ionic - so this is pretty much a blast from the past for me 😄 ).
Let me know if this actually works. I also build a bunch of offline apps on Ionic a few years back, and we always ended up implementing both the database communication manually and the sync via some hacked approach - so would be interesting to learn if the ecosystem improved since then.
n
@janpio Trying to implement it in Ionic 5 with vue and barely any resources. Looks like will be using this this plugin and creating some sort of hacked out solution 😄 https://github.com/capacitor-community/sqlite Would have been take my money if Prisma had a solution 😛
j
At least you are on Capacitor, so a more modern solution than Cordova - but of course at the cost of all the old things you find on the internet (as the typeorm thing above) not being compatible with it.
n
Indeed ... not much documentation on vue/ionic outside of basic stuff ... almost everything else is angular/ionic... Actually thinking of installing prisma and using it's migration generator so that we don't have to manually write SQL queries and if prisma works with ionic in the future, can use it straight away 😅
👍 1
j
To expand a bit why this would generally be difficult for Prisma: The Query Engine we are using ships with the SQLite client and can only talk to a local file. That is a limitation that makes total sense on the server side where Prisma is usually used. It becomes harder in a web/browser context, where there is not real file system and SQLite is usually provided via a browser API or a native API (as in the Capacitor and Cordova plugin). I am sure there is a solution on how to make them talk to each other, but it is not something that works out of the box and that will be trivial to figure out and fix (Especially with all the mobile platforms, versions, changes by device manufacturer etc)
Using Prisma as a nice way to create the sqlite file, or create the SQL queries to create it is actually a nice idea. That way you can maintain your schema in a Prisma schema, and use our tooling for creating the migrations, playing around with the database file and everything. You then "just" (famoust last words...) need to find a way to deploy that on device.
n
haha yep
I think that's where TypeORM comes in as it's supposed to "already work" 😛