Hello. I’m creating an app with SQLite DB.
I need to pre-populate the db: I have a json file with my data, but I don’t know how can I seed the DB just the first time I open my app.
Any idea?
Or maybe is there a way to open a sqlite db file?
Hello. I’m creating an app with SQLite DB.
I need to pre-populate the db: I have a json file with my data, but I don’t know how can I seed the DB just the first time I open my app.
Any idea?
Or maybe is there a way to open a sqlite db file?
In such cases I find it a good idea to have a config
table with name
and value
fields.
When your app starts, after db init, check for the config with your desired name
and check what it’s value
is.
If it’s not what you expect, initiate the json file parsing, insert the data to the db and finally update your config
tables name
config and change the value
to what it should be when the json file has been imported.
So next time your app starts and checks the config
and sees that the file has been imported, skips it.
So:
Sound good? I don’t know if I can produce an app like this but I will try!