Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/darkterminal/turso-http-laravel
Turso/libSQL HTTP SDK for Laravel
https://github.com/darkterminal/turso-http-laravel
database laravel libsql php sqlite turso
Last synced: 3 months ago
JSON representation
Turso/libSQL HTTP SDK for Laravel
- Host: GitHub
- URL: https://github.com/darkterminal/turso-http-laravel
- Owner: darkterminal
- License: mit
- Created: 2024-09-04T21:12:14.000Z (4 months ago)
- Default Branch: main
- Last Pushed: 2024-09-15T19:20:38.000Z (4 months ago)
- Last Synced: 2024-09-30T02:04:24.584Z (3 months ago)
- Topics: database, laravel, libsql, php, sqlite, turso
- Language: PHP
- Homepage:
- Size: 36.1 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE.md
Awesome Lists containing this project
README
SQLite for Production. Powered by libSQL.
Turso ·
Quickstart ·
Examples ·
Docs ·
Discord ·
Blog & Tutorials---
A LibSQL HTTP for Laravel
## Requirement
- Turso CLI - [Installation](https://docs.turso.tech/cli/introduction)
- Turso Account - [Register Here](https://tur.so/dt)## Installation
You can install the package via composer:
```bash
composer require darkterminal/turso-http-laravel
```Then register the service provider at `bootstrap/providers.php` array:
```php
return [
App\Providers\AppServiceProvider::class,
Turso\Http\Laravel\LibSQLHttpServiceProvider::class, // Here
];
```## Database Configuration
```env
DB_CONNECTION=libsql
DB_DATABASE=
DB_AUTH_TOKEN=
```## Database Configuration
Add this configuration at `config/database.php` inside the `connections` array:
```php
'libsql' => [
'driver' => 'libsql',
'url' => env('DB_DATABASE', ''),
'authToken' => env('DB_AUTH_TOKEN', ''),
'database' => null,
'prefix' => '',
],
```> Copy and Paste and do not change it! Or try to change it and will broke your app or give you malfunction.
## Usage
For database operation usage, everything have same interface like usual when you using `Illuminate\Support\Facades\DB` in your database model. But remember, this is LibSQL they have `sync` method that can be used when you connect with Remote Replica Connection (Embedded Replica).
```php
use Illuminate\Support\Facades\DB;// Create
DB::table('users')->insert([
'name' => 'Budi Dalton',
'email' => '[email protected]'
]);// Read
DB::table('users')->get();
DB::table('users')->where('id', 2)->first();
DB::table('users')->orderBy('id', 'DESC')->limit(2)->get();// Update
DB::table('users')->where('id', 2)->update(['name' => 'Doni Mandala']);// Delete
DB::table('users')->where('id', 2)->delete();// Transaction
try {
DB::beginTransaction();$updated = DB::table('users')->where('id', 9)->update(['name' => 'Doni Kumala']);
if ($updated) {
echo "It's updated";
DB::commit();
} else {
echo "Not updated";
DB::rollBack();
}$data = DB::table('users')->orderBy('id', 'DESC')->limit(2)->get();
dump($data);
} catch (\Exception $e) {
DB::rollBack();
echo "An error occurred: " . $e->getMessage();
}```
## Changelog
Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.
## Contributing
Please see [CONTRIBUTING](CONTRIBUTING.md) for details.
## Security Vulnerabilities
Please review [our security policy](../../security/policy) on how to report security vulnerabilities.
## Credits
- [Imam Ali Mustofa](https://github.com/darkterminal)
- [All Contributors](../../contributors)## License
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.