diff --git a/lib/adapter.js b/lib/adapter.js index 26eba2dd..8f03ba39 100644 --- a/lib/adapter.js +++ b/lib/adapter.js @@ -925,20 +925,20 @@ module.exports = (function() { var client = new pg.Client(connectionObject.config); client.connect(); + var _schema = collection.waterline.schema; + var sequel = new Sequel(_schema); + + var _query; + // Build a query for the specific query strategy + try { + _query = sequel.find(table, options); + } catch(e) { + return cb(e); + } - 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); // 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) { @@ -1230,14 +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 = {}; + 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], + formattedErr.originalError = err; + formattedErr.invalidAttributes = {}; + formattedErr.invalidAttributes[matches[1]] = [{ + value: matches[2], rule: 'unique' }]; }