Skip to main content
@capgo/capacitor-data-storage-sqlite Files & Storage Open source

Data Storage Capacitor plugin

Store data locally using SQLite database with simple key-value API and encryption support

Install

bun add @capgo/capacitor-data-storage-sqlite bunx cap sync
npm, pnpm or yarn
  • npm install @capgo/capacitor-data-storage-sqlite
  • pnpm add @capgo/capacitor-data-storage-sqlite
  • yarn add @capgo/capacitor-data-storage-sqlite

Guide

How to use Data Storage in Capacitor

Test on device

Download the Capgo app, then scan the QR code.

Data Storage plugin preview QR code

Using @capgo/capacitor-data-storage-sqlite

SQLite Storage of key/value strings pair.

Install

bun add @capgo/capacitor-data-storage-sqlite
bunx cap sync

bunx cap sync copies the plugin's native code into your native projects. Run it again after every plugin upgrade.

Import

import { CapgoCapacitorDataStorageSqlite } from '@capgo/capacitor-data-storage-sqlite';

API at a glance

Method Description
openStore Open a store.
closeStore Close the Store.
isStoreOpen Check if the Store is opened.
isStoreExists Check if the Store exists.
deleteStore Delete a store.
setTable Set or Add a table to an existing store.
set Store a data with given key and value.
get Retrieve a data value for a given data key.
remove Remove a data with given key.
clear Clear the Data Store (delete all keys).
iskey Check if a data key exists.
keys Get the data key list.
values Get the data value list.
filtervalues Get the data value list for filter keys.
keysvalues Get the data key/value pair list.
isTable Check if a table exists.
tables Get the table list for the current store.
deleteTable Delete a table.
importFromJson Import a database From a JSON.
isJsonValid Check the validity of a JSON Object.
exportToJson Export the given database to a JSON Object.
vacuum Rebuild the current SQLite store to reclaim unused disk space.

Examples

openStore()

Open a store.

import { CapgoCapacitorDataStorageSqlite } from '@capgo/capacitor-data-storage-sqlite';

await CapgoCapacitorDataStorageSqlite.openStore({
  database: 'database',
  table: 'table',
  encrypted: false,
  mode: 'encryption',
  autoVacuum: 'none',
});

closeStore()

Close the Store.

import { CapgoCapacitorDataStorageSqlite } from '@capgo/capacitor-data-storage-sqlite';

await CapgoCapacitorDataStorageSqlite.closeStore({ database: 'database' });

isStoreOpen()

Check if the Store is opened.

import { CapgoCapacitorDataStorageSqlite } from '@capgo/capacitor-data-storage-sqlite';

const result = await CapgoCapacitorDataStorageSqlite.isStoreOpen({ database: 'database' });
console.log(result);

isStoreExists()

Check if the Store exists.

import { CapgoCapacitorDataStorageSqlite } from '@capgo/capacitor-data-storage-sqlite';

const result = await CapgoCapacitorDataStorageSqlite.isStoreExists({ database: 'database' });
console.log(result);

deleteStore()

Delete a store.

import { CapgoCapacitorDataStorageSqlite } from '@capgo/capacitor-data-storage-sqlite';

await CapgoCapacitorDataStorageSqlite.deleteStore({
  database: 'database',
  table: 'table',
  encrypted: false,
  mode: 'encryption',
  autoVacuum: 'none',
});

setTable()

Set or Add a table to an existing store.

import { CapgoCapacitorDataStorageSqlite } from '@capgo/capacitor-data-storage-sqlite';

await CapgoCapacitorDataStorageSqlite.setTable({ table: 'table' });

The table above lists the 22 core methods. Listener and version helpers, and the full contract of each method, are documented in the GitHub repository.

Full reference

Keep going from Using @capgo/capacitor-data-storage-sqlite

If you are using Using @capgo/capacitor-data-storage-sqlite to plan storage and file handling, connect it with @capgo/capacitor-data-storage-sqlite for the implementation detail in @capgo/capacitor-data-storage-sqlite, Getting Started for the implementation detail in Getting Started, @capgo/capacitor-file for the implementation detail in @capgo/capacitor-file, Using @capgo/capacitor-file for the native capability in Using @capgo/capacitor-file, and @capgo/capacitor-uploader for the implementation detail in @capgo/capacitor-uploader.

FAQ

Data Storage plugin FAQ

How do I install the Data Storage plugin in a Capacitor app?

Run "bun add @capgo/capacitor-data-storage-sqlite" (or "npm install @capgo/capacitor-data-storage-sqlite"), then run "bunx cap sync" so the iOS and Android projects pick up the native code. Import it from "@capgo/capacitor-data-storage-sqlite" in your app code.

Does @capgo/capacitor-data-storage-sqlite work with React, Vue and Angular?

Yes. Data Storage is a Capacitor package, so it works with any web framework that runs inside Capacitor, including Ionic, React, Vue, Angular, Svelte and plain JavaScript.

Which Capacitor version does @capgo/capacitor-data-storage-sqlite support?

Capgo plugins follow Capacitor's major version: use the plugin major version that matches your Capacitor major version (for example plugin v8 with Capacitor 8). The compatibility table in the GitHub README lists the maintained versions.

Is @capgo/capacitor-data-storage-sqlite free and open source?

Yes. The source code is public on GitHub at https://github.com/Cap-go/capacitor-data-storage-sqlite/ and the package is free to install from npm. Bug reports and pull requests are welcome.

Can I update code that uses Data Storage without an App Store review?

Installing or upgrading the plugin changes native code, so it needs a new store build. After that, JavaScript, HTML and CSS changes that call the plugin can ship instantly with Capgo live updates.

Ship Data Storage changes without waiting for app review

Once the plugin is in your store build, Capgo live updates push your JavaScript, HTML and CSS changes to users in minutes.

Start with Capgo