Tuesday 26 September 2017

mssql, avoid multiple connections

I'm migrating from Postgres to MSSQL for my node application. For node, I can create a connection and then do individual queries using that connection, instead of making a connection for each query.const dbURL = process.env.DATABASE_URL; const client = new pg.Client(dbURL); client.connect(); client.query( /* SQL /*, callback); Is there a similar method in mssql? I've looked through the documentations and some stackoverflow posts. So far, I've tried this.const sql = require('mssql'); var config = { // db configs }; const connection = new sql.ConnectionPool(config); // sql.Connection is not a constructor connection.connect(); var request = new sql.Request(connection); request.query( /* SQL statement */, function(err, result) { // returns undefined console.log(result); }); Do all queries have to be made inside the connect()? If so, am I opening up a connection for each query?

Submitted September 26, 2017 at 05:58AM by eggtart_prince

No comments:

Post a Comment