SQLITE AS AN IN-APP DATABASE

SQLite Resources

Resources for implementing SQLite as an in-app database for mobile, desktop or browser-based apps.
RECOMMENDED SQLITE LIBRARY
wa-sqlite

wa-sqlite leverages WebAssembly (Wasm), allowing SQLite to run efficiently in web browser environments. The Wasm build is highly customizable by providing access to compiler options and having a good set of default options, however, it does not enable extension loading by default.

This Wasm build of SQLite supports writing to SQLite virtual file systems (VFS) completely in JavaScript and allows for alternative browser storage options such as IndexedDB and Origin Private File System (OPFS). Both the synchronous and asynchronous builds use the same set of default options and provide a consistent way to access the SQLite C API through JavaScript wrappers.

It does not provide an easy-to-use transaction API. It requires manual setup for concurrent read transactions. It does not include any update or commit hooks. Both builds allow the use of SQL queries directly, and support the use of prepared statements.

CRITERIA

Evaluating Client-Side SQLite Libraries

We've evaluated available SQLite libraries based on three criteria:

Configurability
Consistency
Capability
Helpful article
Local-First Software is a Big Deal, Especially for the Web
  • Zero-latency apps using in-browser SQLite

  • Simplified DX with reduced backend and APIs

  • In-browser SQLite will gain more adoption

Read the article
Helpful article
SQLite Optimizations for High-Performance
  • Expected baseline performance/throughput

  • 10 key performance optimizations to consider

  • Performance optimizations included in our sqlite_async library

Read the article
Helpful article
Local-First State Management with SQLite
  • Using a SQLite database to manage state

  • Example to-do list app

  • Link to video talk on this topic

Read the article
RECOMMENDED SQLITE LIBRARY
op-sqlite

op-sqlite provides a low-level API for executing SQL queries within React Native. It provides access to compiler options configurable through the package.json file and caters for loading additional extensions.

It provides a consistent set of options across compatible platforms and direct access to the SQLite C API through JavaScript. It provides a comprehensive transaction API, exposes multiple parameter types and includes update hooks for various operations such as table or row updates. It also has support for prepared statements out of the box.

While it does not have the niceties of an ORM, it has a smaller footprint resulting in a smaller app size and better performance.

CRITERIA

Evaluating Client-Side SQLite Libraries

We've evaluated available SQLite libraries based on three criteria:

Configurability
Consistency
Capability
Helpful article
React Native support
React Native Database Performance Comparison
  • Compares performance on iOS and Android

  • Uses standard benchmark tests

  • Tests effect of using transactions and batching queries

Read the article
Helpful article
SQLite Optimizations for High-Performance
  • Expected baseline performance/throughput

  • 10 key performance optimizations to consider

  • Performance optimizations included in our sqlite_async library

Read the article
Helpful article
Local-First State Management with SQLite
  • Using a SQLite database to manage state

  • Example to-do list app

  • Link to video talk on this topic

Read the article
RECOMMENDED SQLITE LIBRARY
sqlite_async

We recommend sqlite_async because it wraps the sqlite3 Dart bindings and configures the database with a good set of defaults, with all database calls being asynchronous to avoid blocking the UI.

While it does not expose compiler options, it does cater for loading various extensions. It also ensures that core SQLite functionality is consistent across all platforms supported by the library.

For performance-sensitive tasks, transactions are asynchronous and concurrent by default (multiple read and single write) by using a pool of connections, each running in a separate Isolate. Allows the use of SQL queries directly, making complex queries easier, and does not require any code generation. Allows access to the underlying SQLite3 library when high-performance low-level access is required. Allows the use of Drift when an ORM is required.

CRITERIA

Evaluating Client-Side SQLite Libraries

We've evaluated available SQLite libraries based on three criteria:

Configurability
Consistency
Capability
Helpful article
Flutter Database Comparison
  • Background on performance benchmarking methodology used

  • Performance comparison of sqlite_async, sqflite, Isar and ObjectBox

  • Link to GitHub project with performance benchmarking code

Read the article
Helpful article
SQLite Optimizations for High-Performance
  • Expected baseline performance/throughput

  • 10 key performance optimizations to consider

  • Performance optimizations included in our sqlite_async library

Read the article
Helpful article
Local-First State Management with SQLite
  • Using a SQLite database to manage state

  • Example to-do list app

  • Link to video talk on this topic

Read the article
RECOMMENDED SQLITE LIBRARY
SQLDelight

SQLDelight is one the few SQLite drivers that supports Kotlin Multiplatform and is used in almost all KMP samples and showcase apps. It does not expose many compiler options but does however include some good defaults that make extension loading possible. The library shows consistent performance across various platforms when compiling for KMP. It does not allow direct access to the SQLite C API which is provided by the SQLiter library under the hood. SQDelight does however have a rich SQLite API which generates type-safe Kotlin APIs from SQL which makes writing and maintaining SQL statements much easier. It does support querying the database asynchronously and allows the database to be configured for concurrent read transactions (using WAL mode).

CRITERIA

Evaluating Client-Side SQLite Libraries

We've evaluated available SQLite libraries based on three criteria:

Configurability
Consistency
Capability
Helpful article
SQLite Optimizations for High-Performance
  • Expected baseline performance/throughput

  • 10 key performance optimizations to consider

  • Performance optimizations included in our sqlite_async library

Read the article
Helpful article
Local-First State Management with SQLite
  • Using a SQLite database to manage state

  • Example to-do list app

  • Link to video talk on this topic

Read the article
SQL DATABASE ENGINE

For An In-App Database, Just Use SQLite

SQLite is small, reliable and fast. It provides exceptional performance, wide flexibility and supports advanced functionality such as aggregations, joins, advanced indexing and JSON. All this makes SQLite ideal as an embedded in-app database: one that is directly co-located with your application.

SQLite is the most widely-deployed database in the world. Popular apps using SQLite as an in-app database include messaging apps such as WhatsApp (1), Signal (2) and Skype, native bundled apps on iOS and Android, internal apps on operating systems such as Windows and macOS, and many more.
SQLite SQL database engine
SYNC ENGINE

Add Sync for Multi-Device Access, Backup & Real-Time Collaboration

Syncing the data in an in-app SQLite database with a remote database is a common need for developers.

This can be accomplished with a sync engine such as PowerSync.

PowerSync’s open-source client SDKs bundle the recommended client-side SQLite libraries featured on this page. PowerSync also provides the needed server-side component for high-performance syncing (PowerSync Service), which is source-available and can be self-hosted.
Learn more
PowerSync Sync Engine SQLite in-app database
WHEN TO USE SYNC
Data Backup

Avoid data loss with automatic data backup to a backend database.

WHEN TO USE SYNC
Multi-Device Access

Allow users to access data from any device running your app.

WHEN TO USE SYNC
Real-Time Streaming

Automatically update local SQLite with fresh data.

WHEN TO USE SYNC
Collaboration

Allow users to share data with other users and collaborate live.