DEV Community

Cover image for Turso Driver for Laravel
Imam Ali Mustofa
Imam Ali Mustofa

Posted on • Edited on

Turso Driver for Laravel

Hello Punk! πŸ‘‹ Yes, I am again. Sorry for wasting your time reading this pretty blog/article/whatever.


It's re-write?

Yes! But, the first blog is just copy-paste from README.md file. Here the actual story what I've done with Laravel.

PHP Community it's huge! But when Turso/LibSQL Database came, they did not support PHP, because they doesn't have developer that really into in PHP and LibSQL build using Rust, so they have Rust only binary.

For the first launch, They have Rust, Go, Python and TypeScript/JS Official SDKs.

However, Turso provides the HTTP SDK as a creation tool for developers who want to create an SDK that is not yet supported by the official SDK.

From there, several Community SDKs emerged, most of which use the HTTP SDK. When using HTTP SDK so database interact with Remote Database and the developer still use SQLite for In-Memory or Local Interaction. Is it wrong? Of course not, I also did the same thing at first. This is an art, so people can have their own interpretation.

Here is my first Turso/LibSQL Library that support Turso HTTP SDK and Platform API.

But, Turso also have a Embedded Replica that sync local database with remote database on the edge, how do sync then?

Don't worry I am also create a Stupid Worker which will make you poor when using it with the number of interactions reading and writing databases from local to remote via HTTP Protocol.

GitHub logo darkterminal / turso-syncd

Turso Database Background Sync

~ TursoSyncd ~

Turso Dabatabase Background Sync in the Background

Installation

Globally Install

composer global require darkterminal/turso-syncd
Enter fullscreen mode Exit fullscreen mode

or you can install locally within your porject:

composer require darkterminal/turso-syncd
Enter fullscreen mode Exit fullscreen mode

Usage

turso-syncd --database=<database_name> --organization=<organization_name> --token=<token> [--file_recorder=<file>] [--action_log_file=<file>] [--errors_log_file=<file>]
Enter fullscreen mode Exit fullscreen mode

Options

  • --database=<database_name> or -d: The name of the database.
  • --organization=<organization_name> or -o: The name of the organization.
  • --token=<token> or -t: The token for authentication.
  • --file_recorder=<file>: Specify file recorder.
  • --action_log_file=<file>: Specify action log file.
  • --errors_log_file=<file>: Specify errors log file.
  • --help: Display this help message.

Extend in Your Own Daemon

<?php
use Darkterminal\TursoSyncd;

require_once "vendor/autoload.php";

$databaseName       = "your-database-name";
$organizationName   = "your-organization-name";
$token              = "your-turso-token";
$config             = [
    'file_recorder
…
Enter fullscreen mode Exit fullscreen mode

Back to This!

When using HTTP SDK so database interact with Remote Database and the developer still use SQLite for In-Memory or Local Interaction. Is it wrong? Of course not, I also did the same thing at first.

But if we use SQLite to create an In-Memory or Local File Connection, it will reduce the artistic value of LibSQL, because with Binary LibSQL, we can create 4 different types of database connections.

  • In-Memory Connection
  • Local Connection
  • Remote Connection
  • Remote Replica (Embedded Replica) Connection

That's why I was challenged to create a Native Extension/Driver/Whatever to get the full power of what Turso/LibSQL has to offer.

You can read the README.md when you landed at my Laravel Driver repository in GitHub

GitHub logo tursodatabase / turso-driver-laravel

Turso Driver for Laravel with Native libSQL - Community SDK

Caution

There is a new adapter coming soon for Laravel that doesn't require using an extension. This extension doesn't support offline writes beta. Join us on Discord to talk more - https://discord.gg/turso

Shows a black logo in light color mode and a white one in dark color mode.

Turso + Laravel

MIT License Discord Contributors Total downloads Version Tag Testing

SQLite for Production. Powered by libSQL and libSQL Extension for PHP

LibSQL is a fork of SQLite and this package is #1 LibSQL Driver that run natively using LibSQL Native Extension/Driver/Whatever and support Laravel Ecosystem


Installation

You can install the package via composer:

composer require tursodatabase/turso-driver-laravel
Enter fullscreen mode Exit fullscreen mode

Then register the service provider at bootstrap/providers.php array:

return [
    App\Providers\AppServiceProvider::class,
    Turso\Driver\Laravel\LibSQLDriverServiceProvider::class, // Here
];
Enter fullscreen mode Exit fullscreen mode

The package now include the turso-php-installer, so you can install the LibSQL Extension via artisan command:

php artisan turso-php:install

And you can read the all command using php artisan | grep turso-php or read the manual

Laravel Sail

Don't worry, we also provide Laravel Sail step by step…




I just want to bring some joy out of the mess I've made writing code while dancing to the music I hate the most.

You can read Turso Documentation

If you like this project and want to support my activities, you can sponsor me on GitHub. Sorry and thank you for taking the time to read.

Top comments (0)