libSQL · Doctrine DBAL · Turso

Doctrine DBAL, powered by libSQL.

A Doctrine DBAL 4 driver for libSQL/Turso built on the native PHP extension. Use familiar DBAL APIs for local files, remote Turso databases, embedded replicas, and offline-write workflows.

  • Doctrine DBAL 4
  • PHP 8.2+
  • Local/Remote/Replica
  • Offline writes
bootstrap.php
use Doctrine\DBAL\DriverManager;
use Turso\Doctrine\DBAL\Driver;

$conn = DriverManager::getConnection([
    'url' => 'database.sqlite',
    'driverClass' => Driver::class,
]);

$conn->executeStatement(
    'INSERT INTO users (name) VALUES (?)',
    ['Ada']
);
4Connection modes
DBAL 4Doctrine contract
v1.xLatest release
—GitHub stars

Why this driver

Standard DBAL, Turso-native transport.

Keep using Doctrine DBAL APIs while the driver handles libSQL connection modes, transactions, result iteration, and binary transport quirks.

Familiar DBAL API

Use executeStatement, executeQuery, transactions, schema tools, and parameter binding through Doctrine DBAL.

Multiple connection modes

Run in-memory, local file, remote Turso, or embedded replica mode. Enable offline writes for sqld or Turso Cloud flavors.

Proof-first behavior

Test suite and Docker proof harnesses verify real DBAL flows, migrations, transactions, and offline-write behavior.

Connection modes

Pick the right libSQL shape.

The driver selects a connection mode from url, sync_url, and auth options. You can move from local dev to remote or replica without changing your DBAL code style.

Memory

Fast ephemeral database for tests and local scripts. url: ':memory:'.

Local file

SQLite/libSQL file on disk. Use .db or .sqlite path.

Remote

Connect directly to Turso/libSQL over HTTP with sync_url and auth_token.

Embedded replica

Local file synced with remote primary. Supports sync_interval and read-your-writes.

sqld offline writes

Journal writes locally with sqld_offline_mode + offline_writes, then sync.

Turso Cloud offline writes

Journaled writes against Turso Cloud with offline_writes and embedded replica bootstrap sync.

Transactions

DBAL transactions map to libSQL transaction handles with read/write behavior inside tx.

Binary transport

Binary parameters round-trip through BlobCodec marker transport to avoid extension text-binding limits.

Install

Install package, load extension, connect.

Install the Composer package, enable the libSQL PHP extension, and pass Turso\Doctrine\DBAL\Driver as driverClass.

  1. 1

    Install Composer package

    Require tursodatabase/turso-doctrine-dbal in a PHP 8.2+ project with Doctrine DBAL 4.

  2. 2

    Install libSQL extension

    Install libsql_php from turso-client-php releases or Laravel installer, then verify with php -m | grep libsql.

  3. 3

    Configure DriverManager

    Use driverClass => Turso\Doctrine\DBAL\Driver::class and pick local, remote, replica, or offline-write params. See the user manual.

shell
$ composer require tursodatabase/turso-doctrine-dbal

# verify extension
$ php -m | grep libsql

# run tests in this repo
$ composer install && ./vendor/bin/phpunit

Need the full driver manual?

The user manual covers configuration, connection modes, DBAL usage, transactions, offline writes, verification harnesses, limitations, troubleshooting, and API reference.