Skip to content

Alternative to the Capacitor Community SQLite plugin

Looking for a robust SQLite solution for your Capacitor app? While the Capacitor Community SQLite plugin has been a popular choice for many developers, there's now a compelling alternative that addresses common pain points and provides enhanced features. The Capawesome SQLite plugin offers a modern, enterprise-grade SQLite solution with improved security, performance, and developer experience.

Introduction

SQLite databases are a cornerstone of many mobile and web applications, providing a lightweight and efficient way to store structured data. The Capacitor Community SQLite plugin has been widely used in the Capacitor ecosystem, but it comes with certain limitations that can impact application performance, security, and compliance. The Capawesome SQLite plugin emerges as a modern solution designed specifically for enterprise-grade applications, offering a range of features that enhance data management capabilities while addressing the shortcomings of the Capacitor Community SQLite plugin.

Why consider alternatives?

First, let's take a look at some of the drawbacks of the Capacitor Community SQLite plugin that have led to the development of the Capawesome SQLite plugin.

Encryption Export Regulations

When you submit your app to app stores, you upload your app to servers in specific countries (e.g., the US). If your app uses encryption, you may need to comply with export regulations that require you to declare the type of encryption used. The Capacitor Community SQLite plugin uses the SQLCipher library, which is subject to these regulations. The problem here is that the Capacitor Community SQLite plugin uses the SQLCipher library even if you do not use the encryption features, which means you have to declare the use of encryption in your app as soon as you use the plugin.

Disclaimer

We aren’t attorneys or export control experts. This information is not intended as legal advice. Use it at your own risk and consult with a legal expert if you have concerns about compliance.

Performance

The Capacitor Community SQLite plugin has been known to have performance issues, especially with larger databases or complex queries. These performance bottlenecks become particularly noticeable in applications that require real-time data synchronization or handle frequent concurrent database operations.

Swift Package Manager

Modern iOS development increasingly relies on Swift Package Manager (SPM) for dependency management. Unfortunately, the Capacitor Community SQLite plugin does not support SPM, which can complicate integration with other Swift-based libraries and frameworks. This limitation becomes especially problematic for teams working with modern iOS frameworks that have moved away from CocoaPods in favor of SPM's more streamlined approach.

Web Support

There are different approaches to SQLite support in web applications. The most modern approach is to use WebAssembly (Wasm) to run SQLite in the browser and store the database in the Origin Private File System (OPFS) of the browser. This approach is also the only one that is officially associated with the SQLite project. However, the Capacitor Community SQLite plugin does not support this approach and instead uses sql.js and localforage to store the database in IndexedDB. This complicates the setup, creates additional dependencies, and can lead to performance issues compared to the official approach.

Maintenance and Support

The Capacitor Community SQLite plugin is maintained by the community, which allows the plugin to be free and open-source but can lead to slower updates and less reliable support. While this is not a problem for many developers, those building enterprise applications may require more robust support and maintenance options.

Differences to the Capacitor SQLite plugin

The Capawesome SQLite plugin offers several key advantages over the Capacitor Community alternative:

  • Simplified API: More intuitive and streamlined API for database operations, making it easier to implement complex data management features.
  • Optional Encryption: Encryption is optional and only enabled when needed, avoiding unnecessary compliance burdens.
  • WebAssembly Support: Native WebAssembly support for web applications, providing better performance and functionality.
  • Swift Package Manager Support: Full support for SPM, making it easier to integrate with modern iOS projects.
  • Enhanced Performance: Optimized for larger databases and complex queries, ensuring smooth performance even under heavy loads.
  • Professional Support: Direct support from the Capawesome team for all Capawesome Insiders, ensuring timely updates and assistance.

Migration from Capacitor Community SQLite plugin

Migrating from the Capacitor Community SQLite plugin to the Capawesome SQLite plugin involves updating your installation, adapting your database opening logic, and adjusting your SQL execution patterns.

Installation

