A simple reusable class to query a MS SQL Server database. This uses the mssql package to access SQL Server.
Since this is largely used for personal projects, this is not an npm package. Nevertheless, you may still install this by adding the following to your package.json:
{
"dependencies": {
"@roncli/node-database": "roncli/node-database#v1.2.15"
}
}
const Db = require("@roncli/node-database");
const db = new Db({
server: "ms.sql.server.com",
port: 1433,
user: "my_user_name",
password: "my_password",
database: "my_database",
pool: {
max: 50,
min: 0,
idleTimeoutMillis: 30000
},
options: {
trustServerCertificate: true
}
});
try {
const data = await db.query(
"SELECT col1, col2 FROM myTable WHERE col3 = @col3",
{col3: {type: Db.INT, value: 123}}
);
if (data && data.recordsets && data.recordsets[0]) {
data.recordsets[0].forEach((row) => {
console.log(`Col1: ${row.col1}, Col2: ${row.col2}`);
});
}
} catch (err) {
console.log("There was an error connecting to the database.");
console.log(err);
}
See the mssql package for more examples of settings and how to query using the library.
- Package updates.
- Package updates.
- Package updates.
- Package updates.
- Package updates.
- Package updates.
- Package updates.
- Package updates.
- Package updates.
- Package updates.
- Package updates.
- Add typings.
- Use awaits in example.
- Package updates.
- Package updates.
- Package updates.
- Attempt to close existing SQL connection before opening a new one, even if it may not seem necessary.
- Improve handling of dead connections.
- Fix concurrency issues.
- ES7 update.
- Fixed bug with errors thrown by mssql being uncaught rejections, ie: server timeouts, etc.
- Use promises recently added to the mssql library for better exception handling.
- Make the class more object-oriented so that we can have multiple instances connecting to multiple databases.
- Initial release.