Download the PHP package monkeyscloud/monkeyslegion-database without Composer
On this page you can find all versions of the php package monkeyscloud/monkeyslegion-database. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download monkeyscloud/monkeyslegion-database
More information about monkeyscloud/monkeyslegion-database
Files in monkeyscloud/monkeyslegion-database
Package monkeyslegion-database
Short Description High-performance PDO connection management with read/write splitting, connection pooling, and multi-driver support (MySQL, PostgreSQL, SQLite).
License MIT
Informations about the package monkeyslegion-database
MonkeysLegion Database v2
High-performance PDO connection management for PHP 8.4+ with read/write splitting, connection pooling, lazy connections, and multi-driver support.
Features
- ✅ Multi-Driver: MySQL, PostgreSQL, SQLite — unified API via
match()dispatch - ✅ Read/Write Splitting: Route reads to replicas, writes to primary — automatically
- ✅ Lazy Connections: PDO is not allocated until the first query (zero cost in CLI/workers)
- ✅ Connection Pooling: In-memory pool with health monitoring, idle eviction, max-lifetime enforcement
- ✅ Sticky-After-Write: Reads route to primary after a write to avoid replication lag
- ✅ 18 Typed Exceptions: Every
PDOExceptionis classified into a specific actionable type - ✅ Schema Introspection: Table/column/FK/unique-index discovery with aggressive static caching
- ✅ PHP 8.4 Native: Property hooks, asymmetric visibility, readonly classes, backed enums
- ✅ Zero Config Defaults: Sensible PDO defaults (exceptions, assoc fetch, real prepares)
- ✅ Type-Safe Config: Immutable value objects replace raw arrays
Requirements
- PHP 8.4+
ext-pdo(plusext-pdo_mysql,ext-pdo_pgsql, orext-pdo_sqliteper driver)
Installation
Quick Start
ConnectionManager (Recommended)
Direct Connection
SQLite In-Memory (Tests)
Read/Write Splitting
Route read queries to replicas and writes to the primary connection:
Transactions
Lazy Connections
Connections are lazy by default when obtained through ConnectionManager. The PDO is not created until you call pdo(), query(), execute(), or start a transaction:
This is ideal for CLI commands and queue workers where many code paths don't touch the database.
Connection Pooling
Pool Stats
Pool Warm-Up
Pre-warm the pool to minConnections at application boot to avoid cold-start latency:
Exception Handling
Every PDOException is automatically classified into a specific, actionable exception type:
Exception Hierarchy
Schema Introspection
Discover table structure without manual SQL:
Configuration Reference
DatabaseConfig
DsnConfig Options
| Driver | Option | Description |
|---|---|---|
| All | host |
Server hostname |
| All | port |
Server port |
| All | database |
Database name |
| MySQL | socket |
Unix socket path |
| MySQL | charset |
Character set (default: utf8mb4) |
| PostgreSQL | sslMode |
SSL mode (disable, require, etc.) |
| SQLite | file |
Database file path |
| SQLite | memory |
Use :memory: database |
Last Insert ID
Retry Handler
Automatic retry on transient failures (deadlocks, lost connections) with truncated exponential back-off and jitter:
RetryConfig is a PHP 8.4 readonly class. Its $effectiveMaxDelay property
uses a get hook to guarantee the value is never negative.
PSR-3 Logging
Inject a PSR-3 logger directly as a property — no setter method needed:
Logged events: connection established, connection closed, query executed (with SQL + duration), query errors.
Event Dispatcher
Connection Lifecycle
Multi-Connection Management
DI Container Setup
Testing
163 tests, 361 assertions covering all components:
| Component | Tests |
|---|---|
| Types (DatabaseDriver, IsolationLevel, ReadReplicaStrategy) | 21 |
| Config (DsnConfig, PoolConfig, DatabaseConfig) | 25 |
| Connection (Connection, LazyConnection, ConnectionManager, ConnectionPool) | 54 |
| Exceptions (18 classes) | 23 |
| Support (ErrorClassifier, ConnectionPoolStats) | 22 |
Upgrade from v1
v2 is a clean-slate rewrite. Key migration points:
| v1 | v2 |
|---|---|
MySQL\Connection, PostgreSQL\Connection, SQLite\Connection |
Connection\Connection (unified) |
DSN\MySQLDsnBuilder, etc. |
Config\DsnConfig value object |
Factory\ConnectionFactory |
Connection\ConnectionManager |
Types\DatabaseType enum |
Types\DatabaseDriver enum |
$connection->pdo() |
Same — $connection->pdo() |
Raw PDOException |
Typed exceptions (DuplicateKeyException, etc.) |
| No read/write splitting | $manager->read() / $manager->write() |
| No lazy connections | Lazy by default via ConnectionManager |
| No connection pooling | ConnectionPool with health monitoring |
License
MIT — © 2026 MonkeysCloud Inc.
All versions of monkeyslegion-database with dependencies
ext-pdo Version *
psr/simple-cache Version ^3.0
psr/log Version ^3.0
monkeyscloud/monkeyslegion-cli Version ^2.0
monkeyscloud/monkeyslegion-cache Version ^2.0