First, remove the existing plugin and install the Capawesome alternative. To install the Capawesome SQLite plugin, please refer to the Installation section in the plugin documentation.

Opening a database

The database opening process differs between the two plugins. Here's how to migrate your database opening logic:

Capacitor Community SQLite plugin:

import { CapacitorSQLite, SQLiteConnection } from '@capacitor-community/sqlite';

const open = async () => {
  await CapacitorSQLite.addUpgradeStatement({
    database: 'db',
    upgrade: [
      {
        toVersion: 1,
        statements: [
          'CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, age INTEGER)'
        ]
      }
    ]
  });
  await CapacitorSQLite.open({
    database: 'db',
    readonly: false,
  });
};

Capawesome SQLite plugin:

import { Sqlite } from '@capawesome-team/capacitor-sqlite';

const open = async () => {
  const { databaseId } = await Sqlite.open({
    readOnly: false,
    path: 'db.sqlite3',
    upgradeStatements: [
      {
        version: 1,
        statements: [
          'CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, age INTEGER)'
        ]
      }
    ]
  });
};

Executing SQL statements

SQL execution syntax is simplified in the Capawesome SQLite plugin:

Capacitor Community SQLite plugin:

import { CapacitorSQLite } from '@capacitor-community/sqlite';

const execute = async (databaseName: string) => {
  await CapacitorSQLite.run({
    database: databaseName,
    statement: 'INSERT INTO users (name, age) VALUES (?, ?);',
    values: ['John Doe', 30]
  });
};

Capawesome SQLite plugin:

import { Sqlite } from '@capawesome-team/capacitor-sqlite';

const execute = async (databaseId: string) => {
  await Sqlite.execute({
    databaseId,
    statement: 'INSERT INTO users (name, age) VALUES (?, ?);',
    values: ['John Doe', 30]
  });
};

Querying data

Data querying follows a similar simplification pattern:

Capacitor Community SQLite plugin:

import { CapacitorSQLite } from '@capacitor-community/sqlite';

const query = async (databaseName: string) => {
  const result = await CapacitorSQLite.query({
    database: databaseName,
    statement: 'SELECT * FROM users WHERE age > ?;',
    values: [25]
  });
  console.log(result.values);
};

Capawesome SQLite plugin:

import { Sqlite } from '@capawesome-team/capacitor-sqlite';

const query = async (databaseId: string) => {
  const result = await Sqlite.query({
    databaseId,
    statement: 'SELECT * FROM users WHERE age > ?;',
    values: [25]
  });
  console.log(result.values);
};

FAQ

Can I open already existing databases with the Capawesome SQLite plugin?

Yes, you can open existing databases (e.g., created with the Capacitor Community SQLite plugin) using the Capawesome SQLite plugin. Just provide the path to the existing database file when calling the open(...) method. If the database file does not exist, it will be created automatically.

Does the Capawesome SQLite plugin provide the same functionality as the Capacitor Community SQLite plugin?

Yes, at least in terms of core functionality. The Capacitor Community SQLite plugin offers a number of advanced features such as biometrics and encryption key management. However, these features are not required by most applications, so the Capawesome team has decided to move these features to separate plugins (e.g. Capacitor Biometrics and Capacitor Secure Preferences). This allows you to use the Capawesome SQLite plugin without the overhead of these features if you don't need them.

Conclusion

The Capawesome SQLite plugin provides a modern, robust alternative to the Capacitor Community SQLite plugin, addressing key issues such as encryption compliance, performance, and developer experience. By migrating to this plugin, you can enhance your application's data management capabilities while ensuring compliance with export regulations and modern development practices.

To stay updated with the latest updates, features, and news about the Capawesome, Capacitor, and Ionic ecosystem, subscribe to the Capawesome newsletter and follow us on X (formerly Twitter).

If you have any questions or need assistance with the Capacitor SQLite Plugin, feel free to reach out to the Capawesome team. We're here to help you implement powerful data management features in your Ionic applications.