PHPackages                             switon/sharding - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. switon/sharding

ActiveLibrary[Database &amp; ORM](/categories/database)

switon/sharding
===============

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

v1.0.0(1mo ago)0103MITPHPPHP &gt;=8.3CI passing

Since Jun 7Pushed 2mo agoCompare

[ Source](https://github.com/switon-php/sharding)[ Packagist](https://packagist.org/packages/switon/sharding)[ Docs](https://github.com/switon-php/sharding)[ RSS](/packages/switon-sharding/feed)WikiDiscussions main Synced 3w ago

READMEChangelogDependencies (5)Versions (2)Used By (3)

Switon Sharding Package
=======================

[](#switon-sharding-package)

[![Sharding CI](https://camo.githubusercontent.com/244b30d6066236e4e61df65ef649ec798b449decb93e73beae7f77c97ab994ca/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f737769746f6e2d7068702f7368617264696e672f63692e796d6c3f6272616e63683d6d61696e266c6162656c3d5368617264696e672532304349)](https://github.com/switon-php/sharding/actions/workflows/ci.yml) [![PHP 8.3+](https://camo.githubusercontent.com/c03f51341eebaefabbf137e291b20523fc74b4ffd084406d88524d266d95085d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e332532422d373737424234)](https://www.php.net/)

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

Highlights
----------

[](#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
------------

[](#installation)

```
composer require switon/sharding
```

Quick Start
-----------

[](#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:

License
-------

[](#license)

MIT.

###  Health Score

40

—

FairBetter than 86% of packages

Maintenance87

Actively maintained with recent releases

Popularity7

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

48d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/dc0f20ad15b0ae9fbf9c6e2cd3008692b0c88a877ec8d3e0119211314bf86fc8?d=identicon)[switon](/maintainers/switon)

---

Top Contributors

[![switon-php](https://avatars.githubusercontent.com/u/247358032?v=4)](https://github.com/switon-php "switon-php (5 commits)")

---

Tags

distributionframeworkskeletonstarterswitondatabaseshardingpartitioningswiton

###  Code Quality

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/switon-sharding/health.svg)

```
[![Health](https://phpackages.com/badges/switon-sharding/health.svg)](https://phpackages.com/packages/switon-sharding)
```

###  Alternatives

[doctrine/dbal

Powerful PHP database abstraction layer (DBAL) with many features for database schema introspection and management.

9.7k605.0M7.0k](/packages/doctrine-dbal)[doctrine/orm

Object-Relational-Mapper for PHP

10.2k300.5M7.7k](/packages/doctrine-orm)[doctrine/doctrine-bundle

Symfony DoctrineBundle

4.8k254.4M4.2k](/packages/doctrine-doctrine-bundle)[doctrine/migrations

PHP Doctrine Migrations project offer additional functionality on top of the database abstraction layer (DBAL) for versioning your database schema and easily deploying changes to it. It is a very easy to use and a powerful tool.

4.8k217.3M565](/packages/doctrine-migrations)[doctrine/data-fixtures

Data Fixtures for all Doctrine Object Managers

2.9k143.6M590](/packages/doctrine-data-fixtures)[robmorgan/phinx

Phinx makes it ridiculously easy to manage the database migrations for your PHP app.

4.5k48.7M472](/packages/robmorgan-phinx)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
