Skip to content
This repository was archived by the owner on Jan 7, 2025. It is now read-only.

Commit 028f42b

Browse files
🎉 initial commit
0 parents  commit 028f42b

File tree

11 files changed

+294
-0
lines changed

11 files changed

+294
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/vendor
2+
composer.lock

.travis.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
language: php
2+
3+
php:
4+
- '5.6.4'
5+
- '7.0'
6+
- '7.1'
7+
8+
env:
9+
- ILLUMINATE_VERSION=5.4.*
10+
11+
matrix:
12+
include:
13+
- php: 5.6.4
14+
env: ILLUMINATE_VERSION=5.4.*
15+
- php: 7.0
16+
env: ILLUMINATE_VERSION=5.4.*
17+
- php: 7.1
18+
env: ILLUMINATE_VERSION=5.4.*
19+
20+
before_install:
21+
- composer require "illuminate/database:${ILLUMINATE_VERSION}" --no-update -v
22+
- composer require "illuminate/events:${ILLUMINATE_VERSION}" --no-update -v
23+
24+
install: composer update --prefer-source --no-interaction --dev -v
25+
26+
script: vendor/bin/phpunit --debug -c phpunit.xml --coverage-clover=coverage.clover
27+
28+
after_script:
29+
- wget https://scrutinizer-ci.com/ocular.phar
30+
- php ocular.phar code-coverage:upload --format=php-clover coverage.clover

