Search by

trail / db

dodgycoffee

Database addon for trail

Package info

source.tube/brindly/trail-db

Issues

Type:trail-addon

pkg:composer/trail/db

Statistics

Installs: 73

Dependents: 3

Suggesters: 0

0.4.2 2026-10-25 20:04 UTC

This package is auto-updated.

Last update: 2026-10-25 20:17:56 UTC


README

Database addon for trail framework

install

composer require trail/db

run migrations

trail/trail db::migrate

write migrations

Theres a helper at $database->id() which gives an auto increment primary key for the db engine. made it easier for me

$database->jsonType() does the same for json columns. $database->driver() says which db engine it is (mariadb is mysql)

$database->textType() is for large text. mariadb text caps at 64 KB

$database->exact() mariadb case-sensitive solution

return static function (Connection $database): void {
    $database->run("
        create table notes (
            id {$database->id()},
            body text not null
        )
    ");
};

where clauses

Clauses builds where that changes at runtime

use Trail\Db\Query\Clauses;

$where = new Clauses();
$where->add('section = ?', 'news');

if ($status) {
    $where->add('status = ?', $status);
}

$where->in('author_id', $authorIds);

$database->all("select * from entries {$where->sql()} order by posted_at desc", $where->params());

checkpoint (sqlite)

trail/trail db::checkpoint

sqlite runs with a persistent connection, so writes sit in db.sqlite-wal till they get added to the db. Run this before copying db file anywhere to make sure its updated

Notes

Supports sqlite, mariadb, and postgres. Not proper mysql (f*ck oracle)