Switon's shard resolution layer for strategy expressions, single-shard enforcement, and context-based routing across connections and tables.
- 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.
composer require switon/shardinguse 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
MIT.