A Laravel database driver for Litebase, an open source distributed database built on SQLite, distributed file systems, and object storage.
You can install the package via composer:
composer require litebase/litebase-laravelThe service provider will be automatically registered.
Add a Litebase connection to your config/database.php:
'connections' => [
// ... other connections
'litebase' => [
'driver' => 'litebase',
'database' => env('LITEBASE_DATABASE', 'your_database/main'),
'host' => env('LITEBASE_HOST', 'localhost'),
'port' => env('LITEBASE_PORT', '8888'),
'access_key_id' => env('LITEBASE_ACCESS_KEY_ID'),
'access_key_secret' => env('LITEBASE_ACCESS_KEY_SECRET'),
],
],Add the corresponding environment variables to your .env:
LITEBASE_HOST=localhost
LITEBASE_PORT=8888
LITEBASE_ACCESS_KEY_ID=lbakid_**********
LITEBASE_ACCESS_KEY_SECRET=lbaks_**********
LITEBASE_DATABASE=your_database/mainOnce configured, you can use Litebase like any other Laravel database connection:
use Illuminate\Support\Facades\DB;
// Select
$users = DB::connection('litebase')
->table('users')
->where('active', true)
->get();
// Insert
DB::connection('litebase')
->table('users')
->insert([
'name' => 'John Doe',
'email' => 'john@example.com',
]);
// Update
DB::connection('litebase')
->table('users')
->where('id', 1)
->update(['name' => 'Jane Doe']);
// Delete
DB::connection('litebase')
->table('users')
->where('id', 1)
->delete();use Illuminate\Database\Eloquent\Model;
class User extends Model
{
protected $connection = 'litebase';
protected $table = 'users';
}
// Use the model
$user = User::create([
'name' => 'John Doe',
'email' => 'john@example.com',
]);
$users = User::where('active', true)->get();Use Laravel's migration system as usual:
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
protected $connection = 'litebase';
public function up()
{
Schema::connection('litebase')->create('users', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('email')->unique();
$table->boolean('active')->default(true);
$table->timestamps();
});
}
public function down()
{
Schema::connection('litebase')->dropIfExists('users');
}
};Run migrations:
php artisan migrate --database=litebaseuse Illuminate\Support\Facades\Schema;
// Check if table exists
if (Schema::connection('litebase')->hasTable('users')) {
// ...
}
// Get all tables
$tables = Schema::connection('litebase')->getTables();
// Get table columns
$columns = Schema::connection('litebase')->getColumns('users');use Illuminate\Support\Facades\DB;
DB::connection('litebase')->transaction(function () {
DB::connection('litebase')
->table('users')
->insert(['name' => 'John Doe', 'email' => 'john@example.com']);
DB::connection('litebase')
->table('logs')
->insert(['action' => 'user_created']);
});The package includes an interactive database shell command:
php artisan litebase:db [connection?]This provides an interactive SQL prompt where you can execute queries directly against your Litebase database.
Please see CONTRIBUTING for details.
Run unit tests:
composer testRun integration tests (requires Docker):
composer test-integrationIntegration tests require a running Litebase Server. When running integration tests, a server will be automatically started using Docker.
Run static analysis:
composer phpstanRun code style checks:
composer pintPlease see Code of Conduct for details.
All security related issues should be reported directly to security@litebase.com.
Litebase is open-sourced software licensed under the MIT License.