2017 © Pedro Peláez
 

bundle doctrine-types-extra

Doctrine2 storing `UUID()` as BINARY(16) and `UUID_SHORT()` as BIGINT for MySQL.

image

mihai-stancu/doctrine-types-extra

Doctrine2 storing `UUID()` as BINARY(16) and `UUID_SHORT()` as BIGINT for MySQL.

  • Tuesday, August 2, 2016
  • by mihai-stancu
  • Repository
  • 2 Watchers
  • 0 Stars
  • 1,327 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 1 Versions
  • 3 % Grown

The README.md

Doctrine2 extra types

Doctrine2's default GUID works as a native data type for platforms that support it (Oracle, MSSQL, PostgreSQL) but falls back to VARCHAR in others (MySQL, SQLite)., (*1)

  • BINARY: binary_guid is an alternative of the default guid type which uses BINARY(16) on all platforms (or VARBINARY(16) on platforms without fixed length binary). The default GeneratedValue (UUID) is used as the generator function and hex2bin / bin2hex converters are used. BinaryGuidType extends BinaryType.
  • SHORT: short_guid is an extension of the default guid type which uses BIGINT as a fallback type for UUIDs in MySQL instead of VARCHAR. The UUID_SHORT() function from MySQL is used as the generator function and the results are handled as integers. ShortGuidType extends GuidType.

N.B.: !!! MySQl's short UUIDs are not standard UUIDs and they are not guaranteed to be unique across (...more than 256...) servers., (*2)

Sets and enums are not supported in Doctrine2 by default but they can be treated as strings in most scenarios., (*3)

  • SET: set is a naive implementation of MySQL's set data type represented in PHP as an array of strings. The type only supports generating create statements and implode / explode converters. SetType extends SimpleArrayType.

Usage

Adding the following lines in your app/config.yml (for Symfony2 projects) should do the trick:, (*4)

doctrine:
    dbal:
        types:
            binary_guid: MS\DoctrineTypes\DBAL\Types\BinaryGuidType
            short_guid: MS\DoctrineTypes\DBAL\Types\ShortGuidType

            set: MS\DoctrineTypes\DBAL\Types\SetType


        mapping_types:
            binary_guid: binary_guid
            short_guid: short_guid

            set: set

And adding the following Annotation comments in your entity definitions should finish the job:, (*5)

    /**
     * @Id
     * @Column(type="binary_guid")
     * @GeneratedValue(strategy="UUID")
     */

or, (*6)

    /**
     * @Id
     * @Column(type="short_guid")
     * @GeneratedValue(strategy="CUSTOM")
     * @CustomIdGenerator(class="MS\DoctrineTypes\ORM\Id\ShortGuidGenerator")
     */

or, (*7)

    /**
     * @Column(type="set", options={ "values"={"value1", "value2"} })
     */

The Versions

02/08 2016

dev-master

9999999-dev

Doctrine2 storing `UUID()` as BINARY(16) and `UUID_SHORT()` as BIGINT for MySQL.

  Sources   Download

MIT

The Requires

 

by Mihai Stancu

uuid guid mysql doctrine2 binary bigint binary_guid binary_uuid short_guid short_uuid