Skip to content

krasamo/sqlite

 
 


SQLITE DATABASE

@capacitor-community/sqlite


REFACTOR 🚀


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




@NEXT FOR CAPACITOR 3 🚧 (Master)

The refactor release has been upgraded to @capacitor/core@3.0.0-beta.1. !!! ONLY iOS and Android plugins have been upgraded !!!

To install it

npm i --save @capacitor-community/sqlite@next

This release provide a better Error handling through try...catch.

The test has been achieved on:


@LATEST REFACTOR 🚀 (Move to branch 2.9.x)

A refactoring has been started more than a month ago to reach the following objectives:

  • multiple database connections
  • db connector allowing for easy commands db.open(), db.close, ...
  • improve the response time of the encrypted database by removing the internal open and close database for each sqlite query
  • moving to the latest androidx.sqlite.db.xxx
  • offering encryption for Electron MacOs platform by using @journeyapps/sqlcipher. !!! NOT WORKING for Electron Windows platform !!!
  • cleaning and aligning the code between platforms
  • allowing developers to develop easily typeorm or spatialite drivers.

This was discussed lengthly in issue#1 and issue#52

It is now available in a stable release 2.9.x for all platforms (Android, iOS & Electron).

Developers are encouraged to start converting their applications. The interface to the plugin is now achieved through the use of connection wrappers

As you will see it is a Majorchange and the release is now the basis of 3.0.0-beta based on capacitor@3.0.0.

The test has been achieved on:

Other frameworks will be tested later

  • Stencil

When you will find issues, please report them with the REFACTOR word at the start of the issue title.

To install it

npm i --save @capacitor-community/sqlite@latest

Hope you will enjoy it.


@INITIAL 🛑 (Move to branch 2.4.x)

The 2.4.x is now NOT MAINTAINED ANYMORE.

To install it

npm i --save @capacitor-community/sqlite@initial

Maintainers

Maintainer GitHub Social
Quéau Jean Pierre jepiqueau

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@latest
npm run build
npx cap add android
npx cap add ios
npx cap add @capacitor-community/electron

IOS

  • on iOS no further steps needed.

Android

  • On Android, register the plugin in your main activity:
import com.getcapacitor.community.database.sqlite.CapacitorSQLite;

public class MainActivity extends BridgeActivity {

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Initializes the Bridge
    this.init(
        savedInstanceState,
        new ArrayList<Class<? extends Plugin>>() {
          {
            // Additional plugins you've installed go here
            // Ex: add(TotallyAwesomePlugin.class);
            add(CapacitorSQLite.class);
          }
        }
      );
  }
}

Electron

  • On Electron, go to the Electron folder of YOUR_APPLICATION
npm install --save @journeyapps/sqlcipher

Build & Run

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

IOS

npx cap open ios

Android

npx cap open android

Electron

npx cap open @capacitor-community/electron

Issues

When you will find issues, please report them with the REFACTOR word at the start of the issue title.

issues

Configuration

No configuration required for this plugin

Supported methods

Name Android iOS Electron Mac Electron Windows Web
createConnection
closeConnection
open (non-encrypted DB)
open (encrypted DB)
close
execute
executeSet
run
query
deleteDatabase
importFromJson
exportToJson
createSyncTable
setSyncDate
getSyncDate
isJsonValid
isDBExists
addUpgradeStatement
copyFromAssets
isDBOpen
isDatabase
isTableExists
getDatabaseList
addSQLiteSuffix
deleteOldDatabases

Documentation

API_Documentation

API_Connection_Wrapper_Documentation

API_DB_Connection_Wrapper_Documentation

ImportExportJson_Documentation

UpgradeDatabaseVersion_Documentation

MigratingCordovaDatabases_Documentation

Ionic/Angular_Usage_Documentation

Ionic/React_Usage_Documentation

Ionic/Vue_Usage_Documentation

Applications demonstrating the use of the plugin

Ionic/Angular

Ionic/React

Ionic/Vue

Vue (to come later)

Usage

Dependencies

The IOS and Android codes are using SQLCipher allowing for database encryption The Electron code use @journeyapps/sqlcipher allowing for database encryption for MacOS !!! NOT for Windows !!!

Contributors ✨

Thanks goes to these wonderful people (emoji key):


Jean Pierre Quéau

💻

Paul Antoine

💻

Karyfars

💻

Chriswep

📖

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

About

Community plugin for native & electron SQLite databases

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages

  • Swift 40.1%
  • Java 34.0%
  • TypeScript 25.1%
  • Other 0.8%