Skip to content

Latest commit

 

History

History
48 lines (38 loc) · 1.4 KB

README.md

File metadata and controls

48 lines (38 loc) · 1.4 KB

marko/database-readwrite

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

use Marko\Config\Env;

return [
    'driver' => 'readwrite',
    'connections' => [
        'write' => [
            'driver'   => 'pgsql',
            'host'     => Env::string('DB_WRITE_HOST', 'localhost'),
            'port'     => Env::int('DB_WRITE_PORT', 5432, min: 1, max: 65535),
            'database' => Env::string('DB_DATABASE', 'marko'),
            'username' => Env::string('DB_USERNAME', 'postgres'),
            'password' => Env::string('DB_PASSWORD', ''),
        ],
        'read' => [
            [
                'driver'   => 'pgsql',
                'host'     => Env::string('DB_READ_HOST', 'replica-1'),
                'port'     => Env::int('DB_READ_PORT', 5432, min: 1, max: 65535),
                'database' => Env::string('DB_DATABASE', 'marko'),
                'username' => Env::string('DB_USERNAME', 'postgres'),
                'password' => Env::string('DB_PASSWORD', ''),
            ],
        ],
        'read_strategy' => 'random',
    ],
];

Documentation

Full usage, configuration, API reference, and examples: marko/database-readwrite