Skip to content

switon-php/sharding

Repository files navigation

Switon Sharding Package

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.

About

Official application skeleton and framework distribution for Switon Framework

Topics

Resources

License

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Packages

 
 
 

Contributors

Languages