From e09aa89c89c62906fb4c214da18e1bb9fe12e8a4 Mon Sep 17 00:00:00 2001 From: Cody Stoltman Date: Fri, 18 Mar 2016 13:15:44 -0500 Subject: [PATCH 1/5] update dependencies for use with Waterline 0.12 --- package.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index f2833549..d1607782 100644 --- a/package.json +++ b/package.json @@ -26,16 +26,16 @@ "mysql": "2.10.2", "waterline-cursor": "0.0.6", "waterline-errors": "0.10.1", - "waterline-sequel": "0.5.7" + "waterline-sequel": "0.6.0" }, "devDependencies": { "captains-log": "~0.11.11", "mocha": "2.4.1", "should": "8.2.0", - "waterline-adapter-tests": "~0.11.1" + "waterline-adapter-tests": "~0.12.0" }, "waterlineAdapter": { - "waterlineVersion": "~0.10.0", + "waterlineVersion": "~0.12.0", "interfaces": [ "semantic", "queryable", From 4e510bed89ae0ec4ec6251ae8ed6966574e57d0e Mon Sep 17 00:00:00 2001 From: Cody Stoltman Date: Fri, 18 Mar 2016 13:16:28 -0500 Subject: [PATCH 2/5] update connection schema for normalization when passing into the updated wl-sql library --- lib/connections/register.js | 40 +++++++++++++++++++++++----------- test/unit/support/bootstrap.js | 3 ++- 2 files changed, 29 insertions(+), 14 deletions(-) diff --git a/lib/connections/register.js b/lib/connections/register.js index ad45de54..c3619f79 100644 --- a/lib/connections/register.js +++ b/lib/connections/register.js @@ -31,28 +31,42 @@ module.exports.configure = function ( connections ) { // Build up a schema for this connection that can be used throughout the adapter var schema = {}; - _.each(_.keys(collections), function(coll) { - var collection = collections[coll]; - if(!collection) return; + _.each(_.keys(collections), function(collName) { + var collection = collections[collName]; + if(!collection) { + return; + } - var _schema = collection.waterline && collection.waterline.schema && collection.waterline.schema[collection.identity]; - if(!_schema) return; + // Normalize schema into a sane object and discard all the WL context + var wlSchema = collection.waterline && collection.waterline.schema && collection.waterline.schema[collection.identity]; + var _schema = {}; + _schema.attributes = wlSchema.attributes || {}; + _schema.definition = collection.definition || {}; + _schema.meta = collection.meta || {}; + _schema.tableName = wlSchema.tableName; + _schema.connection = wlSchema.connection; // Set defaults to ensure values are set - if(!_schema.attributes) _schema.attributes = {}; - if(!_schema.tableName) _schema.tableName = coll; + if(!_schema.attributes) { + _schema.attributes = {}; + } - // If the connection names are't the same we don't need it in the schema - if(!_.includes(collections[coll].connection, connection.identity)) { + if(!_schema.tableName) { + _schema.tableName = collName; + } + + // If the connection names aren't the same we don't need it in the schema + if(!_.includes(_schema.connection, connection.identity)) { return; } - // If the tableName is different from the identity, store the tableName in the schema - var schemaKey = coll; - if(_schema.tableName != coll) { + // If the tableName is different from the identity, store the tableName + // in the schema. + var schemaKey = collName; + if(_schema.tableName !== collName) { schemaKey = _schema.tableName; } - + // Store the normalized schema schema[schemaKey] = _schema; }); diff --git a/test/unit/support/bootstrap.js b/test/unit/support/bootstrap.js index 8622c23c..a779430f 100644 --- a/test/unit/support/bootstrap.js +++ b/test/unit/support/bootstrap.js @@ -52,7 +52,8 @@ Support.Schema = function(name, def) { connection: 'test', identity: name, tableName: name, - attributes: def || Support.Definition + attributes: def || Support.Definition, + definition: def || Support.Definition }; } From 236c58072934ff64a69e30160728311c4ef131d0 Mon Sep 17 00:00:00 2001 From: Cody Stoltman Date: Fri, 18 Mar 2016 13:18:31 -0500 Subject: [PATCH 3/5] update subqueries to use union all and to better handle ambitious column in order by clause --- lib/adapter.js | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/lib/adapter.js b/lib/adapter.js index affd6739..cc4dd0e5 100644 --- a/lib/adapter.js +++ b/lib/adapter.js @@ -698,30 +698,35 @@ module.exports = (function() { parentRecords.forEach(function(parent) { if(_.isNumber(parent[pk])) { - qs += q.qs.replace('^?^', parent[pk]) + ' UNION '; + qs += q.qs.replace('^?^', parent[pk]) + ' UNION ALL '; } else { - qs += q.qs.replace('^?^', '"' + parent[pk] + '"') + ' UNION '; + qs += q.qs.replace('^?^', '"' + parent[pk] + '"') + ' UNION ALL '; } }); // Remove the last UNION - qs = qs.slice(0, -7); + qs = qs.slice(0, -10); // Add a final sort to the Union clause for integration if(parentRecords.length > 1) { var addedOrder = false; function addSort(sortKey, sorts) { - if (!sortKey.match(/^[0-9,a-z,A-Z$_]+$/)) { - return; - } - if (!addedOrder) { - addedOrder = true; - qs += ' ORDER BY '; - } + // ID sorts are ambiguous + if(sortKey === 'id') { + return; + } + + if (!sortKey.match(/^[0-9,a-z,A-Z$_]+$/)) { + return; + } + if (!addedOrder) { + addedOrder = true; + qs += ' ORDER BY '; + } - var direction = sorts[sortKey] === 1 ? 'ASC' : 'DESC'; - qs += sortKey + ' ' + direction; + var direction = sorts[sortKey] === 1 ? 'ASC' : 'DESC'; + qs += sortKey + ' ' + direction; } if(!Array.isArray(q.instructions)) { From fcc8752316c0a6e388eacf5bf687237247607c18 Mon Sep 17 00:00:00 2001 From: Cody Stoltman Date: Fri, 18 Mar 2016 13:19:22 -0500 Subject: [PATCH 4/5] add a no-op argument for compatibility with the meta argument in Waterline 0.12.0 - Only needed because we already had an extra argument tacked on (connection) for internal use --- lib/adapter.js | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/lib/adapter.js b/lib/adapter.js index cc4dd0e5..0e4b23aa 100644 --- a/lib/adapter.js +++ b/lib/adapter.js @@ -84,7 +84,7 @@ module.exports = (function() { // Direct access to query - query: function(connectionName, collectionName, query, data, cb, connection) { + query: function(connectionName, collectionName, query, data, cb, noop, connection) { if (_.isFunction(data)) { cb = data; @@ -111,7 +111,7 @@ module.exports = (function() { // Fetch the schema for a collection // (contains attributes and autoIncrement value) - describe: function(connectionName, collectionName, cb, connection) { + describe: function(connectionName, collectionName, cb, noop, connection) { if(_.isUndefined(connection)) { return spawnConnection(connectionName, __DESCRIBE__, cb); @@ -187,7 +187,7 @@ module.exports = (function() { }, // Create a new collection - define: function(connectionName, collectionName, definition, cb, connection) { + define: function(connectionName, collectionName, definition, cb, noop, connection) { var self = this; if(_.isUndefined(connection)) { @@ -242,7 +242,7 @@ module.exports = (function() { }, // Drop an existing collection - drop: function(connectionName, collectionName, relations, cb, connection) { + drop: function(connectionName, collectionName, relations, cb, noop, connection) { if(typeof relations === 'function') { cb = relations; @@ -291,7 +291,7 @@ module.exports = (function() { }, // - addAttribute: function (connectionName, collectionName, attrName, attrDef, cb, connection) { + addAttribute: function (connectionName, collectionName, attrName, attrDef, cb, noop, connection) { if(_.isUndefined(connection)) { return spawnConnection(connectionName, __ADD_ATTRIBUTE__, cb); @@ -321,7 +321,7 @@ module.exports = (function() { }, // - removeAttribute: function (connectionName, collectionName, attrName, cb, connection) { + removeAttribute: function (connectionName, collectionName, attrName, cb, noop, connection) { if(_.isUndefined(connection)) { return spawnConnection(connectionName, __REMOVE_ATTRIBUTE__, cb); @@ -355,7 +355,7 @@ module.exports = (function() { // (that is unless you want some enhanced functionality-- then please be my guest!) // Create one or more new models in the collection - create: function(connectionName, collectionName, data, cb, connection) { + create: function(connectionName, collectionName, data, cb, noop, connection) { if(_.isUndefined(connection)) { return spawnConnection(connectionName, __CREATE__, cb); @@ -390,7 +390,7 @@ module.exports = (function() { // Run query log('MySQL.create: ', _query.query); - + if(!connection.query) { console.log('CONNECTION', connection); } connection.query(_query.query, function(err, result) { if (err) return cb( handleQueryError(err) ); @@ -416,7 +416,7 @@ module.exports = (function() { // Override of createEach to share a single connection // instead of using a separate connection for each request - createEach: function (connectionName, collectionName, valuesList, cb, connection) { + createEach: function (connectionName, collectionName, valuesList, cb, noop, connection) { if(_.isUndefined(connection)) { return spawnConnection(connectionName, __CREATE_EACH__, cb); @@ -499,7 +499,7 @@ module.exports = (function() { * @param {[type]} cb [description] * @return {[type]} [description] */ - join: function (connectionName, collectionName, options, cb, connection) { + join: function (connectionName, collectionName, options, cb, noop, connection) { if(_.isUndefined(connection)) { return spawnConnection(connectionName, __JOIN__, cb); @@ -525,7 +525,7 @@ module.exports = (function() { * @param {Function} _cb */ $find: function (collectionName, criteria, _cb) { - return adapter.find(connectionName, collectionName, criteria, _cb, client); + return adapter.find(connectionName, collectionName, criteria, _cb, noop, client); }, /** @@ -804,7 +804,7 @@ module.exports = (function() { // Find one or more models from the collection // using where, limit, skip, and order // In where: handle `or`, `and`, and `like` queries - find: function(connectionName, collectionName, options, cb, connection) { + find: function(connectionName, collectionName, options, cb, noop, connection) { if(_.isUndefined(connection)) { return spawnConnection(connectionName, __FIND__, cb); @@ -851,7 +851,7 @@ module.exports = (function() { // Count one model from the collection // using where, limit, skip, and order // In where: handle `or`, `and`, and `like` queries - count: function(connectionName, collectionName, options, cb, connection) { + count: function(connectionName, collectionName, options, cb, noop, connection) { if(_.isUndefined(connection)) { return spawnConnection(connectionName, __COUNT__, cb); @@ -898,7 +898,7 @@ module.exports = (function() { // Stream one or more models from the collection // using where, limit, skip, and order // In where: handle `or`, `and`, and `like` queries - stream: function(connectionName, collectionName, options, stream, connection) { + stream: function(connectionName, collectionName, options, stream, noop, connection) { if(_.isUndefined(connection)) { return spawnConnection(connectionName, __STREAM__); @@ -957,7 +957,7 @@ module.exports = (function() { }, // Update one or more models in the collection - update: function(connectionName, collectionName, options, values, cb, connection) { + update: function(connectionName, collectionName, options, values, cb, noop, connection) { if(_.isUndefined(connection)) { return spawnConnection(connectionName, __UPDATE__, cb); @@ -1053,7 +1053,7 @@ module.exports = (function() { }, // Delete one or more models from the collection - destroy: function(connectionName, collectionName, options, cb, connection) { + destroy: function(connectionName, collectionName, options, cb, noop, connection) { if(_.isUndefined(connection)) { return spawnConnection(connectionName, __DESTROY__, cb); @@ -1084,7 +1084,7 @@ module.exports = (function() { async.auto({ findRecords: function(next) { - adapter.find(connectionName, collectionName, options, next, connection); + adapter.find(connectionName, collectionName, options, next, noop, connection); }, destroyRecords: ['findRecords', function(next) { From f40a6fe4357980d0b019690a6cf6d047aea0b9d2 Mon Sep 17 00:00:00 2001 From: Cody Stoltman Date: Fri, 18 Mar 2016 13:30:25 -0500 Subject: [PATCH 5/5] remove outdated shrinkwrap --- npm-shrinkwrap.json | 89 --------------------------------------------- 1 file changed, 89 deletions(-) delete mode 100644 npm-shrinkwrap.json diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json deleted file mode 100644 index 0597a7ca..00000000 --- a/npm-shrinkwrap.json +++ /dev/null @@ -1,89 +0,0 @@ -{ - "name": "sails-mysql", - "version": "0.11.5", - "dependencies": { - "async": { - "version": "1.5.2", - "from": "async@1.5.2", - "resolved": "https://registry.npmjs.org/async/-/async-1.5.2.tgz" - }, - "lodash": { - "version": "3.10.1", - "from": "lodash@3.10.1", - "resolved": "https://registry.npmjs.org/lodash/-/lodash-3.10.1.tgz" - }, - "mysql": { - "version": "2.10.2", - "from": "mysql@2.10.2", - "resolved": "https://registry.npmjs.org/mysql/-/mysql-2.10.2.tgz", - "dependencies": { - "bignumber.js": { - "version": "2.1.4", - "from": "bignumber.js@2.1.4", - "resolved": "https://registry.npmjs.org/bignumber.js/-/bignumber.js-2.1.4.tgz" - }, - "readable-stream": { - "version": "1.1.13", - "from": "readable-stream@>=1.1.13 <1.2.0", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-1.1.13.tgz", - "dependencies": { - "core-util-is": { - "version": "1.0.2", - "from": "core-util-is@>=1.0.0 <1.1.0", - "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz" - }, - "isarray": { - "version": "0.0.1", - "from": "isarray@0.0.1", - "resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz" - }, - "string_decoder": { - "version": "0.10.31", - "from": "string_decoder@>=0.10.0 <0.11.0", - "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz" - }, - "inherits": { - "version": "2.0.1", - "from": "inherits@>=2.0.1 <2.1.0", - "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.1.tgz" - } - } - } - } - }, - "waterline-cursor": { - "version": "0.0.6", - "from": "waterline-cursor@0.0.6", - "resolved": "https://registry.npmjs.org/waterline-cursor/-/waterline-cursor-0.0.6.tgz", - "dependencies": { - "async": { - "version": "0.9.2", - "from": "async@>=0.9.0 <0.10.0", - "resolved": "https://registry.npmjs.org/async/-/async-0.9.2.tgz" - }, - "lodash": { - "version": "2.4.2", - "from": "lodash@>=2.4.1 <2.5.0", - "resolved": "https://registry.npmjs.org/lodash/-/lodash-2.4.2.tgz" - } - } - }, - "waterline-errors": { - "version": "0.10.1", - "from": "waterline-errors@0.10.1", - "resolved": "https://registry.npmjs.org/waterline-errors/-/waterline-errors-0.10.1.tgz" - }, - "waterline-sequel": { - "version": "0.5.7", - "from": "waterline-sequel@0.5.7", - "resolved": "https://registry.npmjs.org/waterline-sequel/-/waterline-sequel-0.5.7.tgz", - "dependencies": { - "lodash": { - "version": "3.10.0", - "from": "lodash@3.10.0", - "resolved": "https://registry.npmjs.org/lodash/-/lodash-3.10.0.tgz" - } - } - } - } -}