dresende / node-sql-query

NodeJS SQL query builder
122 stars 103 forks source link

UPDATE and WHERE keeps adding to itself #62

Closed si458 closed 4 years ago

si458 commented 4 years ago

having a strange one with nodejs and express and just displaying the output as string

thedb.sql = require('sql-query');
thedb.sqlquery = thedb.sql.Query('sqlite');
thedb.sqlupdate = thedb.sqlquery.update();
var query = thedb.sqlupdate.into("metrics").set({ metrics_name: req.body.name }).where({ metrics_id: req.body.id }).build();

output:

UPDATE `metrics` SET `metrics_name` = 'my metric name' WHERE `metrics_id` = '24'

but refresh webpage

output:

UPDATE `metrics` SET `metrics_name` = 'my metric name' WHERE (`metrics_id` = '24') AND (`metrics_id` = '24')

why is it adding to the where instead of clearing it and starting a fresh?

si458 commented 4 years ago

IGNORE: i was reusing my thedb.sqlupdate over and over, instead of doing a new thedb.sqlquery.update() every time

var query = thedb.sqlquery.update().into("metrics").set({ metrics_name: req.body.name }).where({ metrics_id: req.body.id }).build();