A Lambo - LibSQL Native Extension/Driver/Whatever
Tags: php, laravel, extensions, libsql
Published: 2024-05-22 20:38:11

Hello Punk!

I build bunch of Turso/LibSQL Client for fun experiment and I love it! I am also build:

- [TursoHTTP](https://github.com/darkterminal/turso-http) (that mentioned by @defenestrator) it's connect Remote Turso Database via HTTP
- [TursoSyncd](https://github.com/darkterminal/turso-syncd) it's stupid worker that sync local database to remote database via HTTP and it will make you poor for a long usage :sweat_smile:
- [LibSQL Client PHP](https://github.com/darkterminal/libsql-client-php) Turso + PHP SDK for Native LibSQL via FFI it's only support **Local Connection**, **Remote Connection** over HTTP, and **Remote Replica**. Also you can check this at [Turso Client SDK](https://docs.turso.tech/sdk/php/quickstart)
- [LibSQL PHP Ext](https://github.com/darkterminal/libsql-php-ext) LibSQL PHP Extension via FFI - Core Dependency for LibSQL Client PHP. This extension behave like SQLite driver but it's LibSQL!

---

## The Final

I've done building a Native LibSQL Extension/Driver/Whatever and I am try to package this driver into Laravel (but I need some help here :smile:). Since this is not an official PHP extension, I need to make it installable in the project.

## What I've Done?

This weekend May, 19 2024, I am done and re-think about what I am talking before. I just drunk stupid person but still; I am handsome. The [LibSQL PHP Ext](https://github.com/darkterminal/libsql-php-ext) can be use stand-alone, this is the core dependency of [LibSQL Client PHP](https://github.com/darkterminal/libsql-client-php).

## Requirements

- Linux or Darwin OS
- C/C++ Compiler
- jq
- Rust Installed
- PHP Installed
- FFI Extension is Enabled (_Why? I read the C heder definition from wrapper_)

## 🚨 DON'T WORRY ABOUT REQUIREMENTS 🚨

Everything will be prepared when you install this extension. But, if you encountered an error; create an issue.

So with [LibSQL PHP Ext](https://github.com/darkterminal/libsql-php-ext) features we can create custom **LibSQL Driver** for Laravel (but it's not support remote), remote connection still handle via HTTP SDK from [LibSQL Client PHP](https://darkterminal/libsql-client-php).

So let me know, who want to join the party :tada: :rocket: 

> NOTE This party only for Linux & Mac/Darwin. But Windows can join when using WSL :smile: 

## Another Options

I am also create native extension [LibSQL Extension](https://github.com/darkterminal/libsql-extension), so you can download and install them and configured in `php.ini` but still, it's not based on PDO driver.

---

## Recent Updates

Make sure you follow the latest update from [My X Thread](https://x.com/panggilmeiam/status/1793206655024496968)!

### 23 Mei 2024 - LibSQL Driver Laravel - LibSQL Remote Replica Connection

And now <a href="https://github.com/darkterminal/libsql-driver-laravel" target="_blank">LibSQL Driver Laravel</a> can perform database <code>sync</code> operations using traditional <code>Illuminate\Support\Facades\DB</code> for LibSQL Remote Replica Connection:

- Migration and Seeding
- CRUD
- Transaction
- Sync

Here the screenshot of fresh Laravel app database migration and data:

1. **Local `database.sqlite` tables**

![Local `database.sqlite` tables](https://github.com/laravel/framework/assets/32319439/2836c371-7e99-47a6-9e62-f496a236dad9)

2. **Remote database tables at Turso Dashboard**

![Remote database tables at Turso Dashboard](https://github.com/laravel/framework/assets/32319439/3869bac5-8351-4f52-accb-172a00e09fdf)

3. **Users Data from Seeder Database at Turso Dashboard**

![Users Data from Seeder Database at Turso Dashboard](https://github.com/laravel/framework/assets/32319439/0976c9d6-1dea-4fe0-a5ae-cf697f278ae2)

5. **Users Data From in Local `database.sqlite` File**

![Users Data From in Local `database.sqlite` File](https://github.com/laravel/framework/assets/32319439/14aef558-beb0-4ecb-bcea-a9ace529ed62)

### 23 May 2024 - LibSQL Driver Laravel - LibSQL Local Connection
And now [LibSQL Driver Laravel](https://github.com/darkterminal/libsql-driver-laravel) can perform database operations using traditional `Illuminate\Support\Facades\DB` for LibSQL Local Connection:

- Migration and Seeding
- CRUD
- Transaction

### 22 May 2024 - LibSQL Driver Laravel - Initial
I created [LibSQL Driver Laravel](https://github.com/darkterminal/libsql-driver-laravel) still work in progress. It's will used <code>Illuminate\Support\Facades\DB</code> to interact with LibSQL native driver.