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

This package is auto-updated.

Last update: 2024-04-13 08:42:51 UTC


README

Snowflake-logos_transparent.png

release

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.