# node-mssql [![Dependency Status](https://david-dm.org/patriksimek/node-mssql.png)](https://david-dm.org/patriksimek/node-mssql) [![NPM version](https://badge.fury.io/js/mssql.png)](http://badge.fury.io/js/mssql)
An easy-to-use MSSQL database connector for Node.js.
There are some TDS modules which offer functionality to communicate with MSSQL databases but none of them does offer enough comfort - implementation takes a lot of lines of code. So I decided to create this module, that make work as easy as it could without losing any important functionality. node-mssql uses other TDS modules as drivers and offer easy to use unified interface. It also add extra features and bug fixes.
There is also [co](https://github.com/visionmedia/co) wrapper available - [co-mssql](https://github.com/patriksimek/co-mssql).
**Extra features:**
- Unified interface for multiple MSSQL modules
- Connection pooling with Transactions and Prepared statements
- Parametrized Stored Procedures in [node-tds](https://github.com/cretz/node-tds) and [Microsoft Driver for Node.js for SQL Server](https://github.com/WindowsAzure/node-sqlserver)
- Serialization of Geography and Geometry CLR types
- Injects original TDS modules with enhancements and bug fixes
At the moment it support three TDS modules:
- [Tedious](https://github.com/pekim/tedious) by Mike D Pilsbury (pure javascript - windows/osx/linux)
- [Microsoft Driver for Node.js for SQL Server](https://github.com/WindowsAzure/node-sqlserver) by Microsoft Corporation (native - windows only)
- [node-tds](https://github.com/cretz/node-tds) by Chad Retz (pure javascript - windows/osx/linux)
## What's new in 1.2.x (stable, npm)
- Updated to latest Tedious 1.4.x
- Added support bulk insert (#bulk)
## Installation
npm install mssql
## Quick Example
```javascript
var sql = require('mssql');
var config = {
user: '...',
password: '...',
server: 'localhost', // You can use 'localhost\\instance' to connect to named instance
database: '...',
options: {
encrypt: true // Use this if you're on Windows Azure
}
}
var connection = new sql.Connection(config, function(err) {
// ... error checks
// Query
var request = new sql.Request(connection); // or: var request = connection.request();
request.query('select 1 as number', function(err, recordset) {
// ... error checks
console.dir(recordset);
});
// Stored Procedure
var request = new sql.Request(connection);
request.input('input_parameter', sql.Int, 10);
request.output('output_parameter', sql.VarChar(50));
request.execute('procedure_name', function(err, recordsets, returnValue) {
// ... error checks
console.dir(recordsets);
});
});
```
### Quick Example with one global connection
```javascript
var sql = require('mssql');
var config = {
user: '...',
password: '...',
server: 'localhost', // You can use 'localhost\\instance' to connect to named instance
database: '...',
options: {
encrypt: true // Use this if you're on Windows Azure
}
}
sql.connect(config, function(err) {
// ... error checks
// Query
var request = new sql.Request();
request.query('select 1 as number', function(err, recordset) {
// ... error checks
console.dir(recordset);
});
// Stored Procedure
var request = new sql.Request();
request.input('input_parameter', sql.Int, value);
request.output('output_parameter', sql.VarChar(50));
request.execute('procedure_name', function(err, recordsets, returnValue) {
// ... error checks
console.dir(recordsets);
});
});
```
<a name="streaming" />
### Streaming example with one global connection
If you plan to work with large amount of rows, you should always use streaming. Once you enable this, you must listen for events to receive data.
```javascript
var sql = require('mssql');
var config = {
user: '...',
password: '...',
server: 'localhost', // You can use 'localhost\\instance' to connect to named instance
database: '...',
stream: true, // You can enable streaming globally
options: {
encrypt: true // Use this if you're on Windows Azure
}
}
sql.connect(config, function(err) {
// ... error checks
var request = new sql.Request();
request.stream = true; // You can set streaming differently for each request
request.query('select * from verylargetable'); // or request.execute(procedure);
request.on('recordset', function(columns) {
// Emitted once for each recordset in a query
});
request.on('row', function(row) {
// Emitted for each row in a recordset
});
request.on('error', function(err) {
// May be emitted multiple times
});
request.on('done', function(returnValue) {
// Always emitted as the last one
});
});
```
## Documentation
### Configuration
* [Basic](#cfg-basic)
* [Tedious](#cfg-tedious)
* [Microsoft Driver for Node.js for SQL Server](#cfg-msnodesql)
* [node-tds](#cfg-node-tds)
### Connections
* [Connection](#connection)
* [connect](#connect)
* [close](#close)
### Requests
* [Request](#request)
* [execute](#execute)
* [input](#input)
* [output](#output)
* [query](#query)
* [batch](#batch)
* [bulk](#bulk)
* [cancel](#cancel)
### Transactions
* [Transaction](#transaction)
* [begin](#begin)
* [commit](#commit)
* [rollback](#rollback)
### Prepared Statements
* [PreparedStatement](#prepared-statement)
* [input](#prepared-statement-input)
* [output](#prepared-statement-output)
* [prepare](#prepare)
* [execute](#prepared-statement-execute)
* [unprepare](#unprepare)
### Other
* [Geography and Geometry](#geography)
* [Table-Valued Parameter](#tvp)
* [Errors](#errors)
* [Metadata](#meta)
* [Data Types](#data-types)
* [SQL injection](#injection)
* [Verbose Mode](#verbose)
* [Known Issues](#issues)
## Configuration
```javascript
var config = {
user: '...',
password: '...',
server: 'localhost',
database: '...',
pool: {
max: 10,
min: 0,
idleTimeoutMillis: 30000
}
}
```
<a name="cfg-basic" />
### Basic configuration is same for all drivers.
- **driver** - Driver to use (default: `tedious`). Possible values: `tedious`, `msnodesql` or `tds`.
- **user** - User name to use for authentication.
- **password** - Password to use for authentication.
- **server** - Server to connect to. You can use 'localhost\\instance' to connect to named instance.
- **port** - Port to connect to (default: `1433`). Don't set when connecting to named instance.
- **domain** - Once you set domain, driver will connect to SQL Server using domain login.
- **database** - Database to connect to (default: dependent on server configuration).
- **connectionTimeout** - Connection timeout in ms (default: `15000`).
- **requestTimeout** - Request timeout in ms (default: `15000`).
- **stream** - Stream recordsets/rows instead of returning them all at once as an argument of callback (default: `false`). You can also enable streaming for each request independently (`request.stream = true`). Always set to `true` if you plan to work with large amount of rows.
- **pool.max** - The maximum number of connections there can be in the pool (default: `10`).
- **pool.min** - The minimun of connections there can be in the pool (default: `0`).
- **pool.idleTimeoutMillis** - The Number of milliseconds before closing an unused connection (default: `30000`).
<a name="cfg-tedious" />
### Tedious
- **options.instanceName** - The instance name to connect to. The SQL Server Browser service must be running on the database server, and UDP port 1444 on the database server must be reachable.
- **options.useUTC** - A boolean determining whether or not use UTC time for values without time zone offset (default: `true`).
- **options.encrypt** - A boolean determining whether or not the connection will
没有合适的资源?快使用搜索试试~ 我知道了~
nodejs+easyui+mysql+mssql登陆增删改查带数据库
共1576个文件
js:753个
png:195个
css:133个
5星 · 超过95%的资源 需积分: 1 255 下载量 127 浏览量
2014-10-08
23:43:51
上传
评论 1
收藏 10.49MB ZIP 举报
温馨提示
nodejs+easyui+mysql+mssql登陆增删改查带数据库,提供简单代码供大家参考,顺便赚取点分,希望大家支持
资源推荐
资源详情
资源评论
收起资源包目录
nodejs+easyui+mysql+mssql登陆增删改查带数据库 (1576个子文件)
no.2js 23B
no.2js 23B
make.bat 1KB
make.bat 1KB
libmysql_password.c 4KB
BigDecTest.class 1KB
BigDecTest.class 1KB
node-supervisor.cmd 206B
supervisor.cmd 206B
express.cmd 139B
jade.cmd 133B
main.coffee 29KB
tedious.coffee 21KB
tds.coffee 12KB
msnodesql.coffee 12KB
udt.coffee 4KB
datatypes.coffee 3KB
table.coffee 2KB
tds-fix.coffee 884B
isolationlevel.coffee 121B
.coffeemaker 45B
bootstrap.min.css 97KB
easyui.css 44KB
easyui.css 44KB
easyui.css 43KB
easyui.css 43KB
easyui.css 40KB
tabs.css 8KB
tabs.css 8KB
tabs.css 8KB
tabs.css 8KB
docco.css 7KB
tabs.css 6KB
datagrid.css 5KB
datagrid.css 5KB
datagrid.css 5KB
datagrid.css 5KB
style.css 5KB
datagrid.css 4KB
calendar.css 3KB
calendar.css 3KB
calendar.css 3KB
calendar.css 3KB
calendar.css 3KB
tree.css 3KB
tree.css 3KB
tree.css 3KB
tree.css 3KB
tree.css 3KB
linkbutton.css 3KB
linkbutton.css 3KB
linkbutton.css 3KB
panel.css 3KB
panel.css 3KB
panel.css 2KB
panel.css 2KB
linkbutton.css 2KB
linkbutton.css 2KB
style.css 2KB
panel.css 2KB
menu.css 2KB
menu.css 2KB
menu.css 2KB
menu.css 2KB
menu.css 2KB
window.css 2KB
window.css 2KB
window.css 2KB
window.css 2KB
layout.css 2KB
layout.css 2KB
layout.css 2KB
layout.css 2KB
layout.css 2KB
icon.css 2KB
window.css 2KB
slider.css 2KB
slider.css 2KB
slider.css 2KB
slider.css 2KB
slider.css 2KB
searchbox.css 1KB
searchbox.css 1KB
searchbox.css 1KB
searchbox.css 1KB
searchbox.css 1KB
pagination.css 1KB
pagination.css 1KB
pagination.css 1KB
pagination.css 1KB
pagination.css 1KB
qunit.css 1KB
validatebox.css 1KB
validatebox.css 1KB
validatebox.css 1KB
validatebox.css 1KB
validatebox.css 1KB
spinner.css 1KB
spinner.css 1KB
spinner.css 1KB
共 1576 条
- 1
- 2
- 3
- 4
- 5
- 6
- 16
墙角绝对有个洞
- 粉丝: 2
- 资源: 3
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
- 5
前往页