Skip to content

Collection of useful types and other minor extensions to the Doctrine DBAL and ORM.

Notifications You must be signed in to change notification settings

cgraefe/doctrine-extensions

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Doctrine-Extensions

Build Status

This is a collection of useful types and other minor extensions to the Doctrine DBAL and ORM.

UnixTimeType

UnixTimeType is a custom Doctrine mapping type for time-stamp values represented in unix time, i.e. seconds since Jan 1, 1970.

// Register custom type during boot-strap.
\Doctrine\DBAL\Types\Type::addType('unixtime', '\Graefe\Doctrine\Type\UnixTimeType');

...

/**
 * @ORM\Column(name="created", type="unixtime", nullable=false)
 */
private $created;

MySqlEnumType

MySqlEnumType is an abstract base class for mapping ENUM types in MySQL.

// Define type.
class ShopModeType extends \Graefe\Doctrine\Type\MySqlEnumType
{
    protected function getValues() { return array('b2b','b2c'); }
    public function getName() { return 'shopmode'; }
}

...

// Register type during boot-strap.
\Doctrine\DBAL\Types\Type::addType('shopmode', 'ShopModeType');

...

/**
 * @ORM\Column(name="mode", type="shopmode", nullable=false)
 */
private $mode;

RAND()

The Rand class provides the RAND() function to DQL for selecting random rows. (Caveat: Improper use might cause serious performance problems.)

// Register function.
$em->getConfiguration()->addCustomNumericFunction('RAND', '\\Graefe\\Doctrine\\Functions\\Rand');

...

$qb->select('d')
    ->addSelect('RAND() AS randval')
    ->from('Dummy', 'd')
    ->orderBy('randval')
    ->setMaxResults(1);

About

Collection of useful types and other minor extensions to the Doctrine DBAL and ORM.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages