-
Notifications
You must be signed in to change notification settings - Fork 602
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prepopulated database #774
Comments
I too am looking for information about this and did not find anything / maybe my search skills are bad. Did you find any solution? |
Hello @sidferreira @radex. Can you share some info on how to use prepopulated SQLite DB with WatermelonDB? We're struggling here with a lack of documentation on this one. |
I'm sure someone asked this before and I answered, but can't find it either ¯_(ツ)_/¯ There's no built-in support for this. One way is to generate a SQLite DB (you can use the the Node SQLite support in Or you could prepare a JSON file compatible with the Watermelon Sync format, and use If you figure out exactly how to do this, please do share in this thread to help others. |
We actually have a work around for it. Will post it later today. |
This is a very simplified version of it. But that's not a big deal IMHO... BTW, you need to add a .db file to the project properly. I added it to the |
@sidferreira thanks for sharing. Much appreciated! |
I'll try to get a tutorial into the whole nodejs + prepopulate thing, but can't give any timeline on that |
@sidferreira |
@cursivedgreat I'll check the android version in the coming weeks and update accordingly... I guess |
Here is my version.. `var RNFS = require('react-native-fs'); let database; const adapter = new SQLiteAdapter({ export async function getDatabaseAsync() {
return database; |
Trying out your solutions. What do i have to do with the schema? seems it's overriding the tables for me |
@cursivedgreat interesting approach... I have specific reasons to use the async every time :) |
@sidferreira can you tell me how you setup your schemas? Do you just copy the one on the existing db? |
Although that solution worked for me. I rewrote my approach because of async reason. Here is my updated steps Put the pre-populated copy code on native side.
call the above method from
` In javascript side do normal setup and that should work |
i'm actually trying this out on ios simulator atm. on ios sim i am successfully copying the asset to the directory but it seems its making a new blank database copy because of the schema. btw it's three backticks to make multiline code
|
@genesy I created a tool to create and update databases on command line. And it generates the DB file for me. Another option is to run the simulator and then use |
@sidferreira thanks for the quick reply. i actually have made a .db file successfully, my issue might be weird but when i do the copyDb file to the db it makes a new blank db using the schema from my AppSchema my question is how did you do your schemas to match your database? manually? seems mine is creating a new.db file because of my schema definition The db path here actually contains the correct .db file with all the tables but i can't query it not sure if these dbName values are doing anything for me
|
Can We see a little example with this sync and JSON file implementation ? I need that for initializate the DB, or maybe you know a simpler way? |
Ok I just solved my issue. I copied the new db that watermelondb generates and used that as my db file and insert all my items there. that was my issue. |
I couldn't get it working for Android with any of the solutions pasted above, so in conjunction with code from this PR I arrived at something like this:
Maybe it'll prove useful if the PR for Android path is ever merged. |
Follows a gist with my current use: https://gist.github.com/sidferreira/2b6b640e25544d601f311e35e430bce0 @radex should we add this to the docs? |
@sidferreira What do you propose? In docs, this whole discussion is linked: https://github.com/Nozbe/WatermelonDB/blob/master/docs-master/Advanced/ProTips.md |
@radex My suggestion was just about having clear documentation about it, instead of a link to a thread that will force the developer to search for a solution. IMHO clearly state one can embed a 🍉 DB is a major selling point. |
@sidferreira OK, PRs are welcome. |
What is the work around for the schema overriding the pre-populated database that I am adding. |
@radex Is there a way of adding a event handler to the DB setup kind of like the |
@KrisLau Not currently, but you can easily implement it in app code by setting a one-time flag at launch. if the flag isn't there, it means the db is new |
@ultra-mine Did you find a solution for this? |
@Stophface I took a detour and use the turbo login solution |
@michalpleszczynski @sidferreira @cursivedgreat Could you share the absolute path to your databases von iOS and Android? I stored my databases in However, when I try
It always tells me that it does not exist. Or do I have to set something in XCode/Android Studio that it bundles the database? |
You are running in a simulator right? |
@sidferreira Yes I am. I contact you on twitter. |
How to copy and move the bundled database to somewhere, where watermelonDB can work with it, follow along @sidferreira posts and gist. However, you need to do more to get it working.
Further, make sure the
You can set that number for the
If that does not work, download a SQLite browser like Then, when you create the
Once you initialized the database, only pass the database name to the
|
me too.
I open the location on a mobile phone or emulator, but both don't have any files and don't know where they are located. any solutions? |
I have an open PR to add sqlite backup and restore on iOS. May or may not be relevant here. I found that copying out the underlying database file (watermelon.db in this example) in a running app was not properly reflecting the data in the db. |
@heyalexchoi I am curious, could you share how you did it before creating a PR. With JavaScript I assume? |
Anyone here could give us a link to a tutorial or something helps me as a beginner to have a prepopulated database with some default data !? |
@Hostname47 there are all the information you need in this thread. Read through it and follow along :) |
Hey everyone, this alredy have a native function? if not, have a lot of solutions in this issue, what is the best? |
@Poowerllz I suggest following #774 (comment) as I helped @Stophface, and it was the last time I made it work. Sadly I'm not using WatermelonDB anymore. |
So we cannot enable jsi for prepopulated database |
@linhttbk97 Great guide! Indeed, adding many steps I did not mention. About the path, I used a relative path to still work with JSI, but it was back in the day. Sadly, I don't use Watermelon anymore. |
Yeah, I use database path on Android. I still can inspect database but it's a new database with addition columns like id, _status, _changed. But i can't find the that database file inside device explorer (support in android studio) |
@linhttbk97 I remember there was a small trick to find it... I used the DOCUMENT folder to host the DB and make it easier |
@sidferreira |
Why we can't use JSI with this? |
Anyone know if following this guide of prepopulated database is the only way I can use watermelondb Sync engine without using watermelon for anything else? We have our own rendering and complex needs (and a desktop app) so all the watermelon rendering frontend stuff we don’t need. But we love the Sync engine. Does anyone know how we can do that? Thanks! |
Is there any info/docs how to use prepopulated sqlite db with watermelon db?
The text was updated successfully, but these errors were encountered: