PHPackages                             richan-fongdasen/turso-laravel - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. richan-fongdasen/turso-laravel

ActiveLibrary[Database &amp; ORM](/categories/database)

richan-fongdasen/turso-laravel
==============================

A Turso/LibSQL database driver for Laravel

1.0.0(1y ago)1085.3k↑27.3%6[1 issues](https://github.com/richan-fongdasen/turso-laravel/issues)[5 PRs](https://github.com/richan-fongdasen/turso-laravel/pulls)MITPHPPHP ^8.2CI passing

Since Apr 11Pushed 2mo ago2 watchersCompare

[ Source](https://github.com/richan-fongdasen/turso-laravel)[ Packagist](https://packagist.org/packages/richan-fongdasen/turso-laravel)[ Docs](https://github.com/richan-fongdasen/turso-laravel)[ GitHub Sponsors](https://github.com/richan-fongdasen)[ RSS](/packages/richan-fongdasen-turso-laravel/feed)WikiDiscussions main Synced 3w ago

READMEChangelog (9)Dependencies (20)Versions (15)Used By (0)

A Turso database driver for Laravel
===================================

[](#a-turso-database-driver-for-laravel)

[![Latest Version on Packagist](https://camo.githubusercontent.com/2635dbf1c861d00887eab7ef2ec370cfe647f91e8b64455eef115bf0538b4e05/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f72696368616e2d666f6e67646173656e2f747572736f2d6c61726176656c2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/richan-fongdasen/turso-laravel)[![License: MIT](https://camo.githubusercontent.com/fb14be8a9ab3408806212a5df0f9f13fc300673e8e373017dc43a532ba1f1c3e/68747470733a2f2f706f7365722e707567782e6f72672f72696368616e2d666f6e67646173656e2f747572736f2d6c61726176656c2f6c6963656e73652e737667)](https://opensource.org/licenses/MIT)[![PHPStan](https://github.com/richan-fongdasen/turso-laravel/actions/workflows/phpstan.yml/badge.svg?branch=main)](https://github.com/richan-fongdasen/turso-laravel/actions/workflows/phpstan.yml)[![Unit Tests](https://github.com/richan-fongdasen/turso-laravel/actions/workflows/run-tests.yml/badge.svg?branch=main)](https://github.com/richan-fongdasen/turso-laravel/actions/workflows/run-tests.yml)[![Code Style](https://github.com/richan-fongdasen/turso-laravel/actions/workflows/fix-php-code-style-issues.yml/badge.svg?branch=main)](https://github.com/richan-fongdasen/turso-laravel/actions/workflows/fix-php-code-style-issues.yml)[![codecov](https://camo.githubusercontent.com/20eeae0c273f1ef66497e166e21bf9f0d3d05a4c954653babe814fa01b8e0379/68747470733a2f2f636f6465636f762e696f2f67682f72696368616e2d666f6e67646173656e2f747572736f2d6c61726176656c2f67726170682f62616467652e7376673f746f6b656e3d654b4a53747479554763)](https://codecov.io/gh/richan-fongdasen/turso-laravel)[![Total Downloads](https://camo.githubusercontent.com/58c46c505730480b04f18a878e018ef8c7ac333b5c1ef0deeb9beb5143687682/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f72696368616e2d666f6e67646173656e2f747572736f2d6c61726176656c2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/richan-fongdasen/turso-laravel)

This package provides a Turso database driver for Laravel, allowing you to use Turso as your database backend in Laravel applications. The driver communicates with the Turso database server using an HTTP client.

You can find a demo application that uses this Turso database driver in the [richan-fongdasen/pingcrm](https://github.com/richan-fongdasen/pingcrm) repository.

Requirements
------------

[](#requirements)

- PHP 8.2 or higher
- Laravel 11.0 or higher
- Node.js 18 or higher

Installation
------------

[](#installation)

You can install the package via Composer:

```
composer require richan-fongdasen/turso-laravel
```

To use Turso as your database driver in Laravel, append the following configuration to the `connections` array in your `config/database.php` file:

```
'turso' => [
    'driver'                  => 'turso',
    'db_url'                  => env('DB_URL', 'http://localhost:8080'),
    'access_token'            => env('DB_ACCESS_TOKEN'),
    'db_replica'              => env('DB_REPLICA'),
    'prefix'                  => env('DB_PREFIX', ''),
    'foreign_key_constraints' => env('DB_FOREIGN_KEYS', true),
    'sticky'                  => env('DB_STICKY', true),
],
```

### Publishing Configuration and Sync Script

[](#publishing-configuration-and-sync-script)

Publish the configuration file and sync script by running the following command:

```
php artisan vendor:publish --provider="RichanFongdasen\Turso\TursoLaravelServiceProvider"
```

The above command publishes the following files:

- `config/turso-laravel.php`
- `turso-sync.mjs`

The content of the `config/turso-laravel.php` file should look like this:

```
return [
    'client' => [
        'connect_timeout' => env('TURSO_CONNECT_TIMEOUT', 2),
        'timeout'         => env('TURSO_REQUEST_TIMEOUT', 5),
    ],

    'sync_command' => [
        'node_path'       => env('NODE_PATH'), // Full path to the node executable. E.g: /usr/bin/node
        'script_filename' => 'turso-sync.mjs',
        'script_path'     => realpath(__DIR__ . '/..'),
        'timeout'         => 60,
    ],
];
```

You may need to set the `NODE_PATH` environment variable to the path of your Node.js executable. This is required to run the sync script.

### Installing Node.js Dependencies

[](#installing-nodejs-dependencies)

The Turso database driver requires Node.js to run the sync script. Install the Node.js dependencies by running the following command:

```
npm install @libsql/client
```

Configuration
-------------

[](#configuration)

In Laravel applications, the database driver configuration is stored in your `.env` file. Here are the available configurations for the Turso database driver:

```
DB_CONNECTION=turso
DB_URL=http://localhost:8080
DB_ACCESS_TOKEN=
DB_REPLICA=
DB_PREFIX=
DB_FOREIGN_KEYS=true
DB_STICKY=true
```

ENV Variable NameDescriptionDB\_URLThe Turso database server URL. E.g: `https://[databaseName]-[organizationName].turso.io`DB\_ACCESS\_TOKEN(Optional) The access token to access the Turso database server.DB\_REPLICA(Optional) The full path to the local embedded replica database file. E.g: `/tmp/turso.sqlite`DB\_PREFIX(Optional) The database table prefix.DB\_FOREIGN\_KEYSEnable or disable foreign key constraints, default is `true`.DB\_STICKYEnable or disable sticky connections while performing write operations, default is `true`.Usage
-----

[](#usage)

For local development, you can use the local Turso database server provided by the Turso team. Refer to the [Turso CLI documentation](https://docs.turso.tech/local-development#turso-cli) for instructions on running the local Turso database server.

The Turso database driver should work as expected with Laravel's Query Builder and Eloquent ORM. Here are some examples:

```
use App\Models\User;
use Illuminate\Support\Facades\DB;

// Using Query Builder
$users = DB::table('users')->orderBy('name')->get();

// Using Eloquent ORM
$users = User::with('posts')->orderBy('name')->get();
```

### Embedded Replica Support

[](#embedded-replica-support)

The driver supports the embedded replica feature. If you're unfamiliar with this feature, refer to the [Turso embedded replica article](https://turso.tech/blog/introducing-embedded-replicas-deploy-turso-anywhere-2085aa0dc242) for more information.

### Running the sync script from artisan command

[](#running-the-sync-script-from-artisan-command)

Run the sync script manually using the following Artisan command:

```
php artisan turso:sync
```

> You may encounter an error if the path to the replica database does not exist. This is expected when the replica database has not been created yet.

### Running the sync script programmatically

[](#running-the-sync-script-programmatically)

Run the sync script programmatically using the following code:

```
use Illuminate\Support\Facades\DB;
use RichanFongdasen\Turso\Facades\Turso;

if ( DB::hasModifiedRecords() ) {
    // Run the sync script immediately
    DB::sync();

    // Run the sync script in the background
    DB::backgroundSync();
}

// Sync on the specific connection
DB::connection('turso')->sync();
DB::connection('turso')->backgroundSync();

// Sync on all of the turso database connections
Turso::sync();
Turso::backgroundSync();
```

Debugging
---------

[](#debugging)

To debug the HTTP requests and responses sent and received by the Turso database client, enable the debugging feature as follows:

```
// Enabling query log on default database connection
DB::enableQueryLog();

// Enabling query log on specific connection
DB::connection('turso')->enableQueryLog();

// Perform some queries
DB::table('users')->get();

// Get the query log for default database connection
DB::getQueryLog();

// Get the query log for specific connection
DB::connection('turso')->getQueryLog();
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](.github/CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [Richan Fongdasen](https://github.com/richan-fongdasen)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

48

—

FairBetter than 94% of packages

Maintenance64

Regular maintenance activity

Popularity37

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 74.2% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~26 days

Recently: every ~52 days

Total

9

Last Release

590d ago

Major Versions

0.7.0 → 1.0.02024-11-13

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/5222595?v=4)[Richan Fongdasen](/maintainers/richan-fongdasen)[@richan-fongdasen](https://github.com/richan-fongdasen)

---

Top Contributors

[![richan-fongdasen](https://avatars.githubusercontent.com/u/5222595?v=4)](https://github.com/richan-fongdasen "richan-fongdasen (49 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (9 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (8 commits)")

---

Tags

hranalaravellibsqltursolaraveltursolibsqlRichan Fongdasenturso-laravel

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/richan-fongdasen-turso-laravel/health.svg)

```
[![Health](https://phpackages.com/badges/richan-fongdasen-turso-laravel/health.svg)](https://phpackages.com/packages/richan-fongdasen-turso-laravel)
```

###  Alternatives

[larastan/larastan

Larastan - Discover bugs in your code without running it. A phpstan/phpstan extension for Laravel

6.4k51.0M7.6k](/packages/larastan-larastan)[psalm/plugin-laravel

Psalm plugin for Laravel

3345.1M337](/packages/psalm-plugin-laravel)[laravel/ai

The official AI SDK for Laravel.

9782.1M162](/packages/laravel-ai)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9742.3M121](/packages/roots-acorn)[spatie/laravel-health

Monitor the health of a Laravel application

87411.3M153](/packages/spatie-laravel-health)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
