CREATE database if it does not exist should be optional
brodybits opened this issue · 3 comments
ADDITIONAL NOTE(S):
- As discussed in storesafe/cordova-sqlite-storage-help#26 it would make it much easier to deal with the different pre-populated database options discussed there.
It would be ideal to keep the API as consistent as possible with the following:
- Web SQL openDatabase API (window.openDatabase) ref: https://www.w3.org/TR/webdatabase/#databases
- existing plugin API (sqlitePlugin.openDatabase) as documented in https://github.com/litehelpers/Cordova-sqlite-storage#opening-a-database which originated in https://github.com/davibe/Phonegap-SQLitePlugin
- SQLite C API with SQLITE_OPEN_CREATE flag ref: https://www.sqlite.org/c3ref/open.html
- Android SQLiteDatabase API ref: https://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html with the following options:
- android.database.sqlite.SQLiteDatabase.openOrCreate (overloaded member functions)
- android.database.sqlite.SQLiteDatabase.CREATE_IF_NECESSARY open flag ref: https://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html#CREATE_IF_NECESSARY
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 tocreate
, 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
andcreate
don't quite describe what is happening - how aboutopenOrCreate
? (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?