diff --git a/README.md b/README.md index 42e2ed90..21ee7daf 100644 --- a/README.md +++ b/README.md @@ -44,9 +44,9 @@ npx cap sync ``` ``` -pnpm install --save @capacitor-community/sqlite -pnpm install --save jeep-sqlite -pnpm install --save sql.js +pnpm add @capacitor-community/sqlite +pnpm add jeep-sqlite +pnpm add --save-exact sql.js@1.11.0 npx cap sync ``` @@ -113,6 +113,12 @@ The plugin follows the guidelines from the `Capacitor Team`, Meaning that it will not work in IE11 without additional JavaScript transformations, e.g. with [Babel](https://babeljs.io/). You'll need the usual capacitor/android/react npm script to build and copy the assets folder. +The file `sql-wasm.wasm` must come from `sql.js` 1.11.0. A file from version 1.13.0 or newer does not work. It fails with an error like `function import requires a callable`. The [Web Usage](https://github.com/capacitor-community/sqlite/blob/master/docs/Web-Usage.md) documentation explains why. Install this exact version in your app before you copy the file: + +``` +npm install --save-exact sql.js@1.11.0 +``` + #### For Angular framework - Copy manually the file `sql-wasm.wasm` from `node_modules/sql.js/dist/sql-wasm.wasm` to the `src/assets` folder of YOUR_APP diff --git a/docs/Ionic-React-Usage.md b/docs/Ionic-React-Usage.md index 72461924..1f003a38 100644 --- a/docs/Ionic-React-Usage.md +++ b/docs/Ionic-React-Usage.md @@ -39,6 +39,8 @@ To install it in your Ionic/React App npm i --save-dev jeep-sqlite@latest ``` +Then follow the setup in [Web Usage](https://github.com/capacitor-community/sqlite/blob/master/docs/Web-Usage.md). It covers `sql.js` and the `sql-wasm.wasm` file. + ### React SQLite Hook Declaration for platforms other than Web @@ -94,7 +96,7 @@ import { createRoot } from 'react-dom/client'; import App from './App'; import * as serviceWorkerRegistration from './serviceWorkerRegistration'; import reportWebVitals from './reportWebVitals'; -import { defineCustomElements as jeepSqlite, applyPolyfills, JSX as LocalJSX } from "jeep-sqlite/loader"; +import { defineCustomElements as jeepSqlite, JSX as LocalJSX } from "jeep-sqlite/loader"; import { HTMLAttributes } from 'react'; import { Capacitor } from '@capacitor/core'; import { CapacitorSQLite, SQLiteConnection, SQLiteDBConnection } from '@capacitor-community/sqlite'; @@ -112,9 +114,7 @@ declare global { } } -applyPolyfills().then(() => { - jeepSqlite(window); -}); +jeepSqlite(window); window.addEventListener('DOMContentLoaded', async () => { console.log('$$$ in index $$$'); const platform = Capacitor.getPlatform(); diff --git a/docs/Ionic-Vue-Usage.md b/docs/Ionic-Vue-Usage.md index 4620b971..c1e4a07c 100644 --- a/docs/Ionic-Vue-Usage.md +++ b/docs/Ionic-Vue-Usage.md @@ -102,18 +102,18 @@ Now the Singleton SQLite Hook `$sqlite`and Existing Connections Store `$existing As for the Web platform, the `jeep-sqlite` Stencil component is used and requires the DOM: the declaration of the SQLite Hook has to be moved to the App.vue +First follow the setup in [Web Usage](https://github.com/capacitor-community/sqlite/blob/master/docs/Web-Usage.md). It covers `jeep-sqlite`, `sql.js` and the `sql-wasm.wasm` file. + So the `main.ts`file ```js ... -import { defineCustomElements as jeepSqlite, applyPolyfills } from "jeep-sqlite/loader"; +import { defineCustomElements as jeepSqlite } from "jeep-sqlite/loader"; import { Capacitor } from '@capacitor/core'; import { CapacitorSQLite, SQLiteConnection, SQLiteDBConnection } from '@capacitor-community/sqlite'; import { useState } from '@/composables/state'; import { schemaToImport179 } from '@/utils/utils-import-from-json'; -applyPolyfills().then(() => { - jeepSqlite(window); -}); +jeepSqlite(window); window.addEventListener('DOMContentLoaded', async () => { const platform = Capacitor.getPlatform(); const sqlite: SQLiteConnection = new SQLiteConnection(CapacitorSQLite) diff --git a/docs/TypeORM-Usage.md b/docs/TypeORM-Usage.md index 4bafb829..895b1585 100644 --- a/docs/TypeORM-Usage.md +++ b/docs/TypeORM-Usage.md @@ -253,6 +253,8 @@ In particular in the : }, ``` +The `sql-wasm.wasm` file must come from `sql.js` 1.11.0. See [Web Usage](https://github.com/capacitor-community/sqlite/blob/master/docs/Web-Usage.md). + #### 4. Add the following to tsconfig.json ```json diff --git a/docs/Web-Usage.md b/docs/Web-Usage.md index 6f48abec..99984844 100644 --- a/docs/Web-Usage.md +++ b/docs/Web-Usage.md @@ -14,8 +14,11 @@ When your developement is fully tested, it will be a good idea to minimize the p ```bash npm i --save @capacitor-community/sqlite@latest npm i --save jeep-sqlite@latest +npm i --save-exact sql.js@1.11.0 ``` +`jeep-sqlite` 2.8.0 is built with `sql.js` 1.11.0. The `sql-wasm.wasm` file in your assets folder must come from that same version. `jeep-sqlite` pulls in the newest `sql.js`, so the file in `node_modules` can be too new. A file from version 1.13.0 or newer does not work. It fails with an error like `function import requires a callable`. + `jeep-sqlite` is a Stencil Component which is using `sql.js` for sql in-memory queries and store the database in the Browser on a `localforage` IndexedDB store named `jeepSqliteStore` and inside a table named `databases`. 🚨 The database is stored from in-memory to `localforage` IndexedDB store when one requires @@ -725,16 +728,14 @@ that is it. ```js ... -import { defineCustomElements as jeepSqlite, applyPolyfills } from "jeep-sqlite/loader"; +import { defineCustomElements as jeepSqlite } from "jeep-sqlite/loader"; import { Capacitor } from '@capacitor/core'; import { CapacitorSQLite, SQLiteConnection, SQLiteDBConnection } from '@capacitor-community/sqlite'; import { useState } from '@/composables/state'; ... -applyPolyfills().then(() => { - jeepSqlite(window); -}); +jeepSqlite(window); window.addEventListener('DOMContentLoaded', async () => { const platform = Capacitor.getPlatform(); @@ -1130,7 +1131,7 @@ that is it. ```ts ... -import { defineCustomElements as jeepSqlite, applyPolyfills, JSX as LocalJSX } from "jeep-sqlite/loader"; +import { defineCustomElements as jeepSqlite, JSX as LocalJSX } from "jeep-sqlite/loader"; import { HTMLAttributes } from 'react'; import { Capacitor } from '@capacitor/core'; import { CapacitorSQLite, SQLiteConnection, SQLiteDBConnection } from '@capacitor-community/sqlite'; @@ -1148,9 +1149,7 @@ declare global { } } -applyPolyfills().then(() => { - jeepSqlite(window); -}); +jeepSqlite(window); window.addEventListener('DOMContentLoaded', async () => { const platform = Capacitor.getPlatform();