/**
  *  this is here because each rdbms is a little different in how they create indexes
  *  
  *  it is not in the _setIndex because _setIndex creates a table for the index, and
  *  we need a way to set an index on an existing table   
  *
  *  @link http://www.postgresql.org/docs/8.2/static/sql-createindex.html   
  *  @param  string  $table
  *  @param  \MingoIndex $index   
  *  @return boolean  
  */
 protected function createIndex($table, MingoIndex $index, array $options = array())
 {
     $query = sprintf('CREATE %sINDEX %s_%s ON %s USING BTREE (%s)', empty($options['unique']) ? '' : 'UNIQUE ', $table, $index->getName(), $this->normalizeTableSQL($table), join(',', $index->getFieldNames()));
     return $this->getQuery($query);
 }
Example #2
0
 /**
  *  this is here because each rdbms is a little different in how they create indexes
  *  
  *  it is not in the _setIndex because _setIndex creates a table for the index, and
  *  we need a way to set an index on an existing table   
  *
  *  why, oh why? http://stackoverflow.com/questions/1676448/
  *      
  *  @param  string  $table
  *  @param  \MingoIndex $index   
  *  @return boolean  
  */
 protected function createIndex($table, MingoIndex $index)
 {
     // SQLite has a different index creation syntax...
     //  http://www.sqlite.org/lang_createindex.html
     //  create index [if not exists] name ON table_name (col_one[,col...])
     $query = sprintf('CREATE INDEX IF NOT EXISTS %s_%s ON %s (%s)', $table, $index->getName(), $this->normalizeTableSQL($table), join(',', $index->getFieldNames()));
     return $this->getQuery($query);
 }
Example #3
0
 /**
  *  get the index table name
  *  
  *  @param  \MingoTable $table   
  *  @param  \MingoIndex $index
  *  @return string  the index table name
  */
 protected function getIndexTableName(MingoTable $table, MingoIndex $index)
 {
     $table_name = sprintf('%s_%s', $table->getName(), $index->getName());
     return $table_name;
 }
Example #4
0
 /**
  *  add an index to the table
  *  
  *  @param  \MingoIndex $index  the index to add to the table         
  *  @return self
  */
 public function addIndex(MingoIndex $index)
 {
     // canary...
     if ($index->hasField('_id')) {
         throw new UnexpectedValueException('an index cannot include the _id field');
     }
     //if
     $name = $index->getName();
     $this->index_map[$name] = $index;
     return $this;
 }