Skip to main content
The libSQL package for Flutter / Dart contains everything you need to work with Turso / libSQL and works flawlessly with all features, because it’s build on top libSQL Rust crate and flutter_rust_bridge package, allowing for seamless communication between Rust and Dart.

Add the package to your project

Alternatively, manually add it to your project’s pubspec.yaml

Initializing

Call LibsqlClient constructor to create the database client. Different configurations are supported, allowing connection to in-memory database, local sqlite file, remote Turso / libSQL database, or embedded replica.

In-Memory Databases

libSQL supports connecting to in-memory databases for cases where you don’t require persistence:

Local Development

You can work locally using an SQLite file and passing the path to LibsqlClient:

Remote

You can work with remote database by passing your Turso Database URL:

Embedded Replicas

You can work with embedded replicas by passing your Turso Database URL to syncUrl:
Embedded Replicas only works where you have access to the file system.

Connect

Manual Sync

The sync() function allows you to sync manually the local database with the remote counterpart:

Periodic Sync

You can automatically sync at intervals by configuring the syncIntervalSeconds property when instantiating the client:

Encryption at rest

To enable encryption on a SQLite file, pass the encryptionKey:
Encrypted databases appear as raw data and cannot be read as standard SQLite databases. You must use the libSQL client for any operations — learn more.

Execute

Returns number of rows affected:

Query

Returns rows as List<Map<String, dynamic>>. Will returns empty list when is not performing select query:

Placeholders

libSQL supports the use of positional and named placeholders within SQL statements:

libSQL supports the same named placeholder characters as SQLite — :, @ and $.

Batch Transactions

A batch consists of multiple SQL statements executed sequentially within an implicit transaction. The backend handles the transaction: success commits all changes, while any failure results in a full rollback with no modifications.

Transaction Modes

Interactive Transactions

Interactive transactions in SQLite ensure the consistency of a series of read and write operations within a transaction’s scope. These transactions give you control over when to commit or roll back changes, isolating them from other client activity.

Interactive transactions in libSQL lock the database for writing until committed or rolled back, with a 5-second timeout. They can impact performance on high-latency or busy databases.

ATTACH

You can attach multiple databases to the current connection using the ATTACH attachment:
Make sure to allow ATTACH and create a token with the permission to attach a database — learn more