Merge branch 'release/1.2.2' into production

This commit is contained in:
Raymond Feng 2014-05-29 15:48:17 -07:00
commit da79a13887
5 changed files with 48 additions and 12 deletions

View File

@ -319,7 +319,7 @@ function mixinDiscovery(MySQL) {
} else { } else {
return 'String'; return 'String';
} }
break;
case 'VARCHAR': case 'VARCHAR':
case 'TINYTEXT': case 'TINYTEXT':
case 'MEDIUMTEXT': case 'MEDIUMTEXT':
@ -343,6 +343,7 @@ function mixinDiscovery(MySQL) {
case 'YEAR': case 'YEAR':
case 'FLOAT': case 'FLOAT':
case 'DOUBLE': case 'DOUBLE':
case 'BIGINT':
return 'Number'; return 'Number';
case 'DATE': case 'DATE':
case 'TIMESTAMP': case 'TIMESTAMP':

View File

@ -304,7 +304,12 @@ MySQL.prototype.toDatabase = function (prop, val) {
if (prop.type.name === 'GeoPoint') { if (prop.type.name === 'GeoPoint') {
return val ? 'Point(' + val.lat + ',' + val.lng + ')' : 'NULL'; return val ? 'Point(' + val.lat + ',' + val.lng + ')' : 'NULL';
} }
if (typeof prop.type === 'function') return this.client.escape(prop.type(val)); if (prop.type === Object) {
return this.client.escape(val);
}
if (typeof prop.type === 'function') {
return this.client.escape(prop.type(val));
}
return this.client.escape(val.toString()); return this.client.escape(val.toString());
}; };
@ -445,6 +450,12 @@ MySQL.prototype._buildWhere = function (model, conds) {
case 'neq': case 'neq':
sqlCond += ' != '; sqlCond += ' != ';
break; break;
case 'like':
sqlCond += ' LIKE ';
break;
case 'nlike':
sqlCond += ' NOT LIKE ';
break;
} }
sqlCond += (condType === 'inq' || condType === 'nin') ? '(' + val + ')' : val; sqlCond += (condType === 'inq' || condType === 'nin') ? '(' + val + ')' : val;
cs.push(sqlCond); cs.push(sqlCond);
@ -544,10 +555,10 @@ MySQL.prototype.destroyAll = function destroyAll(model, where, callback) {
where = undefined; where = undefined;
} }
this.query('DELETE FROM ' this.query('DELETE FROM '
+ this.tableEscaped(model) + ' ' + this.buildWhere(model, where || {}), + this.tableEscaped(model) + ' ' + this.buildWhere(model, where || {}),
function (err, data) { function (err, data) {
callback && callback(err, data); callback && callback(err, data);
}.bind(this)); }.bind(this));
}; };
/** /**
@ -962,8 +973,13 @@ function stringOptionsByType(p, dt) {
switch (dt.toLowerCase()) { switch (dt.toLowerCase()) {
default: default:
case 'varchar': case 'varchar':
// The maximum length for an ID column is 1000 bytes
var len = p.limit || ((p.type !== String) ? 32768 : p.id ? 255: 1024);
dt += '(' + len + ')';
break;
case 'char': case 'char':
dt += '(' + (p.limit || 255) + ')'; len = p.limit || 255;
dt += '(' + len + ')';
break; break;
case 'text': case 'text':

View File

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

View File

@ -49,6 +49,24 @@ describe('MySQL specific datatypes', function () {
}); });
}); });
it('should create a model instance with object/json types', function (done) {
var note = {a: 1, b: '2'};
var extras = {c: 3, d: '4'};
var em = EnumModel.create({animal: ANIMAL_ENUM.DOG, condition: 'sleepy',
mood: 'happy', note: note, extras: extras}, function (err, obj) {
assert.ok(!err);
assert.equal(obj.condition, 'sleepy');
EnumModel.findOne({where: {animal: ANIMAL_ENUM.DOG}}, function (err, found) {
assert.ok(!err);
assert.equal(found.mood, 'happy');
assert.equal(found.animal, ANIMAL_ENUM.DOG);
assert.deepEqual(found.note, note);
assert.deepEqual(found.extras, extras);
done();
});
});
});
it('should disconnect when done', function (done) { it('should disconnect when done', function (done) {
db.disconnect(); db.disconnect();
done() done()
@ -67,7 +85,9 @@ function setup(done) {
EnumModel = db.define('EnumModel', { EnumModel = db.define('EnumModel', {
animal: { type: ANIMAL_ENUM, null: false }, animal: { type: ANIMAL_ENUM, null: false },
condition: { type: db.EnumFactory('hungry', 'sleepy', 'thirsty') }, condition: { type: db.EnumFactory('hungry', 'sleepy', 'thirsty') },
mood: { type: db.EnumFactory('angry', 'happy', 'sad') } mood: { type: db.EnumFactory('angry', 'happy', 'sad') },
note: Object,
extras: 'JSON'
}); });
blankDatabase(db, done); blankDatabase(db, done);

View File

@ -26,14 +26,14 @@ describe('migrations', function () {
Extra: 'auto_increment' }, Extra: 'auto_increment' },
email: { email: {
Field: 'email', Field: 'email',
Type: 'varchar(255)', Type: 'varchar(1024)',
Null: 'NO', Null: 'NO',
Key: 'MUL', Key: 'MUL',
Default: null, Default: null,
Extra: '' }, Extra: '' },
name: { name: {
Field: 'name', Field: 'name',
Type: 'varchar(255)', Type: 'varchar(1024)',
Null: 'YES', Null: 'YES',
Key: '', Key: '',
Default: null, Default: null,
@ -74,7 +74,6 @@ describe('migrations', function () {
it('UserData should have correct indexes', function (done) { it('UserData should have correct indexes', function (done) {
// Note: getIndexes truncates multi-key indexes to the first member. Hence index1 is correct. // Note: getIndexes truncates multi-key indexes to the first member. Hence index1 is correct.
getIndexes('UserData', function (err, fields) { getIndexes('UserData', function (err, fields) {
// console.log('....', fields);
assert.deepEqual(fields, { PRIMARY: { Table: 'UserData', assert.deepEqual(fields, { PRIMARY: { Table: 'UserData',
Non_unique: 0, Non_unique: 0,
Key_name: 'PRIMARY', Key_name: 'PRIMARY',
@ -94,7 +93,7 @@ describe('migrations', function () {
Column_name: 'email', Column_name: 'email',
Collation: 'A', Collation: 'A',
Cardinality: null, Cardinality: null,
Sub_part: null, Sub_part: 333,
Packed: null, Packed: null,
Null: '', Null: '',
Index_type: 'BTREE', Index_type: 'BTREE',
@ -106,7 +105,7 @@ describe('migrations', function () {
Column_name: 'email', Column_name: 'email',
Collation: 'A', Collation: 'A',
Cardinality: null, Cardinality: null,
Sub_part: null, Sub_part: 333,
Packed: null, Packed: null,
Null: '', Null: '',
Index_type: 'BTREE', Index_type: 'BTREE',