Merge branch 'release/1.4.0' into production

This commit is contained in:
Raymond Feng 2014-06-23 10:24:44 -07:00
commit 161fa5927e
3 changed files with 30 additions and 4 deletions

View File

@ -306,6 +306,7 @@ MySQL.prototype.toDatabase = function (prop, val) {
return this.toDatabase(prop, val); return this.toDatabase(prop, val);
} }
} }
return this.toDatabase(prop, val);
} }
if (!prop) { if (!prop) {
return this.client.escape(val); return this.client.escape(val);
@ -634,7 +635,7 @@ MySQL.prototype.autoupdate = function (models, cb) {
wait++; wait++;
self.query('SHOW FIELDS FROM ' + self.tableEscaped(model), function (err, fields) { self.query('SHOW FIELDS FROM ' + self.tableEscaped(model), function (err, fields) {
self.query('SHOW INDEXES FROM ' + self.tableEscaped(model), function (err, indexes) { self.query('SHOW INDEXES FROM ' + self.tableEscaped(model), function (err, indexes) {
if (!err && fields.length) { if (!err && fields && fields.length) {
self.alterTable(model, fields, indexes, done); self.alterTable(model, fields, indexes, done);
} else { } else {
self.createTable(model, done); self.createTable(model, done);
@ -980,10 +981,12 @@ function datatype(p) {
switch (p.type.name) { switch (p.type.name) {
default: default:
case 'String': case 'String':
case 'JSON':
dt = columnType(p, 'VARCHAR'); dt = columnType(p, 'VARCHAR');
dt = stringOptionsByType(p, dt); dt = stringOptionsByType(p, dt);
break; break;
case 'JSON':
case 'Object':
case 'Any':
case 'Text': case 'Text':
dt = columnType(p, 'TEXT'); dt = columnType(p, 'TEXT');
dt = stringOptionsByType(p, dt); dt = stringOptionsByType(p, dt);
@ -1023,7 +1026,8 @@ function stringOptionsByType(p, dt) {
default: default:
case 'varchar': case 'varchar':
// The maximum length for an ID column is 1000 bytes // The maximum length for an ID column is 1000 bytes
var len = p.limit || ((p.type !== String) ? 32768 : p.id ? 255: 1024); // The maximum row size is 64K
var len = p.limit || ((p.type !== String) ? 8192 : p.id ? 255: 1024);
dt += '(' + len + ')'; dt += '(' + len + ')';
break; break;
case 'char': case 'char':

View File

@ -1,6 +1,6 @@
{ {
"name": "loopback-connector-mysql", "name": "loopback-connector-mysql",
"version": "1.3.0", "version": "1.4.0",
"description": "MySQL connector for loopback-datasource-juggler", "description": "MySQL connector for loopback-datasource-juggler",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {

View File

@ -10,6 +10,8 @@ describe('mysql', function () {
Post = db.define('PostWithDefaultId', { Post = db.define('PostWithDefaultId', {
title: { type: String, length: 255, index: true }, title: { type: String, length: 255, index: true },
content: { type: String }, content: { type: String },
comments: [String],
history: Object,
stars: Number stars: Number
}); });
@ -33,6 +35,26 @@ describe('mysql', function () {
}); });
}); });
it('should allow array or object', function (done) {
Post.create({title: 'a', content: 'AAA', comments: ['1', '2'],
history: {a: 1, b: 'b'}}, function (err, post) {
should.not.exist(err);
Post.findById(post.id, function (err, p) {
p.id.should.be.equal(post.id);
p.content.should.be.equal(post.content);
p.title.should.be.equal('a');
p.comments.should.eql(['1', '2']);
p.history.should.eql({a: 1, b: 'b'});
done();
});
});
});
it('updateOrCreate should update the instance', function (done) { it('updateOrCreate should update the instance', function (done) {
Post.create({title: 'a', content: 'AAA'}, function (err, post) { Post.create({title: 'a', content: 'AAA'}, function (err, post) {
post.title = 'b'; post.title = 'b';