Skip to content

ID generator for Doctrine implementing the Snowflake algorithm

Notifications You must be signed in to change notification settings

subiabre/doctrine-snowflakes

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SnowflakeGenerator

ID Generator for Doctrine implementing the Snowflake algorithm.

Install

$ composer require subiabre/doctrine-snowflakes

Usage

In your entity classes:

#[ORM\Id()]
#[ORM\GeneratedValue(strategy: "CUSTOM")]
#[ORM\CustomIdGenerator(class: SnowflakeGenerator::class)]
#[ORM\Column(type: Types::BIGINT]
private string $id;

Take in consideration that PHP does not have a proper bigint data type. Due to this limitation, doctrine-snowflake IDs should be used as string.

public function getId(): string

Testing

This package includes unit tests with the PHPUnit library. Run the tests with:

./vendor/bin/phpunit

The default test cases test against concurrency and uniqueness in 10 batches of 300 IDs each batch, alternatively you can supply any batch size with:

BATCH_SIZE=1000 ./vendor/bin/phpunit

About

ID generator for Doctrine implementing the Snowflake algorithm

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages