tacitjs
v1.1.4
Published
A simple MSSQL library
Downloads
3
Readme
tacit.js
A simple mssql library
Built on top of mssql and tsqljs
Install
$ npm i --save tacitjs
Examples
// Require the module
var tacit = require('tacitjs')({
server: 'localhost',
user: 'enterprise-admin',
password: 'enterprise-password',
database: 'enterprise-database'
});
/* Create a table */
CREATE TABLE users
(
id INT PRIMARY KEY IDENTITY(1,1),
email NVARCHAR(256),
createdAt NOT NULL CONSTRAINT DF_MyTable_CreateDate_GETDATE DEFAULT GETDATE()
)
Insert a record
var tables = {
users: "users"
};
tacit
.insert(tables.users, { email: "[email protected]" })
.then(function(rows) {
/*
rows === [
{
id: "1",
email: "[email protected]",
createdAt: ...
}
]
*/
})
Find a record with a where clause
tacit
.where(tables.users, "id = @1", "1")
.then(function(rows) {
/*
rows === [
{
id: "1",
email: "[email protected]",
createdAt: ...
}
]
*/
});
Update a record
tacit
.update(tables.users, { email: "[email protected]" }, "id = @1", "1")
.then(function(rows) {
/*
rows === [
{
id: "1",
email: "[email protected]",
createdAt: ...
}
]
*/
});
Delete a record
tacit
.delete(tables.users, "id = @1", "1")
.then(function(rows) {
/*
rows === [
{
id: "1",
email: "[email protected]",
createdAt: ...
}
]
*/
]
});
Query with abitrary sql
tacit
.sql("insert into users (email) output inserted.* values (@1)", ["[email protected]"])
.then(function(rows) {
/*
rows === [
{
id: "2",
email: "[email protected]",
createdAt: ...
}
]
*/
});
Execute a stored procedure
tacit
.execute("stored_procedure_name", { param1: "param1", param2: "param2" })
.then(function(result) {
/*
result === {
"recordsets": [ [{ some: "data", maybe: "?" }] ],
"returnValue": 0
}
*/
});
Tests
// Grab a sql server database (appharbor has a free one)
$ git clone [email protected]:swlkr/tacitjs.git
$ npm i
$ touch .env
$ echo "SERVER=<server name>" >> .env
$ echo "DATABASE=<database name>" >> .env
$ echo "USER_ID=<User Id>" >> .env
$ echo "PASSWORD=<Password>" >> .env
$ npm test
What's with the name?
Relational database transactions are guaranteed through ACID, and tacit kind of sounds like acid... just... don't worry about it.