feat(database-readwrite): add marko/database-readwrite package#86
Merged
Conversation
Routes read queries to replica connections and write queries to a primary connection, with sticky writes, single-request fallback on replica failure, and pluggable replica selection (random default, weighted option). Closes #4. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This was referenced May 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
marko/database-readwrite— an opt-in sibling driver package that decoratesConnectionInterfaceto route reads to replica connections and writes to a primary connectionresetStickyState())PDOException/MarkoException; throws loudReadExceptionwhen all exhausted)RandomReplicaSelector(default) andWeightedReplicaSelectormarko/database: newConnectionFactoryInterface, newDatabaseConfig::fromArray()static factory — zero existing API changesmarko/database-pgsqlandmarko/database-mysql: new{Driver}ConnectionFactoryclass + bindingConfiguration
Test plan
ConnectionFactoryInterface,DatabaseConfig::fromArray(),PgSqlConnectionFactory,MySqlConnectionFactoryReadWriteConnectionConfigvalidation (missing write, empty reads, invalid weights, unknown strategy)RandomReplicaSelectorandWeightedReplicaSelector(incl. proportional distribution)ReadWriteConnectionrouting (query → replica, execute/prepare/lastInsertId → write, transaction delegation)driver: 'readwrite', binds bothConnectionInterfaceandTransactionInterface, selector chosen by config)SplitWorkflowTestfailures only)docs/packages/database-readwrite.md+ cross-doc updates todatabase.md,database-pgsql.md,database-mysql.md,.claude/architecture.mdCloses #4
🤖 Generated with Claude Code