Skip to content

Basic Usage

Imam Ali Mustofa edited this page Nov 10, 2026 · 1 revision

Basic Usage

Everything below is exercised by tests/Feature/* and/or the docker/proof/ integration harness.

Query Builder

use Illuminate\Support\Facades\DB;

// insert
DB::table('users')->insert([
    'name' => 'Budi Dalton',
    'email' => 'budi.dalton@duck.com',
]);

// 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();

Eloquent

Models work the standard way. Relations (HasMany, HasManyThrough, BelongsToMany), attribute casting (array, bool, int, float, string, date, datetime, enum), soft deletes, collections — all covered by tests/Feature/EloquentRelationship/*, tests/Feature/EloquentAttributeCasting/*, tests/Feature/EloquentCollectionTest.php, tests/Feature/EloquentDeleteTest.php, and tests/Feature/EloquentSoftDeleteTest.php.

Migrations

php artisan make:migration create_movies_table
php artisan migrate

docker/proof/ runs php artisan migrate --force through the driver during its proof, verifying the full artisan migration path.

Transactions

DB::beginTransaction();
try {
    // …
    DB::commit();
} catch (\Throwable $e) {
    DB::rollBack();
    throw $e;
}

Covered by tests/Feature/DatabaseTransactionsTest.php and tests/Feature/DataTypes/IntegerDataTest.php.

Write failures throw (since v1.4.0)

insert() / update() / delete() raise PDOException (Laravel wraps it as QueryException) on constraint violations instead of returning false. Wrap your writes in try/catch the same way as with SQLite:

try {
    DB::table('users')->insert([...]);
} catch (\Illuminate\Database\QueryException $e) {
    report($e);
}

Vector types

libSQL vector types are exposed through the driver. tests/Feature/DataTypes/VectorDataType.php inserts a vector and runs nearest-neighbour search against a vector index, using the vectorIndex() macro (src/Macros/VectorMacro.php). Vector casts are available for Eloquent (src/Database/Casts/VectorCast.php).

DB::sync()

DB::sync() triggers a manual replica sync. Only valid on the embedded replica connection (remote_replica mode); on other modes it errors. Verified by the replica phases of docker/proof/.

Clone this wiki locally