Skip to content
Yo-An Lin edited this page Jan 23, 2016 · 3 revisions

Defining single column index

DeclareSchema let you be able to define index in the schema class:

class ProductSchema extends DeclareSchema
{
    public function schema()
    {
        $this->column('name')->varchar(32);
        $this->column('identity')->varchar(32);
        $this->index('idx_name', 'name');
    }
}

Defining multiple column index

class ProductSchema extends DeclareSchema
{
    public function schema()
    {
        $this->column('name')->varchar(32);
        $this->column('identity')->varchar(32);
        $this->index('idx_product_query', ['name', 'identity']);
    }
}

Specifying indexing method

Using BTREE:

class ProductSchema extends DeclareSchema
{
    public function schema()
    {
        $this->column('name')->varchar(32);
        $this->column('identity')->varchar(32);
        $this->index('idx_product_query', ['name', 'identity'], 'btree');
    }
}

Using HASH:

class ProductSchema extends DeclareSchema
{
    public function schema()
    {
        $this->column('name')->varchar(32);
        $this->column('identity')->varchar(32);
        $this->index('idx_product_query', ['name', 'identity'], 'hash');
    }
}

Retrieving the CreateIndexQuery object

$query = $this->index('idx_product_query'); // Returns SQLBuilder\Universal\Query\CreateIndexQuery

Defining unique index on column object

$this->column('identity')->varchar(32)->unique();

Clone this wiki locally