Skip to content

Commit e8f2e26

Browse files
author
Christopher J. Brody
committed
Move & update existing browser platform notes
ref: - #297 - #576 - storesafe/cordova-sqlite-storage-help#8
1 parent e0faa5b commit e8f2e26

File tree

1 file changed

+43
-12
lines changed

1 file changed

+43
-12
lines changed

README.md

+43-12
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Native SQLite component with API based on HTML5/[Web SQL (DRAFT) API](http://www
66
- macOS ("osx" platform)
77
- Windows 10 (UWP) DESKTOP and MOBILE (see below for major limitations)
88

9-
Browser platform is supported _with some limitations (no support for numbered parameters)_ as described in [Browser platform usage notes](#browser-platform-usage-notes) section below.
9+
Browser platform is currently supported with some limitations as described in [browser platform usage notes](#browser-platform-usage-notes) section below, will be supported with more features such as numbered parameters in upcoming major release for July 2018 (see below).
1010

1111
**LICENSE:** MIT, with Apache 2.0 option for Android and Windows platforms (see [LICENSE.md](./LICENSE.md) for details, including third-party components used by this plugin)
1212

@@ -29,13 +29,6 @@ New release in July 2018 will include the following major enhancements ([litehel
2929
- ~~drop Android NDK build for x86_64 ([litehelpers/Cordova-sqlite-storage#772](https://github.com/litehelpers/Cordova-sqlite-storage/issues/772)); NDK build for x86 will still work on x86_64 if no other plugins have NDK build for x86_64; feedback is requested in case of interest in NDK build for x86_64~~
3030
- drop support for location: 0-2 values in openDatabase call (please use `location: 'default'` or `iosDatabaseLocation` setting in openDatabase as documented below)
3131

32-
## Browser platform usage notes
33-
34-
As stated above the browser platform will be supported _(with numbered parameters working_ using [kripken / sql.js](https://github.com/kripken/sql.js) (see [litehelpers/Cordova-sqlite-storage#576](https://github.com/litehelpers/Cordova-sqlite-storage/pull/576)) in the near future. Alternative solutions for now _(with no support for numbered parameters such as `?1`, `?2`, ...)_:
35-
36-
- Use [brodybits / sql-promise-helper](https://github.com/brodybits/sql-promise-helper) as described in [brodybits/sql-promise-helper#4](https://github.com/brodybits/sql-promise-helper/issues/4)
37-
- Mocking on Ionic Native is possible as described in <https://www.techiediaries.com/mocking-native-sqlite-plugin/> and <https://medium.com/@tintin301/ionic-sqlite-storage-setting-up-for-browser-development-and-testing-67c0f17fc7af>
38-
3932
## About this plugin version
4033

4134
This is the common plugin version which supports the most widely used features and serves as the basis for the other versions.
@@ -142,7 +135,7 @@ or using numbered parameters as documented in <https://www.sqlite.org/c3ref/bind
142135
});
143136
```
144137

145-
To check the data using the "standard" (deprecated) transaction API:
138+
To check the data using the DRAFT standard transaction API:
146139

147140
```Javascript
148141
db.transaction(function(tx) {
@@ -154,7 +147,9 @@ To check the data using the "standard" (deprecated) transaction API:
154147
});
155148
```
156149

157-
### Using recommended API calls
150+
### Using plugin-specific API calls
151+
152+
NOTE: These samples will NOT work alternative 3 for browser platform support discussed in [browser platform usage notes](#browser-platform-usage-notes).
158153

159154
To populate a database using the SQL batch API:
160155

@@ -194,6 +189,8 @@ To check the data using the single SQL statement API:
194189
});
195190
```
196191

192+
### More detailed sample
193+
197194
See the [Sample section](#sample) for a sample with a more detailed explanation (using the DRAFT standard transaction API).
198195

199196
<!-- END quick tour -->
@@ -326,6 +323,37 @@ In addition, this guide assumes a basic knowledge of some key JavaScript concept
326323

327324
**NOTICE:** This plugin is only supported with the Cordova CLI. This plugin is *not* supported with other Cordova/PhoneGap systems such as PhoneGap CLI, PhoneGap Build, Plugman, Intel XDK, Webstorm, etc.
328325

326+
## Browser platform usage notes
327+
328+
As stated above the browser platform will supported with features such as numbered parameters using [kripken / sql.js](https://github.com/kripken/sql.js) (see [litehelpers/Cordova-sqlite-storage#576](https://github.com/litehelpers/Cordova-sqlite-storage/pull/576)) in the near future. Alternative solutions for now, with features such as numbered paramters (`?1`, `?2`, etc.) missing:
329+
330+
1. Use [brodybits / sql-promise-helper](https://github.com/brodybits/sql-promise-helper) as described in [brodybits/sql-promise-helper#4](https://github.com/brodybits/sql-promise-helper/issues/4)
331+
2. Mocking on Ionic Native is possible as described in <https://www.techiediaries.com/mocking-native-sqlite-plugin/> and <https://medium.com/@tintin301/ionic-sqlite-storage-setting-up-for-browser-development-and-testing-67c0f17fc7af>
332+
3. Open the database as follows:
333+
334+
```js
335+
if (window.cordova.platformId === 'browser') db = window.openDatabase('MyDatabase', '1.0', 'Data', 2*1024*1024);
336+
else db = window.sqlitePlugin.openDatabase({name: 'MyDatabase.db', location: 'default'});
337+
```
338+
339+
or more compactly:
340+
341+
```js
342+
db = (window.cordova.platformId === 'browser') ?
343+
window.openDatabase('MyDatabase', '1.0', 'Data', 2*1024*1024) :
344+
window.sqlitePlugin.openDatabase({name: 'MyDatabase.db', location: 'default'});
345+
```
346+
347+
(lower limit needed to avoid extra permission request popup on Safari)
348+
349+
and limit database access to DRAFT standard transactions, no plugin-specific API calls:
350+
- no `executeSql` calls outside DRAFT standard transactions
351+
- no `sqlBatch` calls
352+
- no `echoTest` or `selfTest` possible
353+
- no `deleteDatabase` calls
354+
355+
It would be ideal for the application code to abstract the openDatabase part away from the rest of the database access code.
356+
329357
### Windows platform notes
330358

331359
The Windows platform can present a number of challenges which increase when using this plugin. The following tips are recommended for getting started with Windows:
@@ -617,7 +645,7 @@ Additional limitations are tracked in [marked Cordova-sqlite-storage doc-todo is
617645

618646
## Some tips and tricks
619647

620-
- If you run into problems and your code follows the asynchronous HTML5/[Web SQL](http://www.w3.org/TR/webdatabase/) transaction API, you can try opening a test database using `window.openDatabase` and see if you get the same problems.
648+
- In case of issues with code that follows the asynchronous Web SQL transaction API, it is possible to test with a test database using `window.openDatabase` for comparison with (WebKit) Web SQL.
621649
- In case your database schema may change, it is recommended to keep a table with one row and one column to keep track of your own schema version number. It is possible to add it later. The recommended schema update procedure is described below.
622650

623651
<!-- END Some tips and tricks -->
@@ -688,7 +716,6 @@ FUTURE TBD: Proper date/time handling will be further tested and documented at s
688716
## Major TODOs
689717

690718
- More formal documentation of API, especially for non-standard functions
691-
- Browser platform
692719
- IndexedDBShim adapter (possibly based on IndexedDBShim)
693720
- Further cleanup of [support](#support) section
694721
- Resolve or document remaining [open Cordova-sqlite-storage bugs](https://github.com/litehelpers/Cordova-sqlite-storage/issues?q=is%3Aissue+is%3Aopen+label%3Abug-general)
@@ -954,6 +981,8 @@ The following types of SQL transactions are supported by this plugin version:
954981

955982
### Single-statement transactions
956983

984+
NOTE: This call will NOT work alternative 3 for browser platform support discussed in [browser platform usage notes](#browser-platform-usage-notes).
985+
957986
Sample with INSERT:
958987

959988
```Javascript
@@ -1001,6 +1030,8 @@ db.executeSql("SELECT UPPER('First') AS uppertext", [], function (resultSet) {
10011030

10021031
### SQL batch transactions
10031032

1033+
NOTE: This call will NOT work alternative 3 for browser platform support discussed in [browser platform usage notes](#browser-platform-usage-notes).
1034+
10041035
Sample:
10051036

10061037
```Javascript

0 commit comments

Comments
 (0)