Sign up ×
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute:

Is there something special i need to do with a parameterized query?

the following seems to succeed (i'm using a promise-ified client.query see end),

console.log('cancel for', data);
var cancelInviteQuery = 'delete from friendship where user_1=$1 and user_2_canonical=$2';
return query(cancelInviteQuery, [data.id, data.friend])
  .then(function (results) {
    console.log('ran delete frienship', results);
  })
  .catch(function (error) {
    console.error('failed to drop friendship', error);
  });

because i get the output:

cancel for {"id":3,"friend":"m"}
ran delete frienship []

but then the following query of the database shows the record still exists

select * from friendship;
 id | user_1 | user_2 | user_2_canonical | confirmed | ignored 
----+--------+--------+------------------+-----------+---------
  8 |      3 |      9 | m                | f         | f

and then the following query succeeds when I make it directly against the database (using psql client)

delete from friendship where user_1=3 and user_2_canonical='m'

my query function (a wrapper for node-postgres's client.query):

function query(sql, params) {
  var promise = new RSVP.Promise(function (resolve, reject) {
    pg.connect(CONNECTIONSTRING, function (error, client, done) {
      if (error) { reject(error); return; }

      client.query(sql, params, function (error, result) {
        done(); // Greedy close.
        if (error) {
          reject(error);
          return;
        }
        else if (result.hasOwnProperty('rows')) {
          resolve(result.rows);
        } else { resolve(result.rows); }
      });
    });
  });
  return promise;
}
share|improve this question
    
Something is wrong with your data variable. In the console.log it is displaying "friend":"m" but you are expecting it to be "friend":"mike". – victorkohl Mar 3 at 0:29
    
sorry @victorkohl it was a sloppy paste. – Michael Mar 3 at 0:33
    
Do you solve this problem? If not send more info – Emilio Platzer Aug 9 at 12:40
    
I have not solved it yet, but i still don't know what more to provide. – Michael Aug 9 at 19:17

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.