Skip to content

marko-php/marko-database-readwrite

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

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

About

[READ-ONLY] Read/write connection splitting for the Marko Framework database layer. Issues and PRs at https://github.com/marko-php/marko

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages