Cake\Database\Schema\SqliteSchema::indexSql PHP Method

indexSql() public method

{@inheritDoc}
public indexSql ( Table $table, $name )
$table Table
    public function indexSql(Table $table, $name)
    {
        $data = $table->index($name);
        $columns = array_map([$this->_driver, 'quoteIdentifier'], $data['columns']);
        return sprintf('CREATE INDEX %s ON %s (%s)', $this->_driver->quoteIdentifier($name), $this->_driver->quoteIdentifier($table->name()), implode(', ', $columns));
    }

Usage Example

Exemplo n.º 1
0
 /**
  * Test the indexSql method.
  *
  * @dataProvider indexSqlProvider
  */
 public function testIndexSql($name, $data, $expected)
 {
     $driver = $this->_getMockedDriver();
     $schema = new SqliteSchema($driver);
     $table = (new Table('articles'))->addColumn('title', ['type' => 'string', 'length' => 255])->addColumn('author_id', ['type' => 'integer'])->addIndex($name, $data);
     $this->assertEquals($expected, $schema->indexSql($table, $name));
 }