An internal class that the user is not expected to instantiate directly. Instances are created by patio.Database#alterTable. It is used to specify table alteration parameters. It takes a Database object and a function which is called in the scope of the patio.AlterTableGenerator to perform on the table, and gives the Database an array of table altering operations, which the database uses to alter a table's description.

Example
DB.alterTable("xyz", function() {
     this.addColumn("aaa", "text", {null : false, unique : true});
     this.dropColumn("bbb");
     this.renameColumn("ccc", "ddd");
     this.setColumnType("eee", "integer");
     this.setColumnDefault("hhh", 'abcd');
     this.addIndex("fff", {unique : true});
     this.dropIndex("ggg");
});

//or using the passed in generator
 DB.alterTable("xyz", function(table) {
     table.addColumn("aaa", "text", {null : false, unique : true});
     table.dropColumn("bbb");
     table.renameColumn("ccc", "ddd");
     table.setColumnType("eee", "integer");
     table.setColumnDefault("hhh", 'abcd');
     table.addIndex("fff", {unique : true});
     table.dropIndex("ggg");
});
            

Constructor

Defined database/schemaGenerators.js Source
function (db,block){
   this.db = db;
   this.operations = [];
   block.apply(this, [this]);
           
}
            

__addCompositeForeignKey Function Private


Defined database/schemaGenerators.js

Arguments Source
function (columns,table,opts){
   this.operations.push(merge({op:"addConstraint", type:"foreignKey", columns:columns, table:table}, opts));
           
}
    

__addCompositePrimaryKey Function Private


Defined database/schemaGenerators.js

Arguments Source
function (columns,opts){
   this.operations.push(merge({op:"addConstraint", type:"primaryKey", columns:columns}, opts));
           
}
    

addColumn Function Public


Defined database/schemaGenerators.js

Add a column with the given name, type, and opts to the DDL for the table. See patio.SchemaGenerator#column for the available options.

Example
DB.alterTable("test", function(){
  this.addColumn("name", String);
    //=> ADD COLUMN name varchar(255)
});
        
Arguments Source
function (name,type,opts){
   opts = opts || {};
   this.operations.push(merge({op:"addColumn", name:name, type:type}, opts));
           
}
    

addConstraint Function Public


Defined database/schemaGenerators.js

Add a constraint with the given name and args to the DDL for the table. See patio.SchemaGenerator#constraint.

Example
var sql = patio.sql;
DB.alterTable("test", function(){
     this.addConstraint("valid_name", sql.name.like('A%'));
         //=>ADD CONSTRAINT valid_name CHECK (name LIKE 'A%')
});
        
Arguments Source
function (name){
   var args = argsToArray(arguments).slice(1);
   var block = isFunction(args[args.length - 1]) ? args[args.length - 1]() : null;
   this.operations.push({op:"addConstraint", name:name, type:"check", check:block || args});
           
}
    

addForeignKey Function Public


Defined database/schemaGenerators.js

Add a foreign key with the given name and referencing the given table to the DDL for the table. See patio.SchemaGenerator#column for the available options.

You can also pass an array of column names for creating composite foreign keys. In this case, it will assume the columns exists and will only add the constraint.

NOTE: If you need to add a foreign key constraint to a single existing column use the composite key syntax even if it is only one column.

Example
DB.alterTable("albums", function(){
  this.addForeignKey("artist_id", "table");
         //=>ADD COLUMN artist_id integer REFERENCES table
  this.addForeignKey(["name"], "table")
         //=>ADD FOREIGN KEY (name) REFERENCES table
});
        
Arguments Source
function (name,table,opts){
   opts = opts;
   if (isArray(name)) {
       return this.__addCompositeForeignKey(name, table, opts);
   } else {
       return this.addColumn(name, this.db.defaultPrimaryKeyType, merge({table:table}, opts));
   }
           
}
    

addFullTextIndex Function Public


Defined database/schemaGenerators.js

