---
title: Key-Value Storage Made Simple with the SQLite Plugin
description: Learn how to use SqliteKeyValueStore for simple, reliable key-value storage in your Capacitor apps without writing a single SQL query.
date:
  created: 2026-02-13
  updated: 2026-07-14
authors:
  - robingenz
categories:
  - Capacitor
  - Guides
  - SDKs
links:
  - Capacitor SQLite: sdks/capacitor/sqlite.md
faq: true
---

# Key-Value Storage Made Simple with the SQLite Plugin

Storing simple key-value data in Ionic and Capacitor apps often means choosing between unreliable browser storage or writing boilerplate SQL. The [Capacitor SQLite plugin](../../sdks/capacitor/sqlite.md) now includes `SqliteKeyValueStore` — a built-in class that gives you a familiar `get`/`set` API backed by a real SQLite database. No SQL queries, no schema setup, no risk of data loss from WebView storage clearing. In this guide, you'll learn how to use `SqliteKeyValueStore` in your Capacitor apps and when to choose it over the [Capacitor Secure Preferences plugin](../../sdks/capacitor/secure-preferences.md). And if your data grows past simple key-value pairs into tables, queries, or migrations, [How to Use SQLite in a Capacitor App](./how-to-use-sqlite-in-a-capacitor-app.md) covers the full database API.

