sequelize
Advanced tools
Comparing version 1.2.0 to 1.2.1
@@ -116,1 +116,7 @@ # v0.1.0 # | ||
# v1.2.1 # | ||
- [REFACTORING] renamed the global options for sync, query and define on sequelize; before: options.queryOptions; now: options.query | ||
- [FEATURE] allow definition of charset via global define option in sequelize or via charset option in sequelize.define | ||
- [FEATURE] allow definition of mysql engine via global define option in sequelize or via engine option in sequelize.define; default is InnoDB now | ||
- [FEATURE] find and findAll will now search in a list of values via: Model.findAll({where: { id: [1,2,3] }}); will return all models with id 1, 2 and 3 | ||
- [TEST] force latin1 charset for travis |
@@ -71,7 +71,7 @@ var Utils = require("./utils") | ||
ModelDefinition.prototype.sync = function(options) { | ||
options = options || {} | ||
options = Utils.merge(options || {}, this.options) | ||
var self = this | ||
var doQuery = function() { | ||
self.query(QueryGenerator.createTableQuery(self.tableName, self.attributes)) | ||
self.query(QueryGenerator.createTableQuery(self.tableName, self.attributes, options)) | ||
.on('success', function() { self.emit('success', self) }) | ||
@@ -113,3 +113,3 @@ .on('failure', function(err) { self.emit('failure', err) }) | ||
var self = this | ||
var emitter = new Utils.CustomEventEmitter(function() { | ||
@@ -124,3 +124,3 @@ self.query(QueryGenerator.maxQuery(self.tableName, field,options), self, {plain: true}).on('success', function(obj) { | ||
var self = this | ||
var emitter = new Utils.CustomEventEmitter(function() { | ||
@@ -127,0 +127,0 @@ self.query(QueryGenerator.minQuery(self.tableName, field,options), self, {plain: true}).on('success', function(obj) { |
@@ -10,4 +10,4 @@ var Utils = require("./utils") | ||
options = options || {} | ||
var query = "CREATE TABLE IF NOT EXISTS <%= table %> (<%= attributes%>);" | ||
var query = "CREATE TABLE IF NOT EXISTS <%= table %> (<%= attributes%>) ENGINE=<%= engine %> <%= charset %>" | ||
, primaryKeys = [] | ||
@@ -23,18 +23,23 @@ , attrStr = Utils._.map(attributes, function(dataType, attr) { | ||
}).join(", ") | ||
, values = {table: Utils.addTicks(tableName), attributes: attrStr} | ||
, values = { | ||
table: Utils.addTicks(tableName), | ||
attributes: attrStr, | ||
engine: options.engine || 'InnoDB', | ||
charset: (options.charset ? "DEFAULT CHARSET=" + options.charset : "") | ||
} | ||
, pkString = primaryKeys.map(function(pk) {return Utils.addTicks(pk)}).join(", ") | ||
if (pkString.length > 0) values.attributes += ", PRIMARY KEY (" + pkString + ")" | ||
return Utils._.template(query)(values) | ||
if(pkString.length > 0) values.attributes += ", PRIMARY KEY (" + pkString + ")" | ||
return Utils._.template(query)(values).trim() + ";" | ||
}, | ||
dropTableQuery: function(tableName, options) { | ||
options = options || {} | ||
var query = "DROP TABLE IF EXISTS <%= table %>;" | ||
return Utils._.template(query)({table: Utils.addTicks(tableName)}) | ||
}, | ||
/* | ||
@@ -44,3 +49,3 @@ Returns a query for selecting elements in the database <tableName>. | ||
- attributes -> An array of attributes (e.g. ['name', 'birthday']). Default: * | ||
- where -> A hash with conditions (e.g. {name: 'foo'}) | ||
- where -> A hash with conditions (e.g. {name: 'foo'}) | ||
OR an ID as integer | ||
@@ -59,5 +64,5 @@ OR a string with conditions (e.g. 'name="foo"'). | ||
options.attributes = options.attributes || '*' | ||
var query = "SELECT <%= attributes %> FROM <%= table %>" | ||
if(options.where) { | ||
@@ -76,3 +81,3 @@ options.where = QueryGenerator.getWhereConditions(options.where) | ||
} | ||
query += ";" | ||
@@ -82,3 +87,3 @@ | ||
}, | ||
countQuery: function(tableName, options) { | ||
@@ -98,3 +103,3 @@ return QueryGenerator.selectQuery(tableName, options).replace("*", "count(*)") | ||
var query = "INSERT INTO <%= table %> (<%= attributes %>) VALUES (<%= values %>);" | ||
var replacements = { | ||
@@ -107,3 +112,3 @@ table: Utils.addTicks(tableName), | ||
} | ||
return Utils._.template(query)(replacements) | ||
@@ -117,3 +122,3 @@ }, | ||
- values -> A hash with attribute-value-pairs | ||
- where -> A hash with conditions (e.g. {name: 'foo'}) | ||
- where -> A hash with conditions (e.g. {name: 'foo'}) | ||
OR an ID as integer | ||
@@ -132,6 +137,6 @@ OR a string with conditions (e.g. 'name="foo"'). | ||
} | ||
return Utils._.template(query)(replacements) | ||
}, | ||
/* | ||
@@ -141,3 +146,3 @@ Returns a deletion query. | ||
- tableName -> Name of the table | ||
- where -> A hash with conditions (e.g. {name: 'foo'}) | ||
- where -> A hash with conditions (e.g. {name: 'foo'}) | ||
OR an ID as integer | ||
@@ -152,3 +157,3 @@ OR a string with conditions (e.g. 'name="foo"'). | ||
options.limit = options.limit || 1 | ||
var query = "DELETE FROM <%= table %> WHERE <%= where %> LIMIT <%= limit %>" | ||
@@ -160,6 +165,6 @@ var replacements = { | ||
} | ||
return Utils._.template(query)(replacements) | ||
}, | ||
/* | ||
@@ -170,3 +175,3 @@ Takes something and transforms it into values of a where condition. | ||
var result = null | ||
if(Utils.isHash(smth)) | ||
@@ -183,3 +188,3 @@ result = QueryGenerator.hashToWhereConditions(smth) | ||
}, | ||
/* | ||
@@ -191,8 +196,17 @@ Takes a hash and transforms it into a mysql where condition: {key: value, key2: value2} ==> key=value AND key2=value2 | ||
return Utils._.map(hash, function(value, key) { | ||
var _value = Utils.escape(value) | ||
, _key = Utils.addTicks(key) | ||
var _key = Utils.addTicks(key) | ||
, _value = null | ||
return (_value == 'NULL') ? _key + " IS NULL" : [_key, _value].join("=") | ||
if(Array.isArray(value)) { | ||
_value = "(" + Utils._.map(value, function(subvalue) { | ||
return Utils.escape(subvalue); | ||
}).join(',') + ")" | ||
return [_key, _value].join(" IN ") | ||
} else { | ||
_value = Utils.escape(value) | ||
return (_value == 'NULL') ? _key + " IS NULL" : [_key, _value].join("=") | ||
} | ||
}).join(" AND ") | ||
} | ||
} | ||
} |
@@ -10,3 +10,5 @@ var Utils = require("./utils") | ||
Utils._.reject(options, function(_, key) { return ["host", "port", "disableTableNameModification"].indexOf(key) > -1 }) | ||
Utils._.reject(options, function(_, key) { | ||
return ["host", "port", "disableTableNameModification"].indexOf(key) > -1 | ||
}) | ||
@@ -31,3 +33,4 @@ this.options = options | ||
if(this.options.defineOptions) options = Sequelize.Utils.merge(options, this.options.defineOptions) | ||
if(this.options.define) | ||
options = Sequelize.Utils.merge(options, this.options.define) | ||
@@ -47,3 +50,4 @@ var model = this.modelManager.addModel(new ModelDefinition(modelName, attributes, options)) | ||
if(this.options.queryOptions) options = Sequelize.Utils.merge(options, this.options.queryOptions) | ||
if(this.options.query) | ||
options = Sequelize.Utils.merge(options, this.options.query) | ||
@@ -58,3 +62,4 @@ options.logging = this.options.hasOwnProperty('logging') ? this.options.logging : true | ||
if(this.options.syncOptions) options = Sequelize.Utils.merge(options, this.options.syncOptions) | ||
if(this.options.sync) | ||
options = Sequelize.Utils.merge(options, this.options.sync) | ||
@@ -61,0 +66,0 @@ var self = this |
{ | ||
"name": "sequelize", | ||
"description": "MySQL ORM for Node.JS", | ||
"version": "1.2.0", | ||
"version": "1.2.1", | ||
"author": "Sascha Depold <sascha@depold.com>", | ||
@@ -17,4 +17,3 @@ "contributors": [ | ||
"jasmine-node": "=1.0.12", | ||
"expresso": "=0.9.2", | ||
"should": "=0.3.2" | ||
"expresso": "=0.9.2" | ||
}, | ||
@@ -21,0 +20,0 @@ "keywords": ["mysql", "orm", "nodejs", "object relational mapper"], |
@@ -17,4 +17,4 @@ # Sequelize # | ||
You can find the documentation and announcements of updates on the [project's website](http://www.sequelizejs.com). | ||
If you want to know about latest development and releases, follow me on [Twitter](http://twitter.com/sdepold). | ||
You can find the documentation and announcements of updates on the [project's website](http://www.sequelizejs.com). | ||
If you want to know about latest development and releases, follow me on [Twitter](http://twitter.com/sdepold). | ||
Also make sure to take a look at the examples in the repository. The website will contain them soon, as well. For a (more or less) complete overview of changes in 1.0.0. take a look at [this blogpost](http://blog.depold.com/post/5936116582/changes-in-sequelize-1-0-0). | ||
@@ -28,4 +28,8 @@ | ||
In order to run the tests, you need the expresso framework! When installed just run: | ||
In order to run the tests, just do ```npm install```, which will install expresso and jasmine. I am switching from | ||
expresso to jasmine, so please add according tests to your pull requests. This is how you start the tests: | ||
expresso -s test/**/* | ||
node_modules/.bin/expresso -s test/**/* | ||
node_modules/.bin/jasmine-node spec/ | ||
Current build status on travis-ci: [![Build Status](https://secure.travis-ci.org/sdepold/sequelize.png)](http://travis-ci.org/sdepold/sequelize) |
@@ -7,4 +7,4 @@ module.exports = { | ||
rand: function() { | ||
return parseInt(Math.random() * 99999999999999) | ||
return parseInt(Math.random() * 999) | ||
} | ||
} |
@@ -7,7 +7,7 @@ var config = require("./config/config") | ||
describe('ModelDefinition', function() { | ||
var User = sequelize.define('User', { age: Sequelize.INTEGER, name: Sequelize.STRING, bio: Sequelize.TEXT }) | ||
beforeEach(function() { Helpers.sync() }) | ||
afterEach(function() { Helpers.drop() }) | ||
var User = sequelize.define('User', { age: Sequelize.INTEGER, name: Sequelize.STRING, bio: Sequelize.TEXT }) | ||
//////////// all ////////////// | ||
@@ -46,3 +46,2 @@ | ||
describe('.min', function() { | ||
it("should return the min value", function() { | ||
@@ -57,3 +56,2 @@ for(var i = 2; i < 5; i++) Helpers.Factories.User({ age: i }) | ||
}) | ||
}) | ||
@@ -64,3 +62,2 @@ | ||
describe('.max', function() { | ||
it("should return the max value", function() { | ||
@@ -75,20 +72,3 @@ for(var i = 2; i <= 5; i++) Helpers.Factories.User({ age: i }) | ||
}) | ||
}) | ||
/////////// many-to-many with same prefix //////////// | ||
describe('many-to-many', function() { | ||
describe('where tables have the same prefix', function() { | ||
var Table2 = sequelize.define('wp_table2', {foo: Sequelize.STRING}) | ||
, Table1 = sequelize.define('wp_table1', {foo: Sequelize.STRING}) | ||
Table1.hasMany(Table2) | ||
Table2.hasMany(Table1) | ||
it("should create a table wp_table1wp_table2s", function() { | ||
expect(sequelize.modelManager.getModel('wp_table1swp_table2s')).toBeDefined() | ||
}) | ||
}) | ||
}) | ||
}) |
@@ -7,4 +7,4 @@ module.exports = { | ||
rand: function() { | ||
return parseInt(Math.random() * 99999999999999) | ||
return parseInt(Math.random() * 999) | ||
} | ||
} |
var assert = require("assert") | ||
, config = require("./../config") | ||
, Sequelize = require("./../../index") | ||
, sequelize = new Sequelize(config.database, config.username, config.password, {logging: false}) | ||
, sequelize = new Sequelize(config.database, config.username, config.password, {logging: false, define: { charset: 'latin1' }}) | ||
module.exports = { | ||
'it should work correctly after being idle': function(exit) { | ||
var User = sequelize.define('User', { username: Sequelize.STRING }) | ||
User.sync({force: true}).on('success', function() { | ||
@@ -22,2 +22,2 @@ User.create({username: 'user1'}).on('success', function() { | ||
} | ||
} | ||
} |
var assert = require("assert") | ||
, config = require("./../config") | ||
, Sequelize = require("./../../index") | ||
, sequelize = new Sequelize(config.database, config.username, config.password, {logging: false}) | ||
, sequelize = new Sequelize(config.database, config.username, config.password, {logging: false, define: { charset: 'latin1' }}) | ||
@@ -11,3 +11,3 @@ | ||
options.userCount = options.userCount || 1 | ||
var num = config.rand() | ||
@@ -20,3 +20,3 @@ , User = sequelize.define('User' + num, { name: Sequelize.STRING }) | ||
Task.hasMany(User, {as:'Users'}) | ||
sequelize.sync({force: true}).on('success', function() { | ||
@@ -27,3 +27,3 @@ for(var i = 0; i < options.taskCount; i++) | ||
chainer.add(User.create({name: 'user'+i})) | ||
chainer.run().on('success', function() { | ||
@@ -52,3 +52,3 @@ callback(Task, User) | ||
}) | ||
}) | ||
@@ -69,3 +69,3 @@ }) | ||
assert.eql(_tasks.length, tasks.length) | ||
user.removeTask(tasks[0]).on('success', function() { | ||
@@ -86,2 +86,2 @@ user.getTasks().on('success', function(_tasks) { | ||
} | ||
} | ||
} |
var assert = require("assert") | ||
, config = require("./../config") | ||
, Sequelize = require("./../../index") | ||
, sequelize = new Sequelize(config.database, config.username, config.password, {logging: false}) | ||
, sequelize = new Sequelize(config.database, config.username, config.password, {logging: false, define: { charset: 'latin1' }}) | ||
module.exports = { | ||
@@ -11,3 +11,3 @@ 'it should correctly add the foreign id': function() { | ||
var Task = sequelize.define('Task' + num, { title: Sequelize.STRING }) | ||
Task.belongsTo(User) | ||
@@ -20,3 +20,3 @@ assert.eql(Task.attributes['User'+num+'Id'], "INT") | ||
var Task = sequelize.define('Task' + num, { title: Sequelize.STRING }, {underscored: true}) | ||
Task.belongsTo(User) | ||
@@ -28,3 +28,3 @@ assert.eql(Task.attributes['user'+num+'_id'], "INT") | ||
var Task = sequelize.define('Task' + config.rand(), { title: Sequelize.STRING }) | ||
Task.belongsTo(User, {foreignKey: 'person_id'}) | ||
@@ -37,5 +37,5 @@ assert.eql(Task.attributes['person_id'], "INT") | ||
var Task = sequelize.define('Task' + num, { title: Sequelize.STRING }) | ||
Task.belongsTo(User) | ||
var t = Task.build({title: 'asd'}) | ||
@@ -48,5 +48,5 @@ assert.isDefined(t['setUser'+num]) | ||
var Task = sequelize.define('Task' + config.rand(), { title: Sequelize.STRING }) | ||
Task.belongsTo(User, {as: 'Person'}) | ||
var t = Task.build({title: 'asd'}) | ||
@@ -60,5 +60,5 @@ assert.isDefined(t.setPerson) | ||
var Task = sequelize.define('Task' + num, { title: Sequelize.STRING }) | ||
Task.belongsTo(User) | ||
var t = Task.build({title: 'asd'}) | ||
@@ -70,3 +70,3 @@ assert.isNull(t['User'+num+'Id']) | ||
var Task = sequelize.define('Task' + config.rand(), { title: Sequelize.STRING }) | ||
Task.belongsTo(User, {as: 'User'}) | ||
@@ -92,5 +92,5 @@ | ||
var Task = sequelize.define('Task' + config.rand(), { title: Sequelize.STRING }) | ||
Task.belongsTo(User, {as: 'User'}) | ||
User.sync({force: true}).on('success', function() { | ||
@@ -121,3 +121,3 @@ Task.sync({force: true}).on('success', function() { | ||
Person.belongsTo(Person, {as: 'Father', foreignKey: 'FatherId'}) | ||
Person.sync({force: true}).on('success', function() { | ||
@@ -137,2 +137,2 @@ var p = Person.build() | ||
} | ||
} | ||
} |
var assert = require("assert") | ||
, config = require("./../config") | ||
, Sequelize = require("./../../index") | ||
, sequelize = new Sequelize(config.database, config.username, config.password, {logging: false}) | ||
, sequelize = new Sequelize(config.database, config.username, config.password, {logging: false, define: { charset: 'latin1' }}) | ||
@@ -9,3 +9,3 @@ var initUsers = function(num, callback) { | ||
, users = [] | ||
User.sync({force: true}).on('success', function() { | ||
@@ -41,2 +41,2 @@ while(num--) users.push(User.build({name: 'user' + num, bio: 'foobar'})) | ||
} | ||
} | ||
} |
var assert = require("assert") | ||
, config = require("./../config") | ||
, Sequelize = require("./../../index") | ||
, sequelize = new Sequelize(config.database, config.username, config.password, {logging: false}) | ||
, sequelize = new Sequelize(config.database, config.username, config.password, {logging: false, define: { charset: 'latin1' }}) | ||
module.exports = { | ||
@@ -33,2 +33,2 @@ 'it should correctly count all objects': function(exit) { | ||
} | ||
} | ||
} |
var assert = require("assert") | ||
, config = require("./../config") | ||
, Sequelize = require("./../../index") | ||
, sequelize = new Sequelize(config.database, config.username, config.password, {logging: false}) | ||
, sequelize = new Sequelize(config.database, config.username, config.password, {logging: false, define: { charset: 'latin1' }}) | ||
@@ -52,2 +52,2 @@ var initUsers = function(num, callback) { | ||
} | ||
} | ||
} |
var assert = require("assert") | ||
, config = require("./../config") | ||
, Sequelize = require("./../../index") | ||
, sequelize = new Sequelize(config.database, config.username, config.password, {logging: false}) | ||
, sequelize = new Sequelize(config.database, config.username, config.password, {logging: false, define: { charset: 'latin1' }}) | ||
@@ -35,2 +35,2 @@ module.exports = { | ||
} | ||
} | ||
} |
var assert = require("assert") | ||
, config = require("./../config") | ||
, Sequelize = require("./../../index") | ||
, sequelize = new Sequelize(config.database, config.username, config.password, {logging: false}) | ||
, sequelize = new Sequelize(config.database, config.username, config.password, { logging: false, define: { charset: 'latin1' } }) | ||
@@ -24,8 +24,8 @@ module.exports = { | ||
User.sync({force: true}).on('success', function() { | ||
User.sync({force: true, charset: 'latin1'}).on('success', function() { | ||
User.create({foo: '1', bar: '2', name: 'hallo', bio: 'welt'}).on('success', function(u) { | ||
assert.eql(u.equals(u), true) | ||
exit(function(){}) | ||
}) | ||
}) | ||
}).on('failure', function(err) { console.log(err) }) | ||
}).on('failure', function(err) { console.log(err) }) | ||
}, | ||
@@ -47,2 +47,2 @@ 'equalsOneOf should work': function(exit) { | ||
} | ||
} | ||
} |
var assert = require("assert") | ||
, config = require("./../config") | ||
, Sequelize = require("./../../index") | ||
, sequelize = new Sequelize(config.database, config.username, config.password, {logging: false}) | ||
, sequelize = new Sequelize(config.database, config.username, config.password, {logging: false, define: { charset: 'latin1' }}) | ||
@@ -14,3 +14,3 @@ var initUsers = function(num, callback) { | ||
} | ||
User.sync({force: true}).on('success', function() { | ||
@@ -122,2 +122,2 @@ createUser() | ||
} | ||
} | ||
} |
var assert = require("assert") | ||
, config = require("./../config") | ||
, Sequelize = require("./../../index") | ||
, sequelize = new Sequelize(config.database, config.username, config.password, {logging: false}) | ||
, sequelize = new Sequelize(config.database, config.username, config.password, {logging: false, define: { charset: 'latin1' }}) | ||
@@ -11,3 +11,3 @@ module.exports = { | ||
var Task = sequelize.define('Task' + num, { title: Sequelize.STRING }) | ||
User.hasMany(Task) | ||
@@ -33,3 +33,3 @@ assert.eql(Task.attributes['User'+num+'Id'], "INT") | ||
} | ||
}) | ||
}) | ||
}, | ||
@@ -40,3 +40,3 @@ 'it should correctly add the foreign id with underscore - monodirectional': function() { | ||
var Task = sequelize.define('Task' + num, { title: Sequelize.STRING}, {underscored: true}) | ||
Task.hasMany(User) | ||
@@ -49,6 +49,6 @@ assert.isDefined(User.attributes['task'+ num +'_id']) | ||
var Task = sequelize.define('Task' + num, { title: Sequelize.STRING }) | ||
Task.hasMany(User) | ||
User.hasMany(Task) | ||
assert.isUndefined(Task.attributes['user'+ num +'_id']) | ||
@@ -68,3 +68,3 @@ assert.isUndefined(User.attributes['user'+ num +'_id']) | ||
var Task = sequelize.define('Task' + num, { title: Sequelize.STRING }) | ||
User.hasMany(Task, {foreignKey: 'person_id'}) | ||
@@ -77,6 +77,6 @@ assert.eql(Task.attributes.person_id, "INT") | ||
var Task = sequelize.define('Task' + num, { title: Sequelize.STRING }) | ||
User.hasMany(Task, {foreignKey: 'person_id'}) | ||
Task.hasMany(User, {foreignKey: 'work_item_id'}) | ||
sequelize.modelManager.models.forEach(function(model) { | ||
@@ -93,5 +93,5 @@ if(model.tableName == (Task.tableName + User.tableName)) { | ||
var Task = sequelize.define('Task' + num, { title: Sequelize.STRING }) | ||
User.hasMany(Task) | ||
var u = User.build({username: 'asd'}) | ||
@@ -105,10 +105,10 @@ assert.isDefined(u['setTask'+num+"s"]) | ||
var Task = sequelize.define('Task' + num, { title: Sequelize.STRING }) | ||
User.hasMany(Task) | ||
Task.hasMany(User) | ||
var u = User.build({username: 'asd'}) | ||
assert.isDefined(u['setTask'+num+"s"]) | ||
assert.isDefined(u['getTask'+num+"s"]) | ||
var t = Task.build({title: 'foobar'}) | ||
@@ -122,5 +122,5 @@ assert.isDefined(t['setUser'+num+'s']) | ||
var Task = sequelize.define('Task' + num, { title: Sequelize.STRING }) | ||
User.hasMany(Task, {as: 'Tasks'}) | ||
var u = User.build({username: 'asd'}) | ||
@@ -134,10 +134,10 @@ assert.isDefined(u.setTasks) | ||
var Task = sequelize.define('Task' + num, { title: Sequelize.STRING }) | ||
User.hasMany(Task, {as: 'Tasks'}) | ||
Task.hasMany(User, {as: 'Users'}) | ||
var u = User.build({username: 'asd'}) | ||
assert.isDefined(u.setTasks) | ||
assert.isDefined(u.getTasks) | ||
var t = Task.build({title: 'asd'}) | ||
@@ -150,12 +150,12 @@ assert.isDefined(t.setUsers) | ||
var Task = sequelize.define('Task' + config.rand(), { title: Sequelize.STRING }) | ||
User.hasMany(Task, {as: 'Tasks'}) | ||
User.sync({force: true}).on('success', function() { | ||
Task.sync({force: true}).on('success', function() { | ||
User.create({username: 'name'}).on('success', function(user) { | ||
Task.create({title: 'task1'}).on('success', function(task1) { | ||
Task.create({title: 'task2'}).on('success', function(task2) { | ||
user.setTasks([task1, task2]).on('success', function() { | ||
@@ -167,6 +167,6 @@ user.getTasks().on('success', function(tasks) { | ||
}) | ||
}) | ||
}) | ||
}) | ||
@@ -179,6 +179,6 @@ }) | ||
var Task = sequelize.define('Task' + config.rand(), { title: Sequelize.STRING }) | ||
User.hasMany(Task, {as: 'Tasks'}) | ||
Task.hasMany(User, {as: 'Users'}) | ||
User.sync({force: true}).on('success', function() { | ||
@@ -188,3 +188,3 @@ Task.sync({force: true}).on('success', function() { | ||
User.create({username: 'name2'}).on('success', function(user2) { | ||
Task.create({title: 'task1'}).on('success', function(task1) { | ||
@@ -196,3 +196,3 @@ Task.create({title: 'task2'}).on('success', function(task2) { | ||
assert.eql(tasks.length, 2) | ||
task2.setUsers([user1, user2]).on('success', function() { | ||
@@ -206,6 +206,6 @@ task2.getUsers().on('success', function(users) { | ||
}) | ||
}) | ||
}) | ||
}) | ||
}) | ||
@@ -223,3 +223,3 @@ }) | ||
Person.hasMany(Person, {as: 'CoWorkers'}) | ||
Person.sync({force: true}).on('success', function() { | ||
@@ -232,3 +232,3 @@ var modelNames = sequelize.modelManager.models.map(function(model) { return model.tableName }) | ||
}) | ||
exit(function(){}) | ||
@@ -244,3 +244,3 @@ }) | ||
Person.hasMany(Person, {as: 'CoWorkers'}) | ||
Person.sync({force: true}).on('success', function() { | ||
@@ -260,2 +260,2 @@ Person.create({name: 'foobar'}).on('success', function(person) { | ||
} | ||
} | ||
} |
var assert = require("assert") | ||
, config = require("./../config") | ||
, Sequelize = require("./../../index") | ||
, sequelize = new Sequelize(config.database, config.username, config.password, {logging: false}) | ||
, sequelize = new Sequelize(config.database, config.username, config.password, {logging: false, define: { charset: 'latin1' }}) | ||
@@ -11,3 +11,3 @@ module.exports = { | ||
var Task = sequelize.define('Task' + num, { title: Sequelize.STRING }) | ||
User.hasOne(Task) | ||
@@ -20,3 +20,3 @@ assert.eql(Task.attributes['User'+num+'Id'], "INT") | ||
var Task = sequelize.define('Task' + num, { title: Sequelize.STRING }) | ||
User.hasOne(Task) | ||
@@ -29,3 +29,3 @@ assert.eql(Task.attributes['user'+num+'_id'], "INT") | ||
var Task = sequelize.define('Task' + num, { title: Sequelize.STRING }) | ||
User.hasOne(Task, {foreignKey: 'person_id'}) | ||
@@ -38,5 +38,5 @@ assert.eql(Task.attributes.person_id, "INT") | ||
var Task = sequelize.define('Task' + num, { title: Sequelize.STRING }) | ||
User.hasOne(Task) | ||
var u = User.build({username: 'asd'}) | ||
@@ -50,5 +50,5 @@ assert.isDefined(u['setTask'+num]) | ||
var Task = sequelize.define('Task' + num, { title: Sequelize.STRING }) | ||
User.hasOne(Task, {as: 'Task'}) | ||
var u = User.build({username: 'asd'}) | ||
@@ -61,5 +61,5 @@ assert.isDefined(u.setTask) | ||
var Task = sequelize.define('Task' + config.rand(), { title: Sequelize.STRING }) | ||
User.hasOne(Task, {as: 'Task'}) | ||
User.sync({force: true}).on('success', function() { | ||
@@ -83,5 +83,5 @@ Task.sync({force: true}).on('success', function() { | ||
var Task = sequelize.define('Task' + config.rand(), { title: Sequelize.STRING }) | ||
User.hasOne(Task, {as: 'Task'}) | ||
User.sync({force: true}).on('success', function() { | ||
@@ -114,3 +114,3 @@ Task.sync({force: true}).on('success', function() { | ||
Person.hasOne(Person, {as: 'Father', foreignKey: 'FatherId'}) | ||
Person.sync({force: true}).on('success', function() { | ||
@@ -130,2 +130,2 @@ var p = Person.build() | ||
} | ||
} | ||
} |
var assert = require("assert") | ||
, config = require("./../config") | ||
, Sequelize = require("./../../index") | ||
, sequelize = new Sequelize(config.database, config.username, config.password, {logging: false}) | ||
, sequelize = new Sequelize(config.database, config.username, config.password, {logging: false, define: { charset: 'latin1' }}) | ||
@@ -9,3 +9,3 @@ var initUsers = function(num, callback) { | ||
, users = [] | ||
User.sync({force: true}).on('success', function() { | ||
@@ -68,2 +68,2 @@ while(num--) users.push(User.build({name: 'user' + num, bio: 'foobar'})) | ||
} | ||
} | ||
} |
var assert = require("assert") | ||
, config = require("./../config") | ||
, Sequelize = require("./../../index") | ||
, sequelize = new Sequelize(config.database, config.username, config.password, {logging: false}) | ||
, sequelize = new Sequelize(config.database, config.username, config.password, {logging: false, define: { charset: 'latin1' }}) | ||
@@ -44,2 +44,2 @@ module.exports = { | ||
} | ||
} | ||
} |
var assert = require("assert") | ||
, config = require("./../config") | ||
, Sequelize = require("./../../index") | ||
, sequelize = new Sequelize(config.database, config.username, config.password, {logging: false}) | ||
, sequelize = new Sequelize(config.database, config.username, config.password, {logging: false, define: { charset: 'latin1' }}) | ||
, User = sequelize.define('User', { name: Sequelize.STRING, bio: Sequelize.TEXT }) | ||
@@ -21,2 +21,2 @@ | ||
} | ||
} | ||
} |
var assert = require("assert") | ||
, config = require("./../config") | ||
, Sequelize = require("./../../index") | ||
, sequelize = new Sequelize(config.database, config.username, config.password, {logging: false}) | ||
, sequelize = new Sequelize(config.database, config.username, config.password, {logging: false, define: { charset: 'latin1' }}) | ||
, User = sequelize.define('User' + config.rand(), { name: Sequelize.STRING, bio: Sequelize.TEXT }) | ||
@@ -61,2 +61,2 @@ | ||
} | ||
} | ||
} |
var assert = require("assert") | ||
, config = require("./../config") | ||
, Sequelize = require("./../../index") | ||
, sequelize = new Sequelize(config.database, config.username, config.password, {logging: false}) | ||
, sequelize = new Sequelize(config.database, config.username, config.password, {logging: false, define: { charset: 'latin1' }}) | ||
@@ -9,3 +9,3 @@ var initUsers = function(num, callback) { | ||
, users = [] | ||
User.sync({force: true}).on('success', function() { | ||
@@ -24,2 +24,2 @@ while(num--) users.push(User.build({name: 'user' + num, bio: 'foobar'})) | ||
} | ||
} | ||
} |
var assert = require("assert") | ||
, QueryGenerator = require("../../lib/sequelize/query-generator") | ||
, eql = assert.equal | ||
module.exports = { | ||
'create table query': function() { | ||
eql(QueryGenerator.createTableQuery('myTable', {title: 'VARCHAR(255)', name: 'VARCHAR(255)'}), "CREATE TABLE IF NOT EXISTS `myTable` (`title` VARCHAR(255), `name` VARCHAR(255));") | ||
eql(QueryGenerator.createTableQuery('myTable', {title: 'VARCHAR(255)', name: 'VARCHAR(255)'}), "CREATE TABLE IF NOT EXISTS `myTable` (`title` VARCHAR(255), `name` VARCHAR(255)) ENGINE=InnoDB;") | ||
eql(QueryGenerator.createTableQuery('myTable', {title: 'VARCHAR(255)', name: 'VARCHAR(255)'}, {engine: 'MyISAM'}), "CREATE TABLE IF NOT EXISTS `myTable` (`title` VARCHAR(255), `name` VARCHAR(255)) ENGINE=MyISAM;") | ||
eql(QueryGenerator.createTableQuery('myTable', {title: 'VARCHAR(255)', name: 'VARCHAR(255)'}, {charset: 'latin1'}), "CREATE TABLE IF NOT EXISTS `myTable` (`title` VARCHAR(255), `name` VARCHAR(255)) ENGINE=InnoDB DEFAULT CHARSET=latin1;") | ||
}, | ||
@@ -62,2 +64,2 @@ 'drop table query': function() { | ||
} | ||
} | ||
} |
var assert = require("assert") | ||
, config = require("./../config") | ||
, Sequelize = require("./../../index") | ||
, sequelize = new Sequelize(config.database, config.username, config.password, {logging: false}) | ||
, sequelize = new Sequelize(config.database, config.username, config.password, {logging: false, define: { charset: 'latin1' }}) | ||
@@ -11,2 +11,2 @@ module.exports = { | ||
} | ||
} | ||
} |
var assert = require("assert") | ||
, config = require("./../config") | ||
, Sequelize = require("./../../index") | ||
, sequelize = new Sequelize(config.database, config.username, config.password, {logging: false}) | ||
, sequelize = new Sequelize(config.database, config.username, config.password, {logging: false, define: { charset: 'latin1' }}) | ||
@@ -14,3 +14,3 @@ module.exports = { | ||
}) | ||
sequelize.sync().on('success', function() { | ||
@@ -24,2 +24,2 @@ Project.create({title: 'bla'}).on('success', function() { | ||
} | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
392488
2
118
3139
34