From abaabff01a0bdb2ad35e51d66b86f53ba246befe Mon Sep 17 00:00:00 2001 From: Raymond Feng Date: Tue, 8 Jul 2014 11:23:45 -0700 Subject: [PATCH 1/2] Fix the default length for strings to avoid row size overflow --- lib/mysql.js | 4 ++-- test/migration.test.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/mysql.js b/lib/mysql.js index 9debd5e..32b6f99 100644 --- a/lib/mysql.js +++ b/lib/mysql.js @@ -1027,11 +1027,11 @@ function stringOptionsByType(p, dt) { case 'varchar': // The maximum length for an ID column is 1000 bytes // The maximum row size is 64K - var len = p.limit || ((p.type !== String) ? 8192 : p.id ? 255: 1024); + var len = p.length || p.limit || ((p.type !== String) ? 4096 : p.id ? 255: 512); dt += '(' + len + ')'; break; case 'char': - len = p.limit || 255; + len = p.length || p.limit || 255; dt += '(' + len + ')'; break; diff --git a/test/migration.test.js b/test/migration.test.js index 3746346..b23c5e6 100644 --- a/test/migration.test.js +++ b/test/migration.test.js @@ -26,14 +26,14 @@ describe('migrations', function () { Extra: 'auto_increment' }, email: { Field: 'email', - Type: 'varchar(1024)', + Type: 'varchar(512)', Null: 'NO', Key: 'MUL', Default: null, Extra: '' }, name: { Field: 'name', - Type: 'varchar(1024)', + Type: 'varchar(512)', Null: 'YES', Key: '', Default: null, From 8f62b08e70fc33e5eec9e05ec942830445c70a60 Mon Sep 17 00:00:00 2001 From: Raymond Feng Date: Fri, 15 Aug 2014 16:27:12 -0700 Subject: [PATCH 2/2] Allow properties to pass through mysql driver See https://github.com/strongloop/loopback-connector-mysql/issues/46 --- lib/mysql.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/mysql.js b/lib/mysql.js index 32b6f99..f72c72c 100644 --- a/lib/mysql.js +++ b/lib/mysql.js @@ -54,6 +54,14 @@ exports.initialize = function initializeDataSource(dataSource, callback) { options.database = s.database; } + // Take other options for mysql driver + // See https://github.com/strongloop/loopback-connector-mysql/issues/46 + for (var p in s) { + if (options[p] === undefined) { + options[p] = s[p]; + } + } + dataSource.client = mysql.createPool(options); dataSource.client.on('error', function (err) {