forked from zendframework/zend-db
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
zendframework#186 Add SERIAL column type to support autoincrement -st…
…yle columns in PostgreSQL
- Loading branch information
Showing
2 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
/** | ||
* Zend Framework (http://framework.zend.com/). | ||
* | ||
* @link http://github.com/zendframework/zf2 for the canonical source repository | ||
* | ||
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) | ||
* @license http://framework.zend.com/license/new-bsd New BSD License | ||
*/ | ||
|
||
namespace Zend\Db\Sql\Ddl\Column; | ||
|
||
/** | ||
* Column for PostgreSQL to automatically increment column. | ||
* | ||
* Similar to MySQL's autoincrement, but without performance issues. | ||
* Used in conjunction with SequenceFeature. | ||
*/ | ||
class Serial extends Column | ||
{ | ||
protected $type = 'SERIAL'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
/** | ||
* Zend Framework (http://framework.zend.com/). | ||
* | ||
* @link http://github.com/zendframework/zf2 for the canonical source repository | ||
* | ||
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) | ||
* @license http://framework.zend.com/license/new-bsd New BSD License | ||
*/ | ||
|
||
namespace ZendTest\Db\Sql\Ddl\Column; | ||
|
||
use Zend\Db\Sql\Ddl\Column\Serial; | ||
use Zend\Db\Sql\Ddl\Constraint\PrimaryKey; | ||
|
||
class SerialTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
public function testGetExpressionData() | ||
{ | ||
$column = new Serial('id'); | ||
$this->assertEquals( | ||
[['%s %s NOT NULL', ['id', 'SERIAL'], [$column::TYPE_IDENTIFIER, $column::TYPE_LITERAL]]], | ||
$column->getExpressionData() | ||
); | ||
|
||
$column = new Serial('id'); | ||
$column->addConstraint(new PrimaryKey()); | ||
$this->assertEquals( | ||
[ | ||
['%s %s NOT NULL', ['id', 'SERIAL'], [$column::TYPE_IDENTIFIER, $column::TYPE_LITERAL]], | ||
' ', | ||
['PRIMARY KEY', [], []], | ||
], | ||
$column->getExpressionData() | ||
); | ||
} | ||
} |