2017 © Pedro Peláez
 

library sharding

Laravel 5.1 sharding

image

enfil/sharding

Laravel 5.1 sharding

  • Monday, July 4, 2016
  • by enfil
  • Repository
  • 2 Watchers
  • 14 Stars
  • 1,509 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 1 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

laravel-sharding

#

LEGACY!!!

CLOSED AND NOT SUPPORTED

#

Installation

Download package

composer require enfil/sharding, (*1)

Add to Providers

Add Enfil\Sharding\ShardingServiceProvider::class, to the providers array in /config/app.php., (*2)

Add to Aliases

Add 'ShardManager' => \Enfil\Sharding\Facades\ShardManager::class, to the alias list in /config/app.php., (*3)

Publish config

php artisan vendor:publish --provider="Enfil\Sharding\ShardingServiceProvider" --tag="config" --force, (*4)

Configuration

You can configurate sharding for all your services in the sharding.php config file located in the config directory., (*5)

Usage

First of all you should set your service:, (*6)

\ShardManager::setService('auth');, (*7)

Adding data

When you're inserting any element into your database you should generate unique ID for it. You can get next id using:, (*8)

$id = \ShardManager::getNextId();, (*9)

Than you can choose shard (database connection) using:, (*10)

$shard = \ShardManager::getShardById($id);, (*11)

Now you can insert your data to current shard:, (*12)

\DB::connection($shard)->table('t')->insert(
    [...]
);

After inserting you should increment id-generator:, (*13)

\ShardManager::increment();, (*14)

Selecting data

To select your data by id you should get a shard:, (*15)

$shard = \ShardManager::getShardById($id);, (*16)

Than you can get data from current shard:, (*17)

DB::connection($shard)->table('t')->select(...);, (*18)

The Versions

04/07 2016

dev-master

9999999-dev

Laravel 5.1 sharding

  Sources   Download

The Requires

 

by Avatar enfil