Luca Fülbier
Luca Fülbier

Reputation: 2731

When to create local (SQLite) database for an application?

I want to be able to support local and remote databases with my application, so i don't have to have an internet connection on my laptop to use the application. I got all my database code set up, but i am not quite sure, when to create my local database (i am using SQLite).

Here are some alternatives i could think of:

  1. Make it part of the build-process
  2. Make it part of the application startup (create if not exists)
  3. Make it a script, that the user has to use manually

Which one of these is preferable? Are there better ways?

Upvotes: 0

Views: 45

Answers (1)

Exile79
Exile79

Reputation: 166

  1. The only reason I can thing that is beneficial to pre-create the database during build is if you have some initial data for it and you find it pretty time-consuming inserting those rows into the db. The size of your package will be bigger of course, but that would also happen if you had those data in some scripts and executed them on startup (the scripts would contain the same amount of data anyway)
  2. (This is my choice in general) Execute sql scripts at startup by the app. Sql-scripts can be version-controlled (that by itself is definite winner). Also you are more expandable in case of updating sqlite version or something.
  3. Anything asked by the user to do manually is annoying and prone to errors. Resort to this only if the app fails for some reason to auto-create the file for some reason (permissions?)

Upvotes: 1

Related Questions