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