不要怂,就是干,撸起袖子干!

Commit a92fb9ce by Mick Hansen

Merge pull request #3837 from BridgeAR/fix-indentation

Remove unnecessary indentation
2 parents 073f1777 33ff3ad5
var Association = function() {
var Association = function () {};
};
module.exports = Association;
\ No newline at end of file
......@@ -7,8 +7,7 @@ var Utils = require('./../utils')
, CounterCache = require('../plugins/counter-cache')
, util = require('util');
module.exports = (function() {
var BelongsToMany = function(source, target, options) {
var BelongsToMany = function(source, target, options) {
Association.call(this);
this.associationType = 'BelongsToMany';
......@@ -176,13 +175,13 @@ module.exports = (function() {
if (this.options.counterCache) {
new CounterCache(this, this.options.counterCache !== true ? this.options.counterCache : {});
}
};
};
util.inherits(BelongsToMany, Association);
util.inherits(BelongsToMany, Association);
// the id is in the target table
// or in an extra table which connects two tables
BelongsToMany.prototype.injectAttributes = function() {
// the id is in the target table
// or in an extra table which connects two tables
BelongsToMany.prototype.injectAttributes = function() {
var self = this;
this.identifier = this.foreignKey;
......@@ -263,9 +262,9 @@ module.exports = (function() {
Helpers.checkNamingCollision(this);
return this;
};
};
BelongsToMany.prototype.injectGetter = function(obj) {
BelongsToMany.prototype.injectGetter = function(obj) {
var association = this;
obj[this.accessors.get] = function(options) {
......@@ -364,9 +363,9 @@ module.exports = (function() {
};
return this;
};
};
BelongsToMany.prototype.injectSetter = function(obj) {
BelongsToMany.prototype.injectSetter = function(obj) {
var association = this
, primaryKeyAttribute = association.target.primaryKeyAttribute;
......@@ -668,9 +667,9 @@ module.exports = (function() {
};
return this;
};
};
BelongsToMany.prototype.injectCreator = function(obj) {
BelongsToMany.prototype.injectCreator = function(obj) {
var association = this;
obj[this.accessors.create] = function(values, options) {
......@@ -701,7 +700,6 @@ module.exports = (function() {
};
return this;
};
};
return BelongsToMany;
})();
module.exports = BelongsToMany;
......@@ -6,8 +6,7 @@ var Utils = require('./../utils')
, Association = require('./base')
, util = require('util');
module.exports = (function() {
var BelongsTo = function(source, target, options) {
var BelongsTo = function(source, target, options) {
Association.call(this);
this.associationType = 'BelongsTo';
......@@ -67,12 +66,12 @@ module.exports = (function() {
set: 'set' + singular,
create: 'create' + singular
};
};
};
util.inherits(BelongsTo, Association);
util.inherits(BelongsTo, Association);
// the id is in the source table
BelongsTo.prototype.injectAttributes = function() {
// the id is in the source table
BelongsTo.prototype.injectAttributes = function() {
var newAttributes = {};
newAttributes[this.identifier] = Utils._.defaults(this.foreignKeyAttribute, { type: this.options.keyType || this.target.rawAttributes[this.targetIdentifier].type });
......@@ -90,10 +89,10 @@ module.exports = (function() {
Helpers.checkNamingCollision(this);
return this;
};
};
// Add getAssociation method to the prototype of the model instance
BelongsTo.prototype.injectGetter = function(instancePrototype) {
// Add getAssociation method to the prototype of the model instance
BelongsTo.prototype.injectGetter = function(instancePrototype) {
var association = this;
instancePrototype[this.accessors.get] = function(options) {
......@@ -124,10 +123,10 @@ module.exports = (function() {
};
return this;
};
};
// Add setAssociaton method to the prototype of the model instance
BelongsTo.prototype.injectSetter = function(instancePrototype) {
// Add setAssociaton method to the prototype of the model instance
BelongsTo.prototype.injectSetter = function(instancePrototype) {
var association = this;
instancePrototype[this.accessors.set] = function(associatedInstance, options) {
......@@ -154,10 +153,10 @@ module.exports = (function() {
};
return this;
};
};
// Add createAssociation method to the prototype of the model instance
BelongsTo.prototype.injectCreator = function(instancePrototype) {
// Add createAssociation method to the prototype of the model instance
BelongsTo.prototype.injectCreator = function(instancePrototype) {
var association = this;
instancePrototype[this.accessors.create] = function(values, fieldsOrOptions) {
......@@ -175,7 +174,6 @@ module.exports = (function() {
};
return this;
};
};
return BelongsTo;
})();
module.exports = BelongsTo;
......@@ -3,15 +3,14 @@
var Utils = require('./../utils')
, _ = require('lodash');
module.exports = (function() {
var HasManySingleLinked = function(association, instance) {
var HasManySingleLinked = function(association, instance) {
this.association = association;
this.instance = instance;
this.target = this.association.target;
this.source = this.association.source;
};
};
HasManySingleLinked.prototype.injectGetter = function(options) {
HasManySingleLinked.prototype.injectGetter = function(options) {
var scopeWhere = this.association.scope ? {} : null;
if (this.association.scope) {
Object.keys(this.association.scope).forEach(function (attribute) {
......@@ -40,9 +39,9 @@ module.exports = (function() {
}
return model.all(options);
};
};
HasManySingleLinked.prototype.injectSetter = function(oldAssociations, newAssociations, defaultAttributes) {
HasManySingleLinked.prototype.injectSetter = function(oldAssociations, newAssociations, defaultAttributes) {
var self = this
, primaryKeys
, primaryKey
......@@ -120,9 +119,9 @@ module.exports = (function() {
}
return Utils.Promise.all(promises);
};
};
HasManySingleLinked.prototype.injectAdder = function(newAssociation, options) {
HasManySingleLinked.prototype.injectAdder = function(newAssociation, options) {
newAssociation.set(this.association.identifier, this.instance.get(this.instance.Model.primaryKeyAttribute));
if (this.association.scope) {
Object.keys(this.association.scope).forEach(function (attribute) {
......@@ -131,7 +130,6 @@ module.exports = (function() {
}
return newAssociation.save(options);
};
};
return HasManySingleLinked;
})();
module.exports = HasManySingleLinked;
......@@ -8,8 +8,7 @@ var Utils = require('./../utils')
, util = require('util')
, HasManySingleLinked = require('./has-many-single-linked');
module.exports = (function() {
var HasMany = function(source, target, options) {
var HasMany = function(source, target, options) {
Association.call(this);
this.associationType = 'HasMany';
......@@ -81,13 +80,13 @@ module.exports = (function() {
if (this.options.counterCache) {
new CounterCache(this, this.options.counterCache !== true ? this.options.counterCache : {});
}
};
};
util.inherits(HasMany, Association);
util.inherits(HasMany, Association);
// the id is in the target table
// or in an extra table which connects two tables
HasMany.prototype.injectAttributes = function() {
// the id is in the target table
// or in an extra table which connects two tables
HasMany.prototype.injectAttributes = function() {
this.identifier = this.foreignKey || Utils._.camelizeIf(
[
Utils._.underscoredIf(this.source.options.name.singular, this.source.options.underscored),
......@@ -115,9 +114,9 @@ module.exports = (function() {
Helpers.checkNamingCollision(this);
return this;
};
};
HasMany.prototype.injectGetter = function(obj) {
HasMany.prototype.injectGetter = function(obj) {
var association = this;
obj[this.accessors.get] = function(options) {
......@@ -188,9 +187,9 @@ module.exports = (function() {
};
return this;
};
};
HasMany.prototype.injectSetter = function(obj) {
HasMany.prototype.injectSetter = function(obj) {
var association = this
, primaryKeyAttribute = association.target.primaryKeyAttribute;
......@@ -340,9 +339,9 @@ module.exports = (function() {
};
return this;
};
};
HasMany.prototype.injectCreator = function(obj) {
HasMany.prototype.injectCreator = function(obj) {
var association = this;
obj[this.accessors.create] = function(values, options) {
......@@ -372,7 +371,6 @@ module.exports = (function() {
};
return this;
};
};
return HasMany;
})();
module.exports = HasMany;
......@@ -5,8 +5,7 @@ var Utils = require('./../utils')
, Association = require('./base')
, util = require('util');
module.exports = (function() {
var HasOne = function(srcModel, targetModel, options) {
var HasOne = function(srcModel, targetModel, options) {
Association.call(this);
this.associationType = 'HasOne';
......@@ -65,12 +64,12 @@ module.exports = (function() {
set: 'set' + singular,
create: 'create' + singular
};
};
};
util.inherits(HasOne, Association);
util.inherits(HasOne, Association);
// the id is in the target table
HasOne.prototype.injectAttributes = function() {
// the id is in the target table
HasOne.prototype.injectAttributes = function() {
var newAttributes = {}
, keyType = this.source.rawAttributes[this.sourceIdentifier].type;
......@@ -91,9 +90,9 @@ module.exports = (function() {
Helpers.checkNamingCollision(this);
return this;
};
};
HasOne.prototype.injectGetter = function(instancePrototype) {
HasOne.prototype.injectGetter = function(instancePrototype) {
var association = this;
instancePrototype[this.accessors.get] = function(options) {
......@@ -124,9 +123,9 @@ module.exports = (function() {
};
return this;
};
};
HasOne.prototype.injectSetter = function(instancePrototype) {
HasOne.prototype.injectSetter = function(instancePrototype) {
var association = this;
instancePrototype[this.accessors.set] = function(associatedInstance, options) {
......@@ -160,9 +159,9 @@ module.exports = (function() {
};
return this;
};
};
HasOne.prototype.injectCreator = function(instancePrototype) {
HasOne.prototype.injectCreator = function(instancePrototype) {
var association = this;
instancePrototype[this.accessors.create] = function(values, options) {
......@@ -176,7 +175,6 @@ module.exports = (function() {
};
return this;
};
};
return HasOne;
})();
module.exports = HasOne;
......@@ -2,8 +2,7 @@
var Utils = require('./../utils');
module.exports = {
checkNamingCollision: function (association) {
function checkNamingCollision (association) {
if (association.source.rawAttributes.hasOwnProperty(association.as)) {
throw new Error(
'Naming collision between attribute \'' + association.as +
......@@ -11,9 +10,9 @@ module.exports = {
'. To remedy this, change either foreignKey or as in your association definition'
);
}
},
}
addForeignKeyConstraints: function(newAttribute, source, target, options) {
function addForeignKeyConstraints (newAttribute, source, target, options) {
// FK constraints are opt-in: users must either set `foreignKeyConstraints`
// on the association, or request an `onDelete` or `onUpdate` behaviour
......@@ -44,6 +43,9 @@ module.exports = {
newAttribute.onUpdate = options.onUpdate;
}
}
}
}
module.exports = {
checkNamingCollision: checkNamingCollision,
addForeignKeyConstraints: addForeignKeyConstraints
};
......@@ -9,8 +9,12 @@ var Utils = require('../../utils')
, Dottie = require('dottie')
, uuid = require('node-uuid');
module.exports = (function() {
var QueryGenerator = {
/* istanbul ignore next */
var throwMethodUndefined = function(methodName) {
throw new Error('The method "' + methodName + '" is not defined! Please add it to your sql dialect.');
};
var QueryGenerator = {
options: {},
addSchema: function(param) {
......@@ -2061,12 +2065,6 @@ module.exports = (function() {
booleanValue: function(value) {
return value;
}
};
/* istanbul ignore next */
var throwMethodUndefined = function(methodName) {
throw new Error('The method "' + methodName + '" is not defined! Please add it to your sql dialect.');
};
};
return QueryGenerator;
})();
module.exports = QueryGenerator;
......@@ -6,8 +6,12 @@ var Utils = require('../../utils')
, Model = require('../../model')
, AbstractQueryGenerator = require('../abstract/query-generator');
module.exports = (function() {
var QueryGenerator = {
/* istanbul ignore next */
var throwMethodUndefined = function(methodName) {
throw new Error('The method "' + methodName + '" is not defined! Please add it to your sql dialect.');
};
var QueryGenerator = {
options: {},
dialect: 'mssql',
......@@ -595,17 +599,11 @@ module.exports = (function() {
booleanValue: function(value) {
return !!value ? 1 : 0;
}
};
};
// private methods
function wrapSingleQuote(identifier){
// private methods
function wrapSingleQuote(identifier){
return Utils.addTicks(identifier, "'");
}
/* istanbul ignore next */
var throwMethodUndefined = function(methodName) {
throw new Error('The method "' + methodName + '" is not defined! Please add it to your sql dialect.');
};
}
return Utils._.extend(Utils._.clone(AbstractQueryGenerator), QueryGenerator);
})();
module.exports = Utils._.extend(Utils._.clone(AbstractQueryGenerator), QueryGenerator);
......@@ -4,8 +4,7 @@ var Utils = require('../../utils')
, AbstractQuery = require('../abstract/query')
, sequelizeErrors = require('../../errors.js');
module.exports = (function() {
var Query = function(connection, sequelize, options) {
var Query = function(connection, sequelize, options) {
this.connection = connection;
this.instance = options.instance;
this.model = options.model;
......@@ -17,15 +16,15 @@ module.exports = (function() {
}, options || {});
this.checkLoggingOption();
};
};
Utils.inherit(Query, AbstractQuery);
Utils.inherit(Query, AbstractQuery);
Query.prototype.getInsertIdField = function() {
Query.prototype.getInsertIdField = function() {
return 'id';
};
};
Query.prototype.run = function(sql) {
Query.prototype.run = function(sql) {
var self = this;
this.sql = sql;
......@@ -84,9 +83,9 @@ module.exports = (function() {
});
return promise;
};
};
/**
/**
* High level function that handles the results of a query execution.
*
*
......@@ -102,7 +101,7 @@ module.exports = (function() {
*
* @param {Array} data - The result of the query execution.
*/
Query.prototype.formatResults = function(data) {
Query.prototype.formatResults = function(data) {
var result = this.instance;
if (this.isInsertQuery(data)) {
this.handleInsertQuery(data);
......@@ -155,18 +154,18 @@ module.exports = (function() {
}
return result;
};
};
Query.prototype.handleShowTablesQuery = function(results) {
Query.prototype.handleShowTablesQuery = function(results) {
return results.map(function(resultSet) {
return {
tableName: resultSet.TABLE_NAME,
schema: resultSet.TABLE_SCHEMA
};
});
};
};
Query.prototype.formatError = function (err) {
Query.prototype.formatError = function (err) {
var match;
match = err.message.match(/Violation of UNIQUE KEY constraint '((.|\s)*)'. Cannot insert duplicate key in object '.*'. The duplicate key value is \((.*)\)./);
match = match || err.message.match(/Cannot insert duplicate key row in object .* with unique index '(.*)'/);
......@@ -210,9 +209,9 @@ module.exports = (function() {
}
return new sequelizeErrors.DatabaseError(err);
};
};
Query.prototype.isShowOrDescribeQuery = function() {
Query.prototype.isShowOrDescribeQuery = function() {
var result = false;
result = result || (this.sql.toLowerCase().indexOf("select c.column_name as 'name', c.data_type as 'type', c.is_nullable as 'isnull'") === 0); /* jshint ignore: line */
......@@ -220,13 +219,13 @@ module.exports = (function() {
result = result || (this.sql.toLowerCase().indexOf('exec sys.sp_helpindex @objname') === 0);
return result;
};
};
Query.prototype.isShowIndexesQuery = function () {
Query.prototype.isShowIndexesQuery = function () {
return this.sql.toLowerCase().indexOf('exec sys.sp_helpindex @objname') === 0;
};
};
Query.prototype.handleShowIndexesQuery = function (data) {
Query.prototype.handleShowIndexesQuery = function (data) {
// Group by index name, and collect all fields
data = Utils._.foldl(data, function (acc, item) {
if (!(item.index_name in acc)) {
......@@ -261,9 +260,9 @@ module.exports = (function() {
type: undefined,
};
});
};
};
Query.prototype.handleInsertQuery = function(results, metaData) {
Query.prototype.handleInsertQuery = function(results, metaData) {
if (this.instance) {
// add the inserted row id to the instance
var autoIncrementField = this.model.autoIncrementField
......@@ -281,7 +280,6 @@ module.exports = (function() {
this.instance[autoIncrementField] = id;
}
};
};
return Query;
})();
module.exports = Query;
......@@ -3,8 +3,7 @@
var Utils = require('../../utils')
, DataTypes = require('../../data-types');
module.exports = (function() {
var QueryGenerator = {
var QueryGenerator = {
dialect: 'mysql',
createSchema: function() {
......@@ -372,7 +371,6 @@ module.exports = (function() {
dropForeignKeyQuery: function(tableName, foreignKey) {
return 'ALTER TABLE ' + this.quoteTable(tableName) + ' DROP FOREIGN KEY ' + this.quoteIdentifier(foreignKey) + ';';
}
};
};
return Utils._.extend(Utils._.clone(require('../abstract/query-generator')), QueryGenerator);
})();
module.exports = Utils._.extend(Utils._.clone(require('../abstract/query-generator')), QueryGenerator);
......@@ -5,8 +5,7 @@ var Utils = require('../../utils')
, uuid = require('node-uuid')
, sequelizeErrors = require('../../errors.js');
module.exports = (function() {
var Query = function(connection, sequelize, options) {
var Query = function(connection, sequelize, options) {
this.connection = connection;
this.instance = options.instance;
this.model = options.model;
......@@ -19,10 +18,10 @@ module.exports = (function() {
}, options || {});
this.checkLoggingOption();
};
};
Utils.inherit(Query, AbstractQuery);
Query.prototype.run = function(sql) {
Utils.inherit(Query, AbstractQuery);
Query.prototype.run = function(sql) {
var self = this;
this.sql = sql;
......@@ -41,7 +40,7 @@ module.exports = (function() {
});
return promise;
};
};
/**
* High level function that handles the results of a query execution.
......@@ -59,7 +58,7 @@ module.exports = (function() {
*
* @param {Array} data - The result of the query execution.
*/
Query.prototype.formatResults = function(data) {
Query.prototype.formatResults = function(data) {
var result = this.instance;
if (this.isInsertQuery(data)) {
......@@ -101,10 +100,10 @@ module.exports = (function() {
}
return result;
};
};
Query.prototype.formatError = function (err) {
Query.prototype.formatError = function (err) {
var match;
switch (err.errno || err.code) {
......@@ -157,9 +156,9 @@ module.exports = (function() {
default:
return new sequelizeErrors.DatabaseError(err);
}
};
};
Query.prototype.handleShowIndexesQuery = function (data) {
Query.prototype.handleShowIndexesQuery = function (data) {
// Group by index name, and collect all fields
data = Utils._.foldl(data, function (acc, item) {
if (!(item.Key_name in acc)) {
......@@ -187,7 +186,6 @@ module.exports = (function() {
type: item.Index_type,
};
});
};
};
return Query;
})();
module.exports = Query;
......@@ -2,15 +2,17 @@
var hstore = require('pg-hstore')({sanitize : true});
module.exports = {
stringify: function(data) {
if(data === null) return null;
function stringify (data) {
if (data === null) return null;
return hstore.stringify(data);
},
parse: function(value) {
if(value === null) return null;
}
function parse (value) {
if (value === null) return null;
return hstore.parse(value);
}
}
module.exports = {
stringify: stringify,
parse: parse
};
......@@ -10,8 +10,7 @@ var Utils = require('../../utils')
, AbstractQueryGenerator = require('../abstract/query-generator')
, primaryKeys = {};
module.exports = (function() {
var QueryGenerator = {
var QueryGenerator = {
options: {},
dialect: 'postgres',
......@@ -938,7 +937,6 @@ module.exports = (function() {
return AbstractQueryGenerator.setAutocommitQuery.call(this, value, options);
}
};
};
return Utils._.extend(Utils._.clone(AbstractQueryGenerator), QueryGenerator);
})();
module.exports = Utils._.extend(Utils._.clone(AbstractQueryGenerator), QueryGenerator);
......@@ -66,8 +66,7 @@ function dialectSpecificFieldDatatypeMap (options, prefix) {
return fields;
}
module.exports = (function() {
var Query = function(client, sequelize, options) {
var Query = function(client, sequelize, options) {
this.client = client;
this.sequelize = sequelize;
this.instance = options.instance;
......@@ -79,12 +78,12 @@ module.exports = (function() {
}, options || {});
this.checkLoggingOption();
};
Utils.inherit(Query, AbstractQuery);
};
Utils.inherit(Query, AbstractQuery);
Query.prototype.parseDialectSpecificFields = parseDialectSpecificFields;
Query.prototype.parseDialectSpecificFields = parseDialectSpecificFields;
Query.prototype.run = function(sql) {
Query.prototype.run = function(sql) {
this.sql = sql;
var self = this
......@@ -336,9 +335,9 @@ module.exports = (function() {
});
return promise;
};
};
Query.prototype.formatError = function (err) {
Query.prototype.formatError = function (err) {
var match
, table
, index
......@@ -420,15 +419,14 @@ module.exports = (function() {
default:
return new sequelizeErrors.DatabaseError(err);
}
};
};
Query.prototype.isForeignKeysQuery = function() {
Query.prototype.isForeignKeysQuery = function() {
return /SELECT conname as constraint_name, pg_catalog\.pg_get_constraintdef\(r\.oid, true\) as condef FROM pg_catalog\.pg_constraint r WHERE r\.conrelid = \(SELECT oid FROM pg_class WHERE relname = '.*' LIMIT 1\) AND r\.contype = 'f' ORDER BY 1;/.test(this.sql);
};
};
Query.prototype.getInsertIdField = function() {
Query.prototype.getInsertIdField = function() {
return 'id';
};
};
return Query;
})();
module.exports = Query;
......@@ -3,8 +3,7 @@
var Utils = require('../../utils'),
moment = require('moment');
module.exports = {
stringify: function (data) {
function stringify (data) {
if (data === null) return null;
if (!Utils._.isArray(data) || data.length !== 2) return '';
......@@ -26,8 +25,9 @@ module.exports = {
});
return (data.inclusive[0] ? '[' : '(') + JSON.stringify(data[0]) + ',' + JSON.stringify(data[1]) + (data.inclusive[1] ? ']' : ')');
},
parse: function (value, AttributeType) {
}
function parse (value, AttributeType) {
if (value === null) return null;
if(typeof AttributeType === 'function') AttributeType = new AttributeType();
......@@ -58,5 +58,9 @@ module.exports = {
result.inclusive = [(value[0] === '['), (value[value.length - 1] === ']')];
return result;
}
}
module.exports = {
stringify: stringify,
parse: parse
};
......@@ -11,8 +11,7 @@ var MySqlQueryGenerator = Utils._.extend(
Utils._.clone(require('../mysql/query-generator'))
);
module.exports = (function() {
var QueryGenerator = {
var QueryGenerator = {
options: {},
dialect: 'sqlite',
......@@ -437,7 +436,6 @@ module.exports = (function() {
var sql = 'PRAGMA foreign_key_list(<%= tableName %>)';
return Utils._.template(sql)({ tableName: tableName });
}
};
};
return Utils._.extend({}, MySqlQueryGenerator, QueryGenerator);
})();
module.exports = Utils._.extend({}, MySqlQueryGenerator, QueryGenerator);
......@@ -9,8 +9,8 @@ var Utils = require('../../utils')
@class QueryInterface
@static
*/
module.exports = {
/**
/**
A wrapper that fixes SQLite's inability to remove columns from existing tables.
It will create a backup of the table, drop the table afterwards and create a
new table with the same name but without the obsolete column.
......@@ -27,7 +27,7 @@ module.exports = {
@since 1.6.0
*/
removeColumn: function(tableName, attributeName, options) {
var removeColumn = function(tableName, attributeName, options) {
var self = this;
options = options || {};
......@@ -41,9 +41,9 @@ module.exports = {
return self.sequelize.query(subQuery + ';', { raw: true, logging: options.logging });
});
});
},
};
/**
/**
A wrapper that fixes SQLite's inability to change columns from existing tables.
It will create a backup of the table, drop the table afterwards and create a
new table with the same name but with a modified version of the respective column.
......@@ -60,7 +60,7 @@ module.exports = {
@since 1.6.0
*/
changeColumn: function(tableName, attributes, options) {
var changeColumn = function(tableName, attributes, options) {
var attributeName = Utils._.keys(attributes)[0]
, self = this;
options = options || {};
......@@ -75,9 +75,9 @@ module.exports = {
return self.sequelize.query(subQuery + ';', { raw: true, logging: options.logging });
});
});
},
};
/**
/**
A wrapper that fixes SQLite's inability to rename columns from existing tables.
It will create a backup of the table, drop the table afterwards and create a
new table with the same name but with a renamed version of the respective column.
......@@ -95,7 +95,7 @@ module.exports = {
@since 1.6.0
*/
renameColumn: function(tableName, attrNameBefore, attrNameAfter, options) {
var renameColumn = function(tableName, attrNameBefore, attrNameAfter, options) {
var self = this;
options = options || {};
......@@ -110,5 +110,10 @@ module.exports = {
return self.sequelize.query(subQuery + ';', { raw: true, logging: options.logging });
});
});
}
};
module.exports = {
removeColumn: removeColumn,
changeColumn: changeColumn,
renameColumn: renameColumn
};
\ No newline at end of file
......@@ -5,8 +5,7 @@ var Utils = require('../../utils')
, QueryTypes = require('../../query-types')
, sequelizeErrors = require('../../errors.js');
module.exports = (function() {
var Query = function(database, sequelize, options) {
var Query = function(database, sequelize, options) {
this.database = database;
this.sequelize = sequelize;
this.instance = options.instance;
......@@ -18,14 +17,14 @@ module.exports = (function() {
}, options || {});
this.checkLoggingOption();
};
Utils.inherit(Query, AbstractQuery);
};
Utils.inherit(Query, AbstractQuery);
Query.prototype.getInsertIdField = function() {
Query.prototype.getInsertIdField = function() {
return 'lastID';
};
};
Query.prototype.run = function(sql) {
Query.prototype.run = function(sql) {
var self = this
, promise;
......@@ -179,9 +178,9 @@ module.exports = (function() {
});
return promise;
};
};
Query.prototype.formatError = function (err) {
Query.prototype.formatError = function (err) {
var match;
switch (err.code) {
......@@ -241,9 +240,9 @@ module.exports = (function() {
default:
return new sequelizeErrors.DatabaseError(err);
}
};
};
Query.prototype.handleShowIndexesQuery = function (data) {
Query.prototype.handleShowIndexesQuery = function (data) {
var self = this;
// Sqlite returns indexes so the one that was defined last is returned first. Lets reverse that!
......@@ -264,9 +263,9 @@ module.exports = (function() {
return item;
});
});
};
};
Query.prototype.getDatabaseMethod = function() {
Query.prototype.getDatabaseMethod = function() {
if (this.isUpsertQuery()) {
return 'exec'; // Needed to run multiple queries in one
} else if (this.isInsertQuery() || this.isUpdateQuery() || this.isBulkUpdateQuery() || (this.sql.toLowerCase().indexOf('CREATE TEMPORARY TABLE'.toLowerCase()) !== -1) || this.options.type === QueryTypes.BULKDELETE) {
......@@ -274,7 +273,6 @@ module.exports = (function() {
} else {
return 'all';
}
};
};
return Query;
})();
module.exports = Query;
......@@ -4,28 +4,27 @@ var Toposort = require('toposort-class')
, Utils = require('./utils')
, _ = require('lodash');
module.exports = (function() {
var ModelManager = function(sequelize) {
var ModelManager = function(sequelize) {
this.models = [];
this.sequelize = sequelize;
};
};
ModelManager.prototype.addModel = function(model) {
ModelManager.prototype.addModel = function(model) {
this.models.push(model);
this.sequelize.models[model.name] = model;
return model;
};
};
ModelManager.prototype.removeModel = function(model) {
ModelManager.prototype.removeModel = function(model) {
this.models = this.models.filter(function($model) {
return $model.name !== model.name;
});
delete this.sequelize.models[model.name];
};
};
ModelManager.prototype.getModel = function(against, options) {
ModelManager.prototype.getModel = function(against, options) {
options = _.defaults(options || {}, {
attribute: 'name'
});
......@@ -35,18 +34,18 @@ module.exports = (function() {
});
return !!model ? model[0] : null;
};
};
ModelManager.prototype.__defineGetter__('all', function() {
ModelManager.prototype.__defineGetter__('all', function() {
return this.models;
});
});
/**
/**
* Iterate over Models in an order suitable for e.g. creating tables. Will
* take foreign key constraints into account so that dependencies are visited
* before dependents.
*/
ModelManager.prototype.forEachModel = function(iterator, options) {
ModelManager.prototype.forEachModel = function(iterator, options) {
var models = {}
, sorter = new Toposort()
, sorted
......@@ -97,7 +96,6 @@ module.exports = (function() {
sorted.forEach(function(name) {
iterator(models[name], name);
});
};
};
return ModelManager;
})();
module.exports = ModelManager;
This diff could not be displayed because it is too large.
'use strict';
module.exports = (function() {
var Attribute = function(options) {
var Attribute = function(options) {
if (options.type === undefined) options = {type: options};
this.type = options.type;
};
};
return Attribute;
})();
module.exports = Attribute;
......@@ -5,8 +5,7 @@ var Utils = require('./../utils')
, DataTypes = require('../data-types')
, Promise = require('bluebird');
module.exports = (function() {
var CounterCache = function(association, options) {
var CounterCache = function(association, options) {
this.association = association;
this.source = association.source;
this.target = association.target;
......@@ -32,10 +31,10 @@ module.exports = (function() {
this.injectAttributes();
this.injectHooks();
};
};
// Add countAssociation attribute to source model
CounterCache.prototype.injectAttributes = function() {
// Add countAssociation attribute to source model
CounterCache.prototype.injectAttributes = function() {
// Do not try to use a column that's already taken
Helpers.checkNamingCollision(this);
......@@ -54,10 +53,10 @@ module.exports = (function() {
// Sync attributes and setters/getters to DAO prototype
this.source.refreshAttributes();
};
};
// Add setAssociaton method to the prototype of the model instance
CounterCache.prototype.injectHooks = function() {
// Add setAssociaton method to the prototype of the model instance
CounterCache.prototype.injectHooks = function() {
var association = this.association,
counterCacheInstance = this,
CounterUtil,
......@@ -173,7 +172,6 @@ module.exports = (function() {
association.target.addHook('afterUpdate', atomicHooks.update);
association.target.addHook('afterDestroy', atomicHooks.destroy);
}
};
};
return CounterCache;
})();
module.exports = CounterCache;
......@@ -3,7 +3,7 @@
var DataTypes = require('./data-types')
, SqlString = require('./sql-string')
, lodash = require('lodash')
, ParameterValidator = require('./utils/parameter-validator')
, parameterValidator = require('./utils/parameter-validator')
, inflection = require('inflection')
, dottie = require('dottie')
, uuid = require('node-uuid')
......@@ -398,9 +398,7 @@ var Utils = module.exports = {
this.logic = logic;
},
validateParameter: function(value, expectation, options) {
return ParameterValidator.check(value, expectation, options);
},
validateParameter: parameterValidator,
formatReferences: function (obj) {
if (!lodash.isPlainObject(obj.references)) {
......
......@@ -3,7 +3,7 @@
var _ = require('lodash');
var util = require('util');
var validateDeprecation = function(value, expectation, options) {
function validateDeprecation (value, expectation, options) {
if (!options.deprecated) {
return;
}
......@@ -17,9 +17,9 @@ var validateDeprecation = function(value, expectation, options) {
}
return valid;
};
}
var validate = function(value, expectation) {
function validate (value, expectation) {
// the second part of this check is a workaround to deal with an issue that occurs in node-webkit when
// using object literals. https://github.com/sequelize/sequelize/issues/2685
if (value instanceof expectation || Object.prototype.toString.call(value) === Object.prototype.toString.call(expectation.call())) {
......@@ -27,10 +27,9 @@ var validate = function(value, expectation) {
}
throw new Error(util.format('The parameter (value: %s) is no %s.', value, expectation.name));
};
}
module.exports = {
check: function(value, expectation, options) {
function check (value, expectation, options) {
options = _.extend({
deprecated: false,
index: null,
......@@ -53,5 +52,6 @@ module.exports = {
return false
|| validateDeprecation(value, expectation, options)
|| validate(value, expectation, options);
}
};
}
module.exports = check;
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!