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

Commit 129fc898 by Mick Hansen

Merge branch 'master' of github.com:sequelize/sequelize

Conflicts:
	lib/instance.js
2 parents 222fb13c fbfbde3a
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
- [FEATURE] add `clone: true` support to `.get()`. Is needed when using `delete` on values from a `.get()` (`toJSON()`, `this.values`). (.get() is just a reference to the values for performance reasons when there's no custom getters or includes) - [FEATURE] add `clone: true` support to `.get()`. Is needed when using `delete` on values from a `.get()` (`toJSON()`, `this.values`). (.get() is just a reference to the values for performance reasons when there's no custom getters or includes)
- [FEATURE] add `sequelize.escape(value)` convenience method - [FEATURE] add `sequelize.escape(value)` convenience method
- [BUG] Fixes crash with `findAll({include: [Model], order: sequelize.literal()})` - [BUG] Fixes crash with `findAll({include: [Model], order: sequelize.literal()})`
- [FEATURE] Now possible to pass createdAt and updatedAt values to Model.create when using silent: true (when importing datasets with existing timestamps) - [FEATURE] Now possible to pass `createdAt` and `updatedAt` values to `Model.create`/`Model.bulkCreate` when using silent: true (when importing datasets with existing timestamps)
# 2.0.0-rc6 # 2.0.0-rc6
- [BUG] Fixed issue with including by association reference and where - [BUG] Fixed issue with including by association reference and where
......
...@@ -45,7 +45,7 @@ var sequelize = new Sequelize('mysql://localhost:3306/database', {}) ...@@ -45,7 +45,7 @@ var sequelize = new Sequelize('mysql://localhost:3306/database', {})
| [username=null] | String | The username which is used to authenticate against the database. | | [username=null] | String | The username which is used to authenticate against the database. |
| [password=null] | String | The password which is used to authenticate against the database. | | [password=null] | String | The password which is used to authenticate against the database. |
| [options={}] | Object | An object with options. | | [options={}] | Object | An object with options. |
| [options.dialect='mysql'] | String | The dialect you of the database you are connecting to. One of mysql, postgres, sqlite and mariadb | | [options.dialect='mysql'] | String | The dialect you of the database you are connecting to. One of mysql, postgres, sqlite, mariadb, and mssql |
| [options.dialectModulePath=null] | String | If specified, load the dialect library from this path. For example, if you want to use pg.js instead of pg when connecting to a pg database, you should specify 'pg.js' here | | [options.dialectModulePath=null] | String | If specified, load the dialect library from this path. For example, if you want to use pg.js instead of pg when connecting to a pg database, you should specify 'pg.js' here |
| [options.dialectOptions] | Object | An object of additional options, which are passed directly to the connection library | | [options.dialectOptions] | Object | An object of additional options, which are passed directly to the connection library |
| [options.storage] | String | Only used by sqlite. Defaults to ':memory:' | | [options.storage] | String | Only used by sqlite. Defaults to ':memory:' |
......
...@@ -45,7 +45,7 @@ Open the created directory in your favorite text editor and add a new file calle ...@@ -45,7 +45,7 @@ Open the created directory in your favorite text editor and add a new file calle
```js ```js
var Sequelize = require('sequelize') var Sequelize = require('sequelize')
, sequelize = new Sequelize('database_name', 'username', 'password', { , sequelize = new Sequelize('database_name', 'username', 'password', {
dialect: "mysql", // or 'sqlite', 'postgres', 'mariadb' dialect: "mysql", // or 'sqlite', 'postgres', 'mariadb', 'mssql'
port: 3306, // or 5432 (for postgres) port: 3306, // or 5432 (for postgres)
}); });
......
...@@ -17,7 +17,7 @@ Sequelize will setup a connection pool on initialization so you should ideally o ...@@ -17,7 +17,7 @@ Sequelize will setup a connection pool on initialization so you should ideally o
```js ```js
var sequelize = new Sequelize('database', 'username', 'password', { var sequelize = new Sequelize('database', 'username', 'password', {
host: 'localhost', host: 'localhost',
dialect: 'mysql'|'mariadb'|'sqlite'|'postgres' dialect: 'mysql'|'mariadb'|'sqlite'|'postgres'|'mssql'
}); });
// Or you can simply use a connection uri // Or you can simply use a connection uri
......
...@@ -56,12 +56,12 @@ var sequelize = new Sequelize('database', 'username', 'password', { ...@@ -56,12 +56,12 @@ var sequelize = new Sequelize('database', 'username', 'password', {
   
// the sql dialect of the database // the sql dialect of the database
// - default is 'mysql' // - default is 'mysql'
// - currently supported: 'mysql', 'sqlite', 'postgres', 'mariadb' // - currently supported: 'mysql', 'sqlite', 'postgres', 'mariadb', 'mssql'
dialect: 'mysql', dialect: 'mysql',
   
// you can also pass any dialect options to the underlying dialect library // you can also pass any dialect options to the underlying dialect library
// - default is empty // - default is empty
// - currently supported: 'mysql', 'mariadb' // - currently supported: 'mysql', 'mariadb', 'postgres', 'mssql'
dialectOptions: { dialectOptions: {
socketPath: '/Applications/MAMP/tmp/mysql/mysql.sock', socketPath: '/Applications/MAMP/tmp/mysql/mysql.sock',
supportBigNumbers: true, supportBigNumbers: true,
......
Sequelize is a promise-based Node.js ORM for Postgres, MySQL, SQLite and MariaDB. It features solid transaction support, relations, read replication and more. Sequelize is a promise-based Node.js ORM for Postgres, MySQL, SQLite, MariaDB and MSSQL. It features solid transaction support, relations, read replication and more.
[Installation](http://sequelize.readthedocs.org/en/latest/docs/installation/) [Installation](http://sequelize.readthedocs.org/en/latest/docs/installation/)
......
...@@ -275,7 +275,7 @@ module.exports = (function() { ...@@ -275,7 +275,7 @@ module.exports = (function() {
field + ' must be unique', 'unique violation', field, value)); field + ' must be unique', 'unique violation', field, value));
}); });
if (this.callee.__options && this.callee.__options.uniqueKeys) { if (this.callee && this.callee.__options && this.callee.__options.uniqueKeys) {
Utils._.forOwn(this.callee.__options.uniqueKeys, function(constraint) { Utils._.forOwn(this.callee.__options.uniqueKeys, function(constraint) {
if (Utils._.isEqual(constraint.fields, Object.keys(fields)) && !!constraint.msg) { if (Utils._.isEqual(constraint.fields, Object.keys(fields)) && !!constraint.msg) {
message = constraint.msg; message = constraint.msg;
......
...@@ -553,7 +553,7 @@ module.exports = (function() { ...@@ -553,7 +553,7 @@ module.exports = (function() {
if (self.isNewRecord) { if (self.isNewRecord) {
query = 'insert'; query = 'insert';
args = [self, self.QueryInterface.QueryGenerator.addSchema(self.Model), values, options]; args = [self, self.Model.getTableName(options), values, options];
hook = 'Create'; hook = 'Create';
} else { } else {
var identifier = self.primaryKeyValues; var identifier = self.primaryKeyValues;
...@@ -574,7 +574,7 @@ module.exports = (function() { ...@@ -574,7 +574,7 @@ module.exports = (function() {
} }
query = 'update'; query = 'update';
args = [self, self.QueryInterface.QueryGenerator.addSchema(self.Model), values, identifier, options]; args = [self, self.Model.getTableName(options), values, identifier, options];
hook = 'Update'; hook = 'Update';
} }
...@@ -613,8 +613,8 @@ module.exports = (function() { ...@@ -613,8 +613,8 @@ module.exports = (function() {
} }
// Field name mapping // Field name mapping
if (this.Model.rawAttributes[attr].field && this.Model.rawAttributes[attr].field !== attr) { if (self.Model.rawAttributes[attr] && self.Model.rawAttributes[attr].field && self.Model.rawAttributes[attr].field !== attr) {
values[this.Model.rawAttributes[attr].field] = values[attr]; values[self.Model.rawAttributes[attr].field] = values[attr];
delete values[attr]; delete values[attr];
} }
}, this); }, this);
...@@ -758,7 +758,7 @@ module.exports = (function() { ...@@ -758,7 +758,7 @@ module.exports = (function() {
} else { } else {
where = {}; where = {};
where[self.Model.rawAttributes[self.Model.primaryKeyAttribute].field] = self.get(self.Model.primaryKeyAttribute, {raw: true}); where[self.Model.rawAttributes[self.Model.primaryKeyAttribute].field] = self.get(self.Model.primaryKeyAttribute, {raw: true});
return self.QueryInterface.delete(self, self.QueryInterface.QueryGenerator.addSchema(self.Model), where, _.defaults(options, {limit: null})); return self.QueryInterface.delete(self, self.Model.getTableName(options), where, _.defaults(options, {limit: null}));
} }
}).tap(function(result) { }).tap(function(result) {
// Run after hook // Run after hook
...@@ -866,7 +866,7 @@ module.exports = (function() { ...@@ -866,7 +866,7 @@ module.exports = (function() {
countOrOptions.attributes[updatedAtAttr] = this.Model.__getTimestamp(updatedAtAttr); countOrOptions.attributes[updatedAtAttr] = this.Model.__getTimestamp(updatedAtAttr);
} }
return this.QueryInterface.increment(this, this.QueryInterface.QueryGenerator.addSchema(this.Model), values, where, countOrOptions); return this.QueryInterface.increment(this, this.Model.getTableName(countOrOptions), values, where, countOrOptions);
}; };
/** /**
......
...@@ -389,9 +389,9 @@ module.exports = (function() { ...@@ -389,9 +389,9 @@ module.exports = (function() {
return self.drop(options); return self.drop(options);
} }
}).then(function () { }).then(function () {
return self.QueryInterface.createTable(self.getTableName(), attributes, options); return self.QueryInterface.createTable(self.getTableName(options), attributes, options);
}).then(function () { }).then(function () {
return self.QueryInterface.showIndex(self.getTableName(), options); return self.QueryInterface.showIndex(self.getTableName(options), options);
}).then(function (indexes) { }).then(function (indexes) {
// Assign an auto-generated name to indexes which are not named by the user // Assign an auto-generated name to indexes which are not named by the user
self.options.indexes = self.QueryInterface.nameIndexes(self.options.indexes, self.tableName); self.options.indexes = self.QueryInterface.nameIndexes(self.options.indexes, self.tableName);
...@@ -403,7 +403,7 @@ module.exports = (function() { ...@@ -403,7 +403,7 @@ module.exports = (function() {
}); });
return Promise.map(indexes, function (index) { return Promise.map(indexes, function (index) {
return self.QueryInterface.addIndex(self.getTableName(), index.fields, index, self.tableName); return self.QueryInterface.addIndex(self.getTableName(options), index.fields, index, self.tableName);
}); });
}).return(this); }).return(this);
}; };
...@@ -415,7 +415,7 @@ module.exports = (function() { ...@@ -415,7 +415,7 @@ module.exports = (function() {
* @return {Promise} * @return {Promise}
*/ */
Model.prototype.drop = function(options) { Model.prototype.drop = function(options) {
return this.QueryInterface.dropTable(this.getTableName(), options); return this.QueryInterface.dropTable(this.getTableName(options), options);
}; };
Model.prototype.dropSchema = function(schema) { Model.prototype.dropSchema = function(schema) {
...@@ -454,7 +454,7 @@ module.exports = (function() { ...@@ -454,7 +454,7 @@ module.exports = (function() {
* @param {Object} options The hash of options from any query. You can use one model to access tables with matching schemas by overriding `getTableName` and using custom key/values to alter the name of the table. (eg. subscribers_1, subscribers_2) * @param {Object} options The hash of options from any query. You can use one model to access tables with matching schemas by overriding `getTableName` and using custom key/values to alter the name of the table. (eg. subscribers_1, subscribers_2)
* @return {String|Object} * @return {String|Object}
*/ */
Model.prototype.getTableName = function() { Model.prototype.getTableName = function(options) {
return this.QueryGenerator.addSchema(this); return this.QueryGenerator.addSchema(this);
}; };
...@@ -676,7 +676,7 @@ module.exports = (function() { ...@@ -676,7 +676,7 @@ module.exports = (function() {
var hasJoin = false var hasJoin = false
, tableNames = { }; , tableNames = { };
tableNames[this.getTableName()] = true; tableNames[this.getTableName(options)] = true;
options = optClone(options || {}); options = optClone(options || {});
options = Utils._.defaults(options, { options = Utils._.defaults(options, {
...@@ -725,7 +725,7 @@ module.exports = (function() { ...@@ -725,7 +725,7 @@ module.exports = (function() {
return this.runHooks('beforeFindAfterOptions', options); return this.runHooks('beforeFindAfterOptions', options);
} }
}).then(function() { }).then(function() {
return this.QueryInterface.select(this, this.getTableName(), options, Utils._.defaults({ return this.QueryInterface.select(this, this.getTableName(options), options, Utils._.defaults({
type: QueryTypes.SELECT, type: QueryTypes.SELECT,
hasJoin: hasJoin, hasJoin: hasJoin,
tableNames: Object.keys(tableNames) tableNames: Object.keys(tableNames)
...@@ -744,7 +744,7 @@ module.exports = (function() { ...@@ -744,7 +744,7 @@ module.exports = (function() {
// whereCollection is used for non-primary key updates // whereCollection is used for non-primary key updates
this.options.whereCollection = options.where || null; this.options.whereCollection = options.where || null;
return this.QueryInterface.select(this, [[this.getTableName(), this.name], joinTableName], options, Utils._.defaults({ return this.QueryInterface.select(this, [[this.getTableName(options), this.name], joinTableName], options, Utils._.defaults({
type: QueryTypes.SELECT type: QueryTypes.SELECT
}, queryOptions, { transaction: (options || {}).transaction })); }, queryOptions, { transaction: (options || {}).transaction }));
}; };
...@@ -817,7 +817,7 @@ module.exports = (function() { ...@@ -817,7 +817,7 @@ module.exports = (function() {
options = paranoidClause.call(this, options); options = paranoidClause.call(this, options);
return this.QueryInterface.rawSelect(this.getTableName(), options, aggregateFunction, this); return this.QueryInterface.rawSelect(this.getTableName(options), options, aggregateFunction, this);
}; };
/** /**
...@@ -1216,7 +1216,7 @@ module.exports = (function() { ...@@ -1216,7 +1216,7 @@ module.exports = (function() {
delete values[this.primaryKeyField]; delete values[this.primaryKeyField];
} }
return this.QueryInterface.upsert(this.getTableName(), values, this, options); return this.QueryInterface.upsert(this.getTableName(options), values, this, options);
}; };
Model.prototype.insertOrUpdate = Model.prototype.upsert; Model.prototype.insertOrUpdate = Model.prototype.upsert;
...@@ -1378,7 +1378,7 @@ module.exports = (function() { ...@@ -1378,7 +1378,7 @@ module.exports = (function() {
} }
// Insert all records at once // Insert all records at once
return self.QueryInterface.bulkInsert(self.getTableName(), records, options, attributes); return self.QueryInterface.bulkInsert(self.getTableName(options), records, options, attributes);
} }
}).then(function() { }).then(function() {
// Run after hook // Run after hook
...@@ -1440,9 +1440,9 @@ module.exports = (function() { ...@@ -1440,9 +1440,9 @@ module.exports = (function() {
if (self._timestampAttributes.deletedAt && !options.force) { if (self._timestampAttributes.deletedAt && !options.force) {
var attrValueHash = {}; var attrValueHash = {};
attrValueHash[self._timestampAttributes.deletedAt] = Utils.now(self.modelManager.sequelize.options.dialect); attrValueHash[self._timestampAttributes.deletedAt] = Utils.now(self.modelManager.sequelize.options.dialect);
return self.QueryInterface.bulkUpdate(self.getTableName(), attrValueHash, options.where, options, self.rawAttributes); return self.QueryInterface.bulkUpdate(self.getTableName(options), attrValueHash, options.where, options, self.rawAttributes);
} else { } else {
return self.QueryInterface.bulkDelete(self.getTableName(), options.where, options, self); return self.QueryInterface.bulkDelete(self.getTableName(options), options.where, options, self);
} }
}).tap(function() { }).tap(function() {
// Run afterDestroy hook on each record individually // Run afterDestroy hook on each record individually
...@@ -1509,7 +1509,7 @@ module.exports = (function() { ...@@ -1509,7 +1509,7 @@ module.exports = (function() {
var attrValueHash = {}; var attrValueHash = {};
attrValueHash[self._timestampAttributes.deletedAt] = null; attrValueHash[self._timestampAttributes.deletedAt] = null;
options.omitNull = false; options.omitNull = false;
return self.QueryInterface.bulkUpdate(self.getTableName(), attrValueHash, options.where, options, self._timestampAttributes.deletedAt); return self.QueryInterface.bulkUpdate(self.getTableName(options), attrValueHash, options.where, options, self._timestampAttributes.deletedAt);
}).tap(function() { }).tap(function() {
// Run afterDestroy hook on each record individually // Run afterDestroy hook on each record individually
if (options.individualHooks) { if (options.individualHooks) {
...@@ -1673,7 +1673,7 @@ module.exports = (function() { ...@@ -1673,7 +1673,7 @@ module.exports = (function() {
mapFieldNames.call(self, options, self); mapFieldNames.call(self, options, self);
// Run query to update all rows // Run query to update all rows
return self.QueryInterface.bulkUpdate(self.getTableName(), valuesUse, options.where, options, self.tableAttributes).then(function(affectedRows) { return self.QueryInterface.bulkUpdate(self.getTableName(options), valuesUse, options.where, options, self.tableAttributes).then(function(affectedRows) {
if (options.returning) { if (options.returning) {
daos = affectedRows; daos = affectedRows;
return [affectedRows.length, affectedRows]; return [affectedRows.length, affectedRows];
...@@ -1726,7 +1726,7 @@ module.exports = (function() { ...@@ -1726,7 +1726,7 @@ module.exports = (function() {
// Object lookups will force any variable to strings, we don't want that for special objects etc // Object lookups will force any variable to strings, we don't want that for special objects etc
if (typeof attr !== "string") return attr; if (typeof attr !== "string") return attr;
// Map attributes to aliased syntax attributes // Map attributes to aliased syntax attributes
if (attr !== Model.rawAttributes[attr].field) { if (Model.rawAttributes[attr] && attr !== Model.rawAttributes[attr].field) {
return [Model.rawAttributes[attr].field, attr]; return [Model.rawAttributes[attr].field, attr];
} }
return attr; return attr;
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!