jakyeru / snowflake
Snowflake is a package for Laravel that allows Twitter's 64 bit snowflake to be used as primary identifier for models.
v1.0.3
2023-05-13 06:51 UTC
Requires
- php: >=8.0
- godruoyi/php-snowflake: >=2.1.1
- illuminate/support: >=8.0
Requires (Dev)
- orchestra/testbench: 8.0.x-dev
README
About snowflake
Snowflake is a package for Laravel that allows Twitter's 64 bit snowflake to be used as primary identifier for models.
Advantages over other identifiers
- Keys begin with a timestamp
- Keys end with a random number, so guessing the size of the table is impossible
- Keys consist entirely of integers, which are handled more efficiently than strings
- Faster key generation (<1ms)
- Standard UUID v4 - 5.6 milliseconds
- Sortable UUID v4 - 8.3 milliseconds
- ULID - 3.1 milliseconds
- Snowflake - 0.4 milliseconds
Installation
composer require jakyeru/snowflake
Usage
resolve('snowflake')->id(); // ---> 112871594573041664
Usage with Eloquent Models
<?php namespace App\Models; use Illuminate\Foundation\Auth\User as Authenticatable; use Jakyeru\Snowflake\Traits\HasSnowflakes; class User extends Authenticatable { use HasSnowflakes; }
Publishing Configuration
php artisan vendor:publish --tag=snowflake-config
Contributing
Thank you for considering contributing to Snowflake! You can read the contribution guide here.
Code of Conduct
In order to ensure that the community is welcoming to everyone, please review and abide by the Code of Conduct.
Security Vulnerabilities
If you need to report a security vulnerability please read our Security Policy.
License
snowflake is open-sourced software licensed under the MIT license.
If you encounter any other error(s), please open an issue on GitHub.