switon/sharding

Rule-driven shard resolution for database connections and tables for Switon Framework

Maintainers

Package info

github.com/switon-php/sharding

Documentation

pkg:composer/switon/sharding

Statistics

Installs: 10

Dependents: 3

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.0 2026-06-07 03:59 UTC

This package is auto-updated.

Last update: 2026-06-07 04:02:43 UTC


README

Sharding CI PHP 8.3+

Switon's shard resolution layer for strategy expressions, single-shard enforcement, and context-based routing across connections and tables.

Highlights

  • Shard resolution: unique(), multiple(), and all() 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, and hash are 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.