marko / database-readwrite
Read/write connection splitting for the Marko Framework database layer
0.7.0
2026-05-27 16:19 UTC
Requires
- php: ^8.5
- ext-pdo: *
- marko/core: 0.7.0
- marko/database: 0.7.0
Requires (Dev)
- pestphp/pest: ^4.0
This package is auto-updated.
Last update: 2026-05-27 16:28:32 UTC
README
Routes reads to replicas, writes to primary --- drop-in decorator for any Marko database driver.
Installation
composer require marko/database-readwrite
Quick Example
<?php declare(strict_types=1); return [ 'driver' => 'readwrite', 'connections' => [ 'write' => [ 'driver' => 'pgsql', 'host' => $_ENV['DB_WRITE_HOST'] ?? 'localhost', 'port' => (int) ($_ENV['DB_WRITE_PORT'] ?? 5432), 'database' => $_ENV['DB_DATABASE'] ?? 'marko', 'username' => $_ENV['DB_USERNAME'] ?? 'postgres', 'password' => $_ENV['DB_PASSWORD'] ?? '', ], 'read' => [ [ 'driver' => 'pgsql', 'host' => $_ENV['DB_READ_HOST'] ?? 'replica-1', 'port' => (int) ($_ENV['DB_READ_PORT'] ?? 5432), 'database' => $_ENV['DB_DATABASE'] ?? 'marko', 'username' => $_ENV['DB_USERNAME'] ?? 'postgres', 'password' => $_ENV['DB_PASSWORD'] ?? '', ], ], 'read_strategy' => 'random', ], ];
Documentation
Full usage, configuration, API reference, and examples: marko/database-readwrite