@capacitor-community/sqlite

Community plugin for native & electron SQLite databases

Usage no npm install needed!

<script type="module">
  import capacitorCommunitySqlite from 'https://cdn.skypack.dev/@capacitor-community/sqlite';
</script>

README


SQLITE DATABASE

@capacitor-community/sqlite


CAPACITOR 3


Capacitor community plugin for Native and Electron SQLite Databases. In Native databases could be encrypted with SQLCipher



Maintainers

Maintainer GitHub Social
Quéau Jean Pierre jepiqueau

CAPACITOR 3 (Master)

🚨 Since release 3.4.0-2 ->> 🚨

  • iOS & Android only Adding biometric FaceID/TouchID to secure the pass phrase in the Keychain/SharedPreferences stores. see: Biometric_Authentication

  • iOS only Fix identical pass phrase stored in the Keychain for differents applications using the plugin by adding an application prefix to the Keychain account. Before the account "CapacitorSQLitePlugin" was used and was the same for all applications. Now by adding iosKeychainPrefix: 'YOUR_APP_NAME'in the capacitor.config.ts of your application, the account will be "YOUR_APP_NAME_CapacitorSQLitePlugin" If you were having a pass phrase stored, first modify the capacitor.config.ts and then run the command isSecretStored which will manage the upgrade of the Keychain account. 🚨 Since release 3.4.0-2 <<- 🚨

🚨 Since release 3.3.3-2 ->> 🚨

  • iOS only Support for a database location not visible to iTunes and backed up to iCloud. For this you must add to the const config: CapacitorConfig of the capacitor.config.ts file of your application the following:
      plugins: {
        CapacitorSQLite: {
          "iosDatabaseLocation": "Library/CapacitorDatabase"
        }
      }
    
    Pre-existing databases from the Documents folder will be moved to the new folder Library/CapacitorDatabase and your application will work as before. If you do not modify the capacitor.config.ts file of your application the databases will still reside in the Documents folder

🚨 Since release 3.3.3-2 <<- 🚨

🚨 Since release 3.2.5-2 ->> 🚨

  • support zip file in copyFromAssets method
  • add optional overwrite parameter (true/false) default to true

🚨 Since release 3.2.5-2 <<- 🚨

🚨 Since release 3.2.3-1 ->> 🚨

The initWebStore and saveToStore methods have been added to the Web platform.

  • The initWebStore has been added to fix the issue#172 and since then is MANDATORY
...
if(platform === "web") {
  await customElements.whenDefined('jeep-sqlite');
  const jeepSqliteEl = document.querySelector('jeep-sqlite');
  if(jeepSqliteEl != null) {
    await sqliteConnection.initWebStore()
    ...
  }
}
...
  • the saveToStore allows to perform intermediate save of the database in case the browser needs to delete the cache.

🚨 Since release 3.2.3-1 <<- 🚨

The test has been achieved on:

Browser Support

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.

Installation

npm install @capacitor-community/sqlite
npm run build
npx cap add android
npx cap add ios
npx cap add @capacitor-community/electron

and do when you update

npx cap sync
npx cap sync @capacitor-community/electron

Web

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

For Vue & React frameworks

  • copy manually the file sql-wasm.wasm from node_modules/sql.js/dist/sql-wasm.wasm to the public/assets folder of YOUR_APP

IOS

  • on iOS, no further steps needed.

Android

  • On Android, no further steps needed.

Electron

  • On Electron, go to the Electron folder of YOUR_APPLICATION
cd electron
npm install --save sqlite3
npm install --save jszip
npm install --save-dev @types/sqlite3
npm run build

Build & Run

npm run build
npx cap copy
npx cap copy web
npx cap copy @capacitor-community/electron

Web

  • Angular
ionic serve
  • Vue
npm run serve
  • React
npm run start

IOS

npx cap open ios

Android

npx cap open android

Electron

npx cap open @capacitor-community/electron

Readme previous releases

previous releases

Issues

issues

Configuration

No configuration required for this plugin

Supported methods

Name Android iOS Electron Web
createConnection
closeConnection
isConnection
open (non-encrypted DB)
open (encrypted DB)
close
getUrl
getVersion
execute
executeSet
run
query
deleteDatabase
importFromJson
exportToJson
createSyncTable
setSyncDate
getSyncDate
isJsonValid
isDBExists
addUpgradeStatement
copyFromAssets
isDBOpen
isDatabase
isTableExists
getDatabaseList
getMigratableDbList
addSQLiteSuffix
deleteOldDatabases
checkConnectionsConsistency
isSecretStored
setEncryptionSecret
changeEncryptionSecret
initWebStore
saveToStore
getNCDatabasePath
createNCConnection
closeNCConnection
isNCDatabase

Supported SQLite Types

-Datatypes In SQLite Version 3

Documentation

API

Framework's Usage

Applications demonstrating the use of the plugin

Ionic/Angular

Ionic/React

React+Vite

Ionic/Vue

Vue

Vue+Vite

Usage

Dependencies

The iOS and Android codes are using SQLCipher allowing for database encryption. The iOS codes is using ZIPFoundation for unzipping assets files The Electron code is using sqlite3. The Web code is using the Stencil component jeep-sqlite based on sql.js, localforage. and jszip

Contributors ✨

Thanks goes to these wonderful people (emoji key):


Jean Pierre Quéau

💻

Paul Antoine

💻

Karyfars

💻

Chriswep

📖

Nirajhinge

💻

Dirk Gausmann

💻

Mike Summerfeldt

💻

Peakcool

💻

Gion-Andri Cantieni

📖

Robin Genz

📖

Dewald Els

💻

Joe Woodhouse

📖

Ptasheq

📖

This project follows the all-contributors specification. Contributions of any kind welcome!