mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-05-11 21:12:15 +09:00
Support more index types in DB::addIndex()
This commit is contained in:
parent
9b776942e5
commit
25373e6540
1 changed files with 8 additions and 3 deletions
|
|
@ -865,19 +865,24 @@ class DB
|
||||||
* @param string $table_name
|
* @param string $table_name
|
||||||
* @param string $index_name
|
* @param string $index_name
|
||||||
* @param array $columns
|
* @param array $columns
|
||||||
* @param bool $unique
|
* @param string $type
|
||||||
* @return \BaseObject
|
* @return \BaseObject
|
||||||
*/
|
*/
|
||||||
public function addIndex(string $table_name, string $index_name, $columns, $unique = false): \BaseObject
|
public function addIndex(string $table_name, string $index_name, $columns, $type = ''): \BaseObject
|
||||||
{
|
{
|
||||||
if (!is_array($columns))
|
if (!is_array($columns))
|
||||||
{
|
{
|
||||||
$columns = array($columns);
|
$columns = array($columns);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($type === true || $type === 1)
|
||||||
|
{
|
||||||
|
$type = 'UNIQUE';
|
||||||
|
}
|
||||||
|
|
||||||
$query = vsprintf("ALTER TABLE `%s` ADD %s `%s` (%s);", array(
|
$query = vsprintf("ALTER TABLE `%s` ADD %s `%s` (%s);", array(
|
||||||
$this->addQuotes($this->_prefix . $table_name),
|
$this->addQuotes($this->_prefix . $table_name),
|
||||||
$unique ? 'UNIQUE INDEX' : 'INDEX',
|
ltrim($type . ' INDEX'),
|
||||||
$this->addQuotes($index_name),
|
$this->addQuotes($index_name),
|
||||||
implode(', ', array_map(function($column_name) {
|
implode(', ', array_map(function($column_name) {
|
||||||
if (preg_match('/^([^()]+)\(([0-9]+)\)$/', $column_name, $matches))
|
if (preg_match('/^([^()]+)\(([0-9]+)\)$/', $column_name, $matches))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue