Package Data | |
---|---|
Maintainer Username: | enfil |
Maintainer Contact: | enfilg@gmail.com (enfil) |
Package Create Date: | 2015-11-13 |
Package Last Update: | 2022-12-29 |
Language: | PHP |
License: | Unknown |
Last Refreshed: | 2024-11-27 15:02:19 |
Package Statistics | |
---|---|
Total Downloads: | 1,534 |
Monthly Downloads: | 0 |
Daily Downloads: | 0 |
Total Stars: | 26 |
Total Watchers: | 2 |
Total Forks: | 7 |
Total Open Issues: | 2 |
composer require enfil/sharding
Add Enfil\Sharding\ShardingServiceProvider::class,
to the providers
array in /config/app.php
.
Add 'ShardManager' => \Enfil\Sharding\Facades\ShardManager::class,
to the alias
list in /config/app.php
.
php artisan vendor:publish --provider="Enfil\Sharding\ShardingServiceProvider" --tag="config" --force
You can configurate sharding for all your services in the sharding.php
config file located in the config
directory.
First of all you should set your service:
\ShardManager::setService('auth');
When you're inserting any element into your database you should generate unique ID for it. You can get next id using:
$id = \ShardManager::getNextId();
Than you can choose shard (database connection) using:
$shard = \ShardManager::getShardById($id);
Now you can insert your data to current shard:
\DB::connection($shard)->table('t')->insert(
[...]
);
After inserting you should increment id-generator:
\ShardManager::increment();
To select your data by id you should get a shard:
$shard = \ShardManager::getShardById($id);
Than you can get data from current shard:
DB::connection($shard)->table('t')->select(...);