Browse Source

improved parameter naming and documentation of schemabuilder

changes according to #9191
close #9191
tags/2.0.6
Carsten Brandt 9 years ago
parent
commit
41b25e94b0
  1. 4
      framework/db/ColumnSchemaBuilder.php
  2. 66
      framework/db/SchemaBuilderTrait.php

4
framework/db/ColumnSchemaBuilder.php

@ -140,7 +140,7 @@ class ColumnSchemaBuilder extends Object
*/ */
protected function buildNotNullString() protected function buildNotNullString()
{ {
return $this->isNotNull === true ? ' NOT NULL' : ''; return $this->isNotNull ? ' NOT NULL' : '';
} }
/** /**
@ -149,7 +149,7 @@ class ColumnSchemaBuilder extends Object
*/ */
protected function buildUniqueString() protected function buildUniqueString()
{ {
return $this->isUnique === true ? ' UNIQUE' : ''; return $this->isUnique ? ' UNIQUE' : '';
} }
/** /**

66
framework/db/SchemaBuilderTrait.php

@ -125,51 +125,35 @@ trait SchemaBuilderTrait
/** /**
* Creates a float column. * Creates a float column.
* @param integer $precision column value precision. First parameter passed to the column type, e.g. FLOAT(precision, scale). * @param integer $precision column value precision. First parameter passed to the column type, e.g. FLOAT(precision).
* This parameter will be ignored if not supported by the DBMS.
* @param integer $scale column value scale. Second parameter passed to the column type, e.g. FLOAT(precision, scale).
* This parameter will be ignored if not supported by the DBMS. * This parameter will be ignored if not supported by the DBMS.
* @return ColumnSchemaBuilder the column instance which can be further customized. * @return ColumnSchemaBuilder the column instance which can be further customized.
* @since 2.0.6 * @since 2.0.6
*/ */
public function float($precision = null, $scale = null) public function float($precision = null)
{ {
$length = []; return $this->getDb()->getSchema()->createColumnSchemaBuilder(Schema::TYPE_FLOAT, $precision);
if ($precision !== null) {
$length[] = $precision;
}
if ($scale !== null) {
$length[] = $scale;
}
return $this->getDb()->getSchema()->createColumnSchemaBuilder(Schema::TYPE_FLOAT, $length);
} }
/** /**
* Creates a double column. * Creates a double column.
* @param integer $precision column value precision. First parameter passed to the column type, e.g. DOUBLE(precision, scale). * @param integer $precision column value precision. First parameter passed to the column type, e.g. DOUBLE(precision).
* This parameter will be ignored if not supported by the DBMS.
* @param integer $scale column value scale. Second parameter passed to the column type, e.g. DOUBLE(precision, scale).
* This parameter will be ignored if not supported by the DBMS. * This parameter will be ignored if not supported by the DBMS.
* @return ColumnSchemaBuilder the column instance which can be further customized. * @return ColumnSchemaBuilder the column instance which can be further customized.
* @since 2.0.6 * @since 2.0.6
*/ */
public function double($precision = null, $scale = null) public function double($precision = null)
{ {
$length = []; return $this->getDb()->getSchema()->createColumnSchemaBuilder(Schema::TYPE_DOUBLE, $precision);
if ($precision !== null) {
$length[] = $precision;
}
if ($scale !== null) {
$length[] = $scale;
}
return $this->getDb()->getSchema()->createColumnSchemaBuilder(Schema::TYPE_DOUBLE, $length);
} }
/** /**
* Creates a decimal column. * Creates a decimal column.
* @param integer $precision column value precision. First parameter passed to the column type, e.g. DECIMAL(precision, scale). * @param integer $precision column value precision, which is usually the total number of digits.
* First parameter passed to the column type, e.g. DECIMAL(precision, scale).
* This parameter will be ignored if not supported by the DBMS. * This parameter will be ignored if not supported by the DBMS.
* @param integer $scale column value scale. Second parameter passed to the column type, e.g. DECIMAL(precision, scale). * @param integer $scale column value scale, which is usually the number of digits after the decimal point.
* Second parameter passed to the column type, e.g. DECIMAL(precision, scale).
* This parameter will be ignored if not supported by the DBMS. * This parameter will be ignored if not supported by the DBMS.
* @return ColumnSchemaBuilder the column instance which can be further customized. * @return ColumnSchemaBuilder the column instance which can be further customized.
* @since 2.0.6 * @since 2.0.6
@ -188,38 +172,38 @@ trait SchemaBuilderTrait
/** /**
* Creates a datetime column. * Creates a datetime column.
* @param integer $length column size or precision definition. * @param integer $precision column value precision. First parameter passed to the column type, e.g. DATETIME(precision).
* This parameter will be ignored if not supported by the DBMS. * This parameter will be ignored if not supported by the DBMS.
* @return ColumnSchemaBuilder the column instance which can be further customized. * @return ColumnSchemaBuilder the column instance which can be further customized.
* @since 2.0.6 * @since 2.0.6
*/ */
public function dateTime($length = null) public function dateTime($precision = null)
{ {
return $this->getDb()->getSchema()->createColumnSchemaBuilder(Schema::TYPE_DATETIME, $length); return $this->getDb()->getSchema()->createColumnSchemaBuilder(Schema::TYPE_DATETIME, $precision);
} }
/** /**
* Creates a timestamp column. * Creates a timestamp column.
* @param integer $length column size or precision definition. * @param integer $precision column value precision. First parameter passed to the column type, e.g. TIMESTAMP(precision).
* This parameter will be ignored if not supported by the DBMS. * This parameter will be ignored if not supported by the DBMS.
* @return ColumnSchemaBuilder the column instance which can be further customized. * @return ColumnSchemaBuilder the column instance which can be further customized.
* @since 2.0.6 * @since 2.0.6
*/ */
public function timestamp($length = null) public function timestamp($precision = null)
{ {
return $this->getDb()->getSchema()->createColumnSchemaBuilder(Schema::TYPE_TIMESTAMP, $length); return $this->getDb()->getSchema()->createColumnSchemaBuilder(Schema::TYPE_TIMESTAMP, $precision);
} }
/** /**
* Creates a time column. * Creates a time column.
* @param integer $length column size or precision definition. * @param integer $precision column value precision. First parameter passed to the column type, e.g. TIME(precision).
* This parameter will be ignored if not supported by the DBMS. * This parameter will be ignored if not supported by the DBMS.
* @return ColumnSchemaBuilder the column instance which can be further customized. * @return ColumnSchemaBuilder the column instance which can be further customized.
* @since 2.0.6 * @since 2.0.6
*/ */
public function time($length = null) public function time($precision = null)
{ {
return $this->getDb()->getSchema()->createColumnSchemaBuilder(Schema::TYPE_TIME, $length); return $this->getDb()->getSchema()->createColumnSchemaBuilder(Schema::TYPE_TIME, $precision);
} }
/** /**
@ -246,21 +230,21 @@ trait SchemaBuilderTrait
/** /**
* Creates a boolean column. * Creates a boolean column.
* @param integer $length column size or precision definition.
* This parameter will be ignored if not supported by the DBMS.
* @return ColumnSchemaBuilder the column instance which can be further customized. * @return ColumnSchemaBuilder the column instance which can be further customized.
* @since 2.0.6 * @since 2.0.6
*/ */
public function boolean($length = null) public function boolean()
{ {
return $this->getDb()->getSchema()->createColumnSchemaBuilder(Schema::TYPE_BOOLEAN, $length); return $this->getDb()->getSchema()->createColumnSchemaBuilder(Schema::TYPE_BOOLEAN);
} }
/** /**
* Creates a money column. * Creates a money column.
* @param integer $precision column value precision. First parameter passed to the column type, e.g. MONEY(precision, scale). * @param integer $precision column value precision, which is usually the total number of digits.
* First parameter passed to the column type, e.g. DECIMAL(precision, scale).
* This parameter will be ignored if not supported by the DBMS. * This parameter will be ignored if not supported by the DBMS.
* @param integer $scale column value scale. Second parameter passed to the column type, e.g. MONEY(precision, scale). * @param integer $scale column value scale, which is usually the number of digits after the decimal point.
* Second parameter passed to the column type, e.g. DECIMAL(precision, scale).
* This parameter will be ignored if not supported by the DBMS. * This parameter will be ignored if not supported by the DBMS.
* @return ColumnSchemaBuilder the column instance which can be further customized. * @return ColumnSchemaBuilder the column instance which can be further customized.
* @since 2.0.6 * @since 2.0.6

Loading…
Cancel
Save