storesafe/cordova-sqlite-storage

CREATE database if it does not exist should be optional

brodybits opened this issue · 3 comments

ADDITIONAL NOTE(S):

It would be ideal to keep the API as consistent as possible with the following:

I am thinking of adding an option such as createIfNecessary, createIfNotExist, or createIfNotPresent to let the app developer control this.

An alternative idea discussed in #401 is to add an openDatabase creation callback according to the Web SQL API. I think it would add extra, unneeded complexity but am happy to leave it open for discussion.

ADDITIONAL NOTE: the openDatabase creation callback would add extra complexity to higher level libraries such as Ionic-native & https://github.com/nolanlawson/pouchdb-adapter-cordova-sqlite, and it may cause problems with pre-populated database options discussed in storesafe/cordova-sqlite-storage-help#26 as well. NOT DESIRED.

I would like to also address some discussion points in danielsogl/awesome-cordova-plugins#881:

From danielsogl/awesome-cordova-plugins#881 (comment) by @cocowalla:

The openDatabase method has been renamed to create, which despite the misleading name only actually creates a new database if the specified file doesn't already exist.

Agreed on my part.

From danielsogl/awesome-cordova-plugins#881 (comment) by @cocowalla:

  • Bit of a tangent, but both openDatabase and create don't quite describe what is happening - how about openOrCreate? (although I imagine you'll be reluctant to change it again so soon)

Nice idea but I would not favor it.

In general I think this plugin should have a single openDatabase entry point where the options may be passed down from higher level application code and libraries such as Ionic-native and pouchdb-adapter-cordova-sqlite.

As I said above my idea is to add an option such as createIfNecessary, createIfNotExist, or createIfNotPresent to let the app developer control this.

ADDITIONAL COMMENT: I would like to keep the API as consistent as possible with other SQLite APIs as discussed in the comment above.

I will probably need at least 1-2 months to clear my backlog before resolving this one.

@brodybits your alternative using an option sounds fine too, although its not immediately clear to me what the meaning of createIfNecessary and createIfNotPresent are?