trail / db
Database addon for trail
Requires
- php: >=8.4
- ext-pdo: *
- trail/framework: ^0.4.0
Requires (Dev)
None
Suggests
None
Provides
None
Conflicts
None
Replaces
None
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)