Add a full text index on the given columns to the DDL for the table. See @{link patio.SchemaGenerator#index} for available options.

Arguments Source
function (columns,opts){
   opts = opts || {};
   return this.addIndex(columns, merge({type:"fullText"}, opts));
           
}
    

addIndex Function Public


Defined database/schemaGenerators.js

Add an index on the given columns to the DDL for the table. See patio.SchemaGenerator#index for available options.

Example
DB.alterTable("table", function(){
  this.addIndex("artist_id");
         //=> CREATE INDEX table_artist_id_index ON table (artist_id)
});
        
Arguments Source
function (columns,opts){
   opts = opts || {};
   this.operations.push(merge({op:"addIndex", columns:toArray(columns)}, opts));
           
}
    

addPrimaryKey Function Public


Defined database/schemaGenerators.js

Add a primary key to the DDL for the table. See patio.SchemaGenerator#column for the available options. Like patio.ALterTableGenerator#addForeignKey, if you specify the column name as an array, it just creates a constraint:

Example
DB.alterTable("albums", function(){
     this.addPrimaryKey("id");
          //=> ADD COLUMN id serial PRIMARY KEY
     this.addPrimaryKey(["artist_id", "name"])
         //=>ADD PRIMARY KEY (artist_id, name)
});
        
Arguments Source
function (name,opts){
   opts = opts || {};
   if (isArray(name)) {
       return this.__addCompositePrimaryKey(name, opts);
   } else {
       opts = merge({}, this.db.serialPrimaryKeyOptions, opts);
       delete opts.type;
       return this.addColumn(name, "integer", opts);
   }
           
}
    

addSpatialIndex Function Public


Defined database/schemaGenerators.js

Add a spatial index on the given columns to the DDL for the table. See patio.SchemaGenerator#index for available options.

Arguments Source
function (columns,opts){
   opts = opts || {};
   this.addIndex(columns, merge({}, {type:"spatial"}, opts));
           
}
    

addUniqueConstraint Function Public


Defined database/schemaGenerators.js

Add a unique constraint to the given column(s). See patio.SchemaGenerator#constraint.

Example
DB.alterTable("test", function(){
  this.addUniqueConstraint("name");
     //=> ADD UNIQUE (name)
  this.addUniqueConstraint("name", {name : "uniqueName});
     //=> ADD CONSTRAINT uniqueName UNIQUE (name)
});
        
Arguments Source
function (columns,opts){
   opts = opts || {};
   this.operations.push(merge({op:"addConstraint", type:"unique", columns:toArray(columns)}, opts));
           
}
    

dropColumn Function Public


Defined database/schemaGenerators.js

Remove a column from the DDL for the table.

Example
DB.alterTable("albums", function(){
  this.dropColumn("artist_id");
     //=>DROP COLUMN artist_id
});
        
Arguments Source
function (name){
   this.operations.push({op:"dropColumn", name:name});
           
}
    

dropConstraint Function Public


Defined database/schemaGenerators.js

Remove a constraint from the DDL for the table.

Example
DB.alterTable("test", function(){
     this.dropConstraint("constraint_name");
         //=>DROP CONSTRAINT constraint_name
});
        
Arguments Source
function (name){
   this.operations.push({op:"dropConstraint", name:name});
           
}
    

dropIndex Function Public


Defined database/schemaGenerators.js

Remove an index from the DDL for the table.

Example
DB.alterTable("albums", function(){
  this.dropIndex("artist_id")
     //=>DROP INDEX table_artist_id_index
  this.dropIndex(["a", "b"])
     //=>DROP INDEX table_a_b_index
  this.dropIndex(["a", "b"], {name : "foo"})
         //=>DROP INDEX foo
});
        
Arguments Source
function (columns,opts){
   opts = opts || {};
   this.operations.push(merge({op:"dropIndex", columns:toArray(columns)}, opts));
           
}
    

noInherit Function Public


Defined database/schemaGenerators.js

Remove a child table's inheritance from a parent table.

Example
DB.alterTable("test", function () {
     this.noInherit("parentTable");
         //=>ALTER TABLE test NO INHERIT parent_table
});
        
Arguments Source
function (name){
   this.operations.push({op:"noInherit", name: name});
           
}
    

renameColumn Function Public


Defined database/schemaGenerators.js

Modify a column's name in the DDL for the table.

Example
DB.alterTable("artist", function(){
     this.renameColumn("name", "artistName");
         //=> RENAME COLUMN name TO artist_name
});
        
Arguments Source
function (name,newName,opts){
   opts = opts || {};
   this.operations.push(merge({op:"renameColumn", name:name, newName:newName}, opts));
           
}
    

setAllowNull Function Public


Defined database/schemaGenerators.js

Modify a column's NOT NULL constraint.

Example
DB.alterTable("artist", function(){
  this.setColumnAllowNull("artist_name", false);
     //=> ALTER COLUMN artist_name SET NOT NULL
});
        
Arguments Source
function (name,allowNull){
   this.operations.push({op:"setColumnNull", name:name, "null":allowNull});
           
}
    

setColumnDefault Function Public


Defined database/schemaGenerators.js

Modify a column's default value in the DDL for the table.

Example
DB.alterTable("artist", function(){
     //=>this.setColumnDefault("artist_name", "a");
         //=> ALTER COLUMN artist_name SET DEFAULT 'a'
});
        
Arguments Source
function (name,def){
   this.operations.push({op:"setColumnDefault", name:name, "default":def});
           
}
    

setColumnType Function Public


Defined database/schemaGenerators.js

Modify a column's type in the DDL for the table.

Example
DB.alterTable("artist", function(){
  this.setColumnType("artist_name", 'char(10)');
     //=> ALTER COLUMN artist_name TYPE char(10)
});
        
Arguments Source
function (name,type,opts){
   opts = opts || {};
   this.operations.push(merge({op:"setColumnType", name:name, type:type}, opts));
           
}
    

Documentation generated using coddoc.