javascript - Node.js and Heroku, how to insert a second query? -


i working node.js , heroku; , have question following code, found online:

app.get('/db', function (request, response) {   pg.connect(process.env.database_url, function(err, client, done) {     client.query('select * test_table', function(err, result) {       done();       if (err)        { console.error(err); response.send("error " + err); }       else        { response.render('pages/db', {results: result.rows} ); }     });   }); }); 

this lists contents of test_table table, want perform following query:

*"insert test_table (fieldone, fieldtwo) values (max(fieldone)+1, max(fieldtwo)2)"

how can integrate in code above?

here tried, no success:

app.get('/db', function (request, response) {   pg.connect(process.env.database_url, function(err, client, done) {     client.query('select * test_table', function(err, result) {       done();       if (err)        { console.error(err); response.send("error " + err); }       else {          response.render('pages/db', {results: result.rows} );          client.query("insert test_table  (id, name) values (max(id)+1,'test')", function(err, result) {done();});       }     });   }); }); 

i don't know if last chunk of code right or totally wrong. can db table (test_table) not updated.

in case might else, post here change made have code work:

app.get('/db', function (request, response) {   pg.connect(process.env.database_url, function(err, client, done) {     client.query('select * test_table', function(err, result) {       done();       if (err)        { console.error(err); response.send("error " + err); }       else {          response.render('pages/db', {results: result.rows} );          client.query("insert test_table  (id, name) values ((select max(id) test_table)+1,'test')", function(err2, result2) {done();});       }     });   }); }); 

there must other things said this, @ least works.


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -