From 1cb029fe8520afdcf94505f5121844e45019be68 Mon Sep 17 00:00:00 2001 From: Oleg Zhvankov Date: Thu, 24 Sep 2015 12:20:05 +0300 Subject: [PATCH 1/2] Update adapter.js fix stream function: change to new query builder line 930-939 new Query --> new Sequel --- lib/adapter.js | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/lib/adapter.js b/lib/adapter.js index 26eba2dd..e16162f1 100644 --- a/lib/adapter.js +++ b/lib/adapter.js @@ -14,6 +14,7 @@ var utils = require('./utils'); var Processor = require('./processor'); var Cursor = require('waterline-cursor'); var hop = utils.object.hasOwnProperty; +var Query = require('./query'); module.exports = (function() { @@ -926,19 +927,33 @@ module.exports = (function() { var client = new pg.Client(connectionObject.config); client.connect(); - var schema = {}; + //var schema = {}; - Object.keys(connectionObject.collections).forEach(function(coll) { - schema[coll] = connectionObject.collections[coll].schema; - }); + //Object.keys(connectionObject.collections).forEach(function(coll) { + // schema[coll] = connectionObject.collections[coll].schema; + //}); // Build Query - var _schema = collection.schema; - var queryObj = new Query(_schema, schema); - var query =queryObj.find(table, options); + //var _schema = collection.schema; + //var queryObj = new Query(_schema, schema); + //var query =queryObj.find(table, options); + + var _schema = collection.waterline.schema; + //var processor = new Processor(schema); + var sequel = new Sequel(_schema); + + var _query; + // Build a query for the specific query strategy + try { + _query = sequel.find(table, options); + //console.log(_query.query[0]); + } catch(e) { + return cb(e); + } + // Run Query - var dbStream = client.query(query.query, query.values); + var dbStream = client.query(_query.query[0], _query.values[0]); //can stream row results back 1 at a time dbStream.on('row', function(row) { @@ -1232,9 +1247,6 @@ module.exports = (function() { if (matches && matches.length) { formattedErr = {}; formattedErr.code = 'E_UNIQUE'; - // This is the same property that is set on WLError instances. - // Accessible as `.originalError` on a WLValidationError instance. - formattedErr.originalError = err; formattedErr.invalidAttributes = {}; formattedErr.invalidAttributes[matches[1]] = [{ value: matches[2], From 564d69f2a2bdc013b5405782bc9ee0b29aebf8e2 Mon Sep 17 00:00:00 2001 From: Oleg Zhvankov Date: Thu, 24 Sep 2015 15:26:27 +0300 Subject: [PATCH 2/2] Update adapter.js bug fix of path-1 thanx for U "focus" on removing formattedErr.originalError = err; its our mistake --- lib/adapter.js | 28 ++++++++-------------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/lib/adapter.js b/lib/adapter.js index e16162f1..8f03ba39 100644 --- a/lib/adapter.js +++ b/lib/adapter.js @@ -14,7 +14,6 @@ var utils = require('./utils'); var Processor = require('./processor'); var Cursor = require('waterline-cursor'); var hop = utils.object.hasOwnProperty; -var Query = require('./query'); module.exports = (function() { @@ -926,27 +925,13 @@ module.exports = (function() { var client = new pg.Client(connectionObject.config); client.connect(); - - //var schema = {}; - - //Object.keys(connectionObject.collections).forEach(function(coll) { - // schema[coll] = connectionObject.collections[coll].schema; - //}); - - // Build Query - //var _schema = collection.schema; - //var queryObj = new Query(_schema, schema); - //var query =queryObj.find(table, options); - var _schema = collection.waterline.schema; - //var processor = new Processor(schema); var sequel = new Sequel(_schema); var _query; // Build a query for the specific query strategy try { _query = sequel.find(table, options); - //console.log(_query.query[0]); } catch(e) { return cb(e); } @@ -1245,11 +1230,14 @@ module.exports = (function() { // WLValidationError in Waterline core. var matches = err.detail.match(/Key \((.*)\)=\((.*)\) already exists\.$/); if (matches && matches.length) { - formattedErr = {}; - formattedErr.code = 'E_UNIQUE'; - formattedErr.invalidAttributes = {}; - formattedErr.invalidAttributes[matches[1]] = [{ - value: matches[2], + formattedErr = {}; + formattedErr.code = 'E_UNIQUE'; + // This is the same property that is set on WLError instances. + // Accessible as `.originalError` on a WLValidationError instance. + formattedErr.originalError = err; + formattedErr.invalidAttributes = {}; + formattedErr.invalidAttributes[matches[1]] = [{ + value: matches[2], rule: 'unique' }]; }