switon / sharding
Rule-driven shard resolution for database connections and tables for Switon Framework
v1.0.0
2026-06-07 03:59 UTC
Requires
- php: >=8.3
- switon/core: ^1.0
- switon/event: ^1.0
Requires (Dev)
- phpstan/extension-installer: ^1.4
- phpstan/phpstan: ^2.0
- switon/testing: ^1.0
README
Switon's shard resolution layer for strategy expressions, single-shard enforcement, and context-based routing across connections and tables.
Highlights
- Shard resolution:
unique(),multiple(), andall()cover the common lookup modes. - Single-shard safety: requests that resolve to too many shards are rejected.
- Flexible context: array, object, and empty contexts can all be handled.
- Built-in strategies:
modulo,list,range,crc32, andhashare included. - Compact expressions: short routing expressions can resolve into shard names.
Installation
composer require switon/sharding
Quick Start
use Switon\Core\Attribute\Autowired; use Switon\Sharding\ShardingManagerInterface; class UserRepository { #[Autowired] protected ShardingManagerInterface $shardingManager; public function find(int $userId): array { return $this->shardingManager->unique( 'db:user_id%4', 'user:user_id%8', ['user_id' => $userId], ); } }
Docs: https://docs.switon.dev/latest/sharding
License
MIT.