LICENSE.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2017 Michael Dyrynda
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Laravel Efficient UUIDs
2+
## v1.0.0
3+
4+
[![Build Status](https://travis-ci.org/michaeldyrynda/laravel-efficient-uuid.svg?branch=master)](https://travis-ci.org/michaeldyrynda/laravel-efficient-uuid)
5+
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/michaeldyrynda/laravel-efficient-uuid/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/michaeldyrynda/laravel-efficient-uuid/?branch=master)
6+
[![Code Coverage](https://scrutinizer-ci.com/g/michaeldyrynda/laravel-efficient-uuid/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/michaeldyrynda/laravel-efficient-uuid/?branch=master)
7+
[![Latest Stable Version](https://poser.pugx.org/dyrynda/laravel-efficient-uuid/v/stable)](https://packagist.org/packages/dyrynda/laravel-efficient-uuid)
8+
[![Total Downloads](https://poser.pugx.org/dyrynda/laravel-efficient-uuid/downloads)](https://packagist.org/packages/dyrynda/laravel-efficient-uuid)
9+
[![License](https://poser.pugx.org/dyrynda/laravel-efficient-uuid/license)](https://packagist.org/packages/dyrynda/laravel-efficient-uuid)
10+
11+
## Introduction
12+
13+
This package simply overrides the default grammar file for the given connection making the `uuid()` blueprint method return a `binary(16)` rather than the default `char(36)`.
14+
15+
MySQL is the only supported connection type, only because I've no experience with other drivers. I welcome any pull requests to implement this functionality for other database drivers.
16+
17+
For more information, check out [this post](https://www.percona.com/blog/2014/12/19/store-uuid-optimized-way/) on storing and working with UUID in an optimised manner.
18+
19+
Using UUIDs in Laravel is made super simple in combination with [laravel-model-uuid](https://github.com/michaeldyrynda/laravel-model-uuid).
20+
21+
## Installation
22+
23+
This package is installed via [Composer](https://getcomposer.org/). To install, run the following command.
24+
25+
```bash
26+
composer require dyrynda/laravel-efficient-uuid
27+
```
28+
29+
Register the service provider in your `config/app.php` configuration file:
30+
31+
```php
32+
'providers' => [
33+
...
34+
Dyrynda\Database\LaravelEfficientUuidServiceProvider::class,
35+
],
36+
```
37+
38+
There is nothing special needed for this to function, simply declare a `uuid` column type in your migration files.
39+
40+
```php
41+
Schema::create('posts', function (Blueprint $table) {
42+
$table->increments('id');
43+
$table->uuid('uuid')->index();
44+
$table->string('title');
45+
$table->text('body');
46+
$table->timestamps();
47+
});
48+
```
49+
50+
## Support
51+
52+
If you are having general issues with this package, feel free to contact me on [Twitter](https://twitter.com/michaeldyrynda).
53+
54+
If you believe you have found an issue, please report it using the [GitHub issue tracker](https://github.com/michaeldyrynda/laravel-efficient-uuid/issues), or better yet, fork the repository and submit a pull request.
55+
56+
If you're using this package, I'd love to hear your thoughts. Thanks!

composer.json

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"name": "dyrynda/laravel-efficient-uuid",
3+
"description": "A package to override Laravel migrations to more efficiently store UUID fields in your database",
4+
"type": "utility",
5+
"require": {
6+
"php": ">=5.6.4",
7+
"illuminate/container": "5.4.*",
8+
"illuminate/database": "5.4.*"
9+
},
10+
"require-dev": {
11+
"phpunit/phpunit": "~5.7",
12+
"mockery/mockery": "~0.9.4"
13+
},
14+
"autoload": {
15+
"psr-4": {
16+
"Dyrynda\\Database\\": "src/"
17+
}
18+
},
19+
"autoload-dev": {
20+
"psr-4": {
21+
"Tests\\": "tests/"
22+
}
23+
},
24+
"license": "MIT",
25+
"authors": [
26+
{
27+
"name": "Michael Dyrynda",
28+
"email": "[email protected]",
29+
"homepage": "https://dyrynda.com.au"
30+
}
31+
],
32+
"minimum-stability": "stable"
33+
}

phpunit.xml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit backupGlobals="false"
3+
backupStaticAttributes="false"
4+
colors="true"
5+
convertErrorsToExceptions="true"
6+
convertNoticesToExceptions="true"
7+
convertWarningsToExceptions="true"
8+
processIsolation="false"
9+
stopOnFailure="false"
10+
syntaxCheck="false">
11+
<testsuites>
12+
<testsuite name="Application Test Suite">
13+
<directory>./tests/</directory>
14+
</testsuite>
15+
</testsuites>
16+
<filter>
17+
<whitelist>
18+
<directory suffix=".php">src/</directory>
19+
</whitelist>
20+
</filter>
21+
</phpunit>

src/Blueprint.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
namespace Dyrynda\Database;
4+
5+
use Illuminate\Database\Schema\Blueprint as BaseBlueprint;
6+
7+
class Blueprint extends BaseBlueprint
8+
{
9+
/**
10+
* Create a new uuid column on the table, of type binary(16)
11+
*
12+
* @link https://www.percona.com/blog/2014/12/19/store-uuid-optimized-way/ Store UUID in an optimized way
13+
*
14+
* @param string $column
15+
*
16+
* @return \Illuminate\Support\Fluent
17+
*/
18+
public function uuid($column)
19+
{
20+
return $this->addColumn('uuid', $column);
21+
}
22+
}

src/Connection/MySqlConnection.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace Dyrynda\Database\Connection;
4+
5+
use Dyrynda\Database\Schema\Grammars\MySqlGrammar;
6+
use Illuminate\Database\MySqlConnection as BaseMySqlConnection;
7+
8+
class MySqlConnection extends BaseMySqlConnection
9+
{
10+
/**
11+
* Get the default schema grammar instance.
12+
*
13+
* @return \Illuminate\Database\Grammar
14+
*/
15+
protected function getDefaultSchemaGrammar()
16+
{
17+
return $this->withTablePrefix(new MySqlGrammar);
18+
}
19+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
namespace Dyrynda\Database;
4+
5+
use Dyrynda\Database\Connection\MySqlConnection;
6+
use Illuminate\Database\Connection;
7+
use Illuminate\Support\ServiceProvider;
8+
9+
class LaravelEfficientUuidServiceProvider extends ServiceProvider
10+
{
11+
12+
/**
13+
* Bootstrap any application services.
14+
*
15+
* @return void
16+
*/
17+
public function boot()
18+
{
19+
//
20+
}
21+
22+
23+
/**
24+
* Register any application services.
25+
*
26+
* @return void
27+
*/
28+
public function register()
29+
{
30+
Connection::resolverFor('mysql', function ($connection, $database, $prefix, $config) {
31+
return new MySqlConnection($connection, $database, $prefix, $config);
32+
});
33+
}
34+
}

src/Schema/Grammars/MySqlGrammar.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace Dyrynda\Database\Schema\Grammars;
4+
5+
use Illuminate\Database\Schema\Grammars\MySqlGrammar as BaseMySqlGrammar;
6+
use Illuminate\Support\Fluent;
7+
8+
class MySqlGrammar extends BaseMySqlGrammar
9+
{
10+
/**
11+
* Create the column definition for a UUID type.
12+
*
13+
* @param \Illuminate\Support\Fluent $column
14+
*
15+
* @return string
16+
*/
17+
protected function typeUuid(Fluent $column)
18+
{
19+
return sprintf('binary(16)');
20+
}
21+
}

0 commit comments

Comments
 (0)