No SQL, no schema; when you need more, use the same **Capacitor SQLite plugin** and the full [plugin documentation](../../sdks/capacitor/sqlite.md#key-value-store).

<!-- more -->

<div class="capawesome-z29o10a">
  <a href="/" target="_blank">
    <img alt="Build and deploy your Capacitor app with Capawesome Cloud" src="https://capawesome.io/assets/banners/cloud-build-and-deploy-capacitor-apps.png?t=1" />
  </a>
</div>

## What is `SqliteKeyValueStore`?

`SqliteKeyValueStore` is a built-in class shipped with the [Capacitor SQLite plugin](../../sdks/capacitor/sqlite.md) that wraps a SQLite database behind a minimal key-value API. The database is automatically created and managed under the hood — you don't need to define schemas, write migrations, or execute any SQL. Values are stored as strings, so you can use `JSON.stringify` and `JSON.parse` to work with objects.

Here's what makes it a great choice for your next project:

- **Reliable persistence** — Data lives in a SQLite database file, not in WebView storage that the OS can clear at any time.
- **No SQL required** — A simple `get`/`set` interface. No schemas, no migrations, no queries.
- **Cross-platform** — Works on Android, iOS, Web, and [Electron](./announcing-the-capacitor-electron-platform.md) with a single API.
- **Performance** — SQLite is optimized for fast reads and writes, even with larger data sets.
- **Scales with your app** — Start with key-value storage today, graduate to full SQL queries later using the same plugin — no migration needed.

For more details on the available methods, check out the [Key-Value Store](../../sdks/capacitor/sqlite.md#key-value-store) section in the plugin documentation.

## SQLite Key Value Store vs. Secure Preferences

If you're already familiar with the [Capacitor Secure Preferences plugin](../../sdks/capacitor/secure-preferences.md), you might be wondering when to use which. Both provide key-value storage, but they're designed for different use cases:

|                                 | SQLite Key Value Store                  | Secure Preferences                        |
| ------------------------------- | --------------------------------------- | ----------------------------------------- |
| **Best for**                    | App settings, caching, larger data sets | Sensitive data (tokens, keys, secrets)    |
| **Encryption**                  | Optional (requires SQLCipher setup)     | Built-in, uses platform keychain/keystore |
| **Third-party dependency**      | SQLCipher (only if encryption needed)   | None                                      |
| **Performance with large data** | Optimized (SQLite engine)               | Designed for small values                 |
| **SQL upgrade path**            | Yes, same plugin                        | No                                        |

Use [Capacitor Secure Preferences plugin](../../sdks/capacitor/secure-preferences.md) for sensitive credentials that need encryption by default with zero setup. Use [SQLite Key Value Store](../../sdks/capacitor/sqlite.md#key-value-store) when you need reliable persistence for larger data sets with SQLite-level performance and an optional upgrade path to full SQL.

## Getting Started

To get started with `SqliteKeyValueStore`, you first need to install the [Capacitor SQLite plugin](../../sdks/capacitor/sqlite.md). Please refer to the [Installation](../../sdks/capacitor/sqlite.md/#installation) section in the plugin documentation.

## Usage

Once the plugin is installed, you can start using `SqliteKeyValueStore` right away. Let's walk through the most common operations.

### Storing Data

First, create a `SqliteKeyValueStore` instance. Then use [`set(...)`](../../sdks/capacitor/sqlite.md#set) to store simple strings or JSON-serialized objects:

```typescript
import { Sqlite, SqliteKeyValueStore } from '@capawesome-team/capacitor-sqlite';

const store = new SqliteKeyValueStore(Sqlite);

// Store a simple string value
await store.set({ key: 'language', value: 'en' });

// Store an object as a JSON string
const preferences = { theme: 'dark', fontSize: 16, notifications: true };
await store.set({ key: 'preferences', value: JSON.stringify(preferences) });
```

### Retrieving Data

Use [`get(...)`](../../sdks/capacitor/sqlite.md#get) to read a value by its key. The returned `value` is `null` if the key doesn't exist, so always check before parsing:

```typescript
const { value } = await store.get({ key: 'preferences' });
if (value) {
  const preferences = JSON.parse(value);
  console.log(preferences.theme); // 'dark'
}
```

### Removing Data

Use `remove(...)` to delete a single key or `clear()` to wipe all stored data:

```typescript
await store.remove({ key: 'language' });

await store.clear();
```

### Listing All Keys

Use `keys()` to get a list of all stored keys:

```typescript
const { keys } = await store.keys();
console.log(keys); // ['preferences', 'onboardingComplete', ...]
```

## Use Cases

Here are some common scenarios where `SqliteKeyValueStore` is a great fit:

- **User preferences** — Theme, language, font size, or notification settings. Data persists reliably across app restarts without worrying about WebView storage limits.
- **Feature flags and onboarding state** — Track which features are enabled or whether the user has completed onboarding. Simple boolean or string values that need to survive app updates.
- **Lightweight caching** — Cache API responses or computed results as JSON strings. SQLite performance keeps reads fast even as your cache grows.

## FAQ

### Do I need to write SQL to use `SqliteKeyValueStore`?

No. `SqliteKeyValueStore` wraps the [Capacitor SQLite plugin](../../sdks/capacitor/sqlite.md) with a simple `set` / `get` / `remove` API, so you get SQLite's reliability and performance without writing a single query. If your needs grow, you can drop down to full SQL with the same plugin.

### When should I use this instead of Secure Preferences?

Use `SqliteKeyValueStore` for app settings, caching, and larger data sets where you want SQLite-level performance and an upgrade path to full SQL. Use the [Capacitor Secure Preferences plugin](../../sdks/capacitor/secure-preferences.md) for sensitive values like tokens and keys, which need encryption by default with zero setup. See [SQLite Key Value Store vs. Secure Preferences](#sqlite-key-value-store-vs-secure-preferences) for a side-by-side comparison.

### Which platforms does it support?

It runs on Android, iOS, Web, and [Electron](./announcing-the-capacitor-electron-platform.md) with a single API, since it's part of the Capacitor SQLite plugin.

### Can I encrypt the stored values?

Yes, optionally. The underlying SQLite database supports encryption via SQLCipher when you need it. If encryption is your primary requirement, though, the Secure Preferences plugin provides it out of the box without extra setup.

## Conclusion

`SqliteKeyValueStore` gives you reliable, performant key-value storage with zero SQL boilerplate — and a clear path to full SQL when your app needs it. If you're looking for a simple yet robust way to persist data in your Capacitor app, give it a try.

**Resources:** 
- [Plugin docs](../../sdks/capacitor/sqlite.md)
- [Key-Value Store API](../../sdks/capacitor/sqlite.md#key-value-store)

**Related guides:**

- For raw API usage [Exploring the Capacitor SQLite API](./exploring-the-capacitor-sqlite-api.md)
- [Encrypting SQLite databases](./encrypting-capacitor-sqlite-database.md)
- ORMs: [TypeORM](./how-to-use-typeorm-with-capacitor-and-sqlite.md), [Drizzle ORM](./how-to-use-drizzle-orm-with-capacitor-and-sqlite.md), [Kysely](./how-to-use-kysely-with-capacitor-and-sqlite.md)

If you have any questions or need help, join the [Capawesome Discord server](https://discord.gg/VCXxSVjefW){:target="_blank"} to connect with the community. To stay updated with the latest news about Capawesome, Capacitor, and the Ionic ecosystem, subscribe to the [Capawesome newsletter](/newsletter/){:target="_blank"}.
