From c3dd47f44833f41c46f0c94af110dc50f60a46f0 Mon Sep 17 00:00:00 2001 From: Matt Huggins Date: Thu, 13 Sep 2012 20:15:46 -0400 Subject: [PATCH] Allow for IN, NOT IN, and != queries in postgres --- lib/adapters/postgres.js | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/lib/adapters/postgres.js b/lib/adapters/postgres.js index 44e5a153..3604c5ee 100644 --- a/lib/adapters/postgres.js +++ b/lib/adapters/postgres.js @@ -229,22 +229,31 @@ PG.prototype.toFilter = function (model, filter) { var sqlCond = key; switch (condType) { case 'gt': - sqlCond += ' > '; - break; + sqlCond += ' > '; + break; case 'gte': - sqlCond += ' >= '; - break; + sqlCond += ' >= '; + break; case 'lt': - sqlCond += ' < '; - break; + sqlCond += ' < '; + break; case 'lte': - sqlCond += ' <= '; - break; + sqlCond += ' <= '; + break; case 'between': - sqlCond += ' BETWEEN '; - break; + sqlCond += ' BETWEEN '; + break; + case 'inq': + sqlCond += ' IN '; + break; + case 'nin': + sqlCond += ' NOT IN '; + break; + case 'neq': + sqlCond += ' != '; + break; } - sqlCond += filterValue; + sqlCond += (condType == 'inq' || condType == 'nin') ? '(' + filterValue + ')' : filterValue; fields.push(sqlCond); } else { fields.push('"' + key + '" = ' + filterValue);