SchemaInterface.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. <?php
  2. /**
  3. * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  4. * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  5. *
  6. * Licensed under The MIT License
  7. * For full copyright and license information, please see the LICENSE.txt
  8. * Redistributions of files must retain the above copyright notice.
  9. *
  10. * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  11. * @link http://cakephp.org CakePHP(tm) Project
  12. * @since 3.5.0
  13. * @license http://www.opensource.org/licenses/mit-license.php MIT License
  14. */
  15. namespace Cake\Datasource;
  16. /**
  17. * An interface used by TableSchema objects.
  18. */
  19. interface SchemaInterface
  20. {
  21. /**
  22. * Get the name of the table.
  23. *
  24. * @return string
  25. */
  26. public function name();
  27. /**
  28. * Add a column to the table.
  29. *
  30. * ### Attributes
  31. *
  32. * Columns can have several attributes:
  33. *
  34. * - `type` The type of the column. This should be
  35. * one of CakePHP's abstract types.
  36. * - `length` The length of the column.
  37. * - `precision` The number of decimal places to store
  38. * for float and decimal types.
  39. * - `default` The default value of the column.
  40. * - `null` Whether or not the column can hold nulls.
  41. * - `fixed` Whether or not the column is a fixed length column.
  42. * This is only present/valid with string columns.
  43. * - `unsigned` Whether or not the column is an unsigned column.
  44. * This is only present/valid for integer, decimal, float columns.
  45. *
  46. * In addition to the above keys, the following keys are
  47. * implemented in some database dialects, but not all:
  48. *
  49. * - `comment` The comment for the column.
  50. *
  51. * @param string $name The name of the column
  52. * @param array|string $attrs The attributes for the column.
  53. * @return $this
  54. */
  55. public function addColumn($name, $attrs);
  56. /**
  57. * Get column data in the table.
  58. *
  59. * @param string $name The column name.
  60. * @return array|null Column data or null.
  61. */
  62. public function getColumn($name);
  63. /**
  64. * Returns true if a column exists in the schema.
  65. *
  66. * @param string $name Column name.
  67. * @return bool
  68. */
  69. public function hasColumn($name);
  70. /**
  71. * Remove a column from the table schema.
  72. *
  73. * If the column is not defined in the table, no error will be raised.
  74. *
  75. * @param string $name The name of the column
  76. * @return $this
  77. */
  78. public function removeColumn($name);
  79. /**
  80. * Get the column names in the table.
  81. *
  82. * @return string[]
  83. */
  84. public function columns();
  85. /**
  86. * Returns column type or null if a column does not exist.
  87. *
  88. * @param string $name The column to get the type of.
  89. * @return string|null
  90. */
  91. public function getColumnType($name);
  92. /**
  93. * Sets the type of a column.
  94. *
  95. * @param string $name The column to set the type of.
  96. * @param string $type The type to set the column to.
  97. * @return $this
  98. */
  99. public function setColumnType($name, $type);
  100. /**
  101. * Returns the base type name for the provided column.
  102. * This represent the database type a more complex class is
  103. * based upon.
  104. *
  105. * @param string $column The column name to get the base type from
  106. * @return string|null The base type name
  107. */
  108. public function baseColumnType($column);
  109. /**
  110. * Check whether or not a field is nullable
  111. *
  112. * Missing columns are nullable.
  113. *
  114. * @param string $name The column to get the type of.
  115. * @return bool Whether or not the field is nullable.
  116. */
  117. public function isNullable($name);
  118. /**
  119. * Returns an array where the keys are the column names in the schema
  120. * and the values the database type they have.
  121. *
  122. * @return array
  123. */
  124. public function typeMap();
  125. /**
  126. * Get a hash of columns and their default values.
  127. *
  128. * @return array
  129. */
  130. public function defaultValues();
  131. /**
  132. * Sets the options for a table.
  133. *
  134. * Table options allow you to set platform specific table level options.
  135. * For example the engine type in MySQL.
  136. *
  137. * @param array $options The options to set, or null to read options.
  138. * @return $this
  139. */
  140. public function setOptions($options);
  141. /**
  142. * Gets the options for a table.
  143. *
  144. * Table options allow you to set platform specific table level options.
  145. * For example the engine type in MySQL.
  146. *
  147. * @return array An array of options.
  148. */
  149. public function getOptions();
  150. }