PHP code example of switon / sharding

1. Go to this page and download the library: Download switon/sharding library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

switon / sharding example snippets


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],
        );
    }
}