mssql 10.0.4 → 11.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +71 -19
- package/lib/datatypes.js +1 -0
- package/lib/shared.js +7 -1
- package/package.json +10 -10
package/README.md
CHANGED
|
@@ -1,16 +1,31 @@
|
|
|
1
1
|
# node-mssql
|
|
2
2
|
|
|
3
|
-
Microsoft SQL Server client for Node.js
|
|
3
|
+
**Microsoft SQL Server client for Node.js**
|
|
4
4
|
|
|
5
5
|
[![NPM Version][npm-image]][npm-url] [![NPM Downloads][downloads-image]][downloads-url] [![Appveyor CI][appveyor-image]][appveyor-url] [](https://gitter.im/patriksimek/node-mssql?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
|
6
6
|
|
|
7
7
|
Supported TDS drivers:
|
|
8
|
+
|
|
8
9
|
- [Tedious][tedious-url] (pure JavaScript - Windows/macOS/Linux, default)
|
|
9
|
-
- [Microsoft / Contributors Node V8 Driver for Node.js for SQL Server
|
|
10
|
+
- [MSNodeSQLv8][msnodesqlv8-url] (Microsoft / Contributors Node V8 Driver for Node.js for SQL Server, v2 native - Windows or Linux/macOS 64 bits only)
|
|
10
11
|
|
|
11
12
|
## Installation
|
|
12
13
|
|
|
13
|
-
|
|
14
|
+
### Tedious driver (default)
|
|
15
|
+
|
|
16
|
+
```
|
|
17
|
+
npm install mssql
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
### MSNodeSQLv8 driver (optional)
|
|
21
|
+
|
|
22
|
+
```
|
|
23
|
+
npm install mssql msnodesqlv8
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## SQL Server prerequisites
|
|
27
|
+
|
|
28
|
+
This package requires TCP/IP to connect to SQL Server, and you may need to enable this in your installation.
|
|
14
29
|
|
|
15
30
|
## Short Example: Use Connect String
|
|
16
31
|
|
|
@@ -68,6 +83,32 @@ const sqlConfig = {
|
|
|
68
83
|
})()
|
|
69
84
|
```
|
|
70
85
|
|
|
86
|
+
## Windows Authentication Example Using MSNodeSQLv8
|
|
87
|
+
|
|
88
|
+
```javascript
|
|
89
|
+
const sql = require('mssql/msnodesqlv8');
|
|
90
|
+
|
|
91
|
+
const config = {
|
|
92
|
+
server: "MyServer",
|
|
93
|
+
database: "MyDatabase",
|
|
94
|
+
options: {
|
|
95
|
+
trustedConnection: true, // Set to true if using Windows Authentication
|
|
96
|
+
trustServerCertificate: true, // Set to true if using self-signed certificates
|
|
97
|
+
},
|
|
98
|
+
driver: "msnodesqlv8", // Required if using Windows Authentication
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
(async () => {
|
|
102
|
+
try {
|
|
103
|
+
await sql.connect(config);
|
|
104
|
+
const result = await sql.query`select TOP 10 * from MyTable`;
|
|
105
|
+
console.dir(result);
|
|
106
|
+
} catch (err) {
|
|
107
|
+
console.error(err);
|
|
108
|
+
}
|
|
109
|
+
})();
|
|
110
|
+
```
|
|
111
|
+
|
|
71
112
|
## Documentation
|
|
72
113
|
|
|
73
114
|
### Examples
|
|
@@ -87,7 +128,7 @@ const sqlConfig = {
|
|
|
87
128
|
### Drivers
|
|
88
129
|
|
|
89
130
|
* [Tedious](#tedious)
|
|
90
|
-
* [
|
|
131
|
+
* [MSNodeSQLv8](#msnodesqlv8)
|
|
91
132
|
|
|
92
133
|
### Connections
|
|
93
134
|
|
|
@@ -174,16 +215,16 @@ const sql = require('mssql')
|
|
|
174
215
|
let result1 = await pool.request()
|
|
175
216
|
.input('input_parameter', sql.Int, value)
|
|
176
217
|
.query('select * from mytable where id = @input_parameter')
|
|
177
|
-
|
|
218
|
+
|
|
178
219
|
console.dir(result1)
|
|
179
|
-
|
|
220
|
+
|
|
180
221
|
// Stored procedure
|
|
181
|
-
|
|
222
|
+
|
|
182
223
|
let result2 = await pool.request()
|
|
183
224
|
.input('input_parameter', sql.Int, value)
|
|
184
225
|
.output('output_parameter', sql.VarChar(50))
|
|
185
226
|
.execute('procedure_name')
|
|
186
|
-
|
|
227
|
+
|
|
187
228
|
console.dir(result2)
|
|
188
229
|
} catch (err) {
|
|
189
230
|
// ... error checks
|
|
@@ -208,7 +249,7 @@ sql.on('error', err => {
|
|
|
208
249
|
|
|
209
250
|
sql.connect(config).then(pool => {
|
|
210
251
|
// Query
|
|
211
|
-
|
|
252
|
+
|
|
212
253
|
return pool.request()
|
|
213
254
|
.input('input_parameter', sql.Int, value)
|
|
214
255
|
.query('select * from mytable where id = @input_parameter')
|
|
@@ -229,9 +270,9 @@ sql.on('error', err => {
|
|
|
229
270
|
})
|
|
230
271
|
|
|
231
272
|
sql.connect(config).then(pool => {
|
|
232
|
-
|
|
273
|
+
|
|
233
274
|
// Stored procedure
|
|
234
|
-
|
|
275
|
+
|
|
235
276
|
return pool.request()
|
|
236
277
|
.input('input_parameter', sql.Int, value)
|
|
237
278
|
.output('output_parameter', sql.VarChar(50))
|
|
@@ -263,7 +304,7 @@ sql.on('error', err => {
|
|
|
263
304
|
})
|
|
264
305
|
```
|
|
265
306
|
|
|
266
|
-
All values are automatically sanitized against sql injection.
|
|
307
|
+
All values are automatically sanitized against sql injection.
|
|
267
308
|
This is because it is rendered as prepared statement, and thus all limitations imposed in MS SQL on parameters apply.
|
|
268
309
|
e.g. Column names cannot be passed/set in statements using variables.
|
|
269
310
|
|
|
@@ -580,7 +621,7 @@ In addition to configuration object there is an option to pass config as a conne
|
|
|
580
621
|
```
|
|
581
622
|
Server=localhost,1433;Database=database;User Id=username;Password=password;Encrypt=true
|
|
582
623
|
```
|
|
583
|
-
###### Standard configuration using
|
|
624
|
+
###### Standard configuration using MSNodeSQLv8 driver
|
|
584
625
|
```
|
|
585
626
|
Driver=msnodesqlv8;Server=(local)\INSTANCE;Database=database;UID=DOMAIN\username;PWD=password;Encrypt=true
|
|
586
627
|
```
|
|
@@ -648,12 +689,21 @@ On top of the extra options, an `authentication` property can be added to the po
|
|
|
648
689
|
- **authentication** - An object with authentication settings, according to the [Tedious Documentation](https://tediousjs.github.io/tedious/api-connection.html). Passing this object will override `user`, `password`, `domain` settings.
|
|
649
690
|
- **authentication.type** - Type of the authentication method, valid types are `default`, `ntlm`, `azure-active-directory-password`, `azure-active-directory-access-token`, `azure-active-directory-msi-vm`, or `azure-active-directory-msi-app-service`
|
|
650
691
|
- **authentication.options** - Options of the authentication required by the `tedious` driver, depends on `authentication.type`. For more details, check [Tedious Authentication Interfaces](https://github.com/tediousjs/tedious/blob/v11.1.1/src/connection.ts#L200-L318)
|
|
692
|
+
- `tedious` does not support Windows Authentication/Trusted Connection, however the `msnodesqlv8` driver does.
|
|
651
693
|
|
|
652
694
|
More information about Tedious specific options: http://tediousjs.github.io/tedious/api-connection.html
|
|
653
695
|
|
|
654
|
-
|
|
696
|
+
___
|
|
655
697
|
|
|
656
|
-
|
|
698
|
+
### MSNodeSQLv8
|
|
699
|
+
|
|
700
|
+
Alternative driver, requires Node.js v10+ or newer; Windows (32 or 64-bit) or Linux/macOS (64-bit only). It's not part of the default package so it must be [installed](#msnodesqlv8-driver) in addition. Supports [Windows/Trusted Connection authentication](#windows-authentication-example-using-msnodesqlv8).
|
|
701
|
+
|
|
702
|
+
**To use this driver you must use this `require` statement:**
|
|
703
|
+
|
|
704
|
+
```javascript
|
|
705
|
+
const sql = require('mssql/msnodesqlv8')
|
|
706
|
+
```
|
|
657
707
|
|
|
658
708
|
Note: If you use import into your lib to prepare your request (`const { VarChar } = require('mssql')`) you also need to upgrade all your types import into your code (`const { VarChar } = require('mssql/msnodesqlv8')`) or a `connection.on is not a function` error will be thrown.
|
|
659
709
|
|
|
@@ -678,6 +728,8 @@ Driver={SQL Server Native Client 11.0};Server={#{server}\\#{instance}};Database=
|
|
|
678
728
|
|
|
679
729
|
Please note that the connection string with this driver is not the same than tedious and use yes/no instead of true/false. You can see more on the [ODBC](https://docs.microsoft.com/fr-fr/dotnet/api/system.data.odbc.odbcconnection.connectionstring?view=dotnet-plat-ext-5.0) documentation.
|
|
680
730
|
|
|
731
|
+
___
|
|
732
|
+
|
|
681
733
|
## Connections
|
|
682
734
|
|
|
683
735
|
Internally, each `ConnectionPool` instance is a separate pool of TDS connections. Once you create a new `Request`/`Transaction`/`Prepared Statement`, a new TDS connection is acquired from the pool and reserved for desired action. Once the action is complete, connection is released back to the pool. Connection health check is built-in so once the dead connection is discovered, it is immediately replaced with a new one.
|
|
@@ -1341,7 +1393,7 @@ ps.prepare('select @param as value', err => {
|
|
|
1341
1393
|
|
|
1342
1394
|
console.log(result.recordset[0].value) // return 12345
|
|
1343
1395
|
console.log(result.rowsAffected) // Returns number of affected rows in case of INSERT, UPDATE or DELETE statement.
|
|
1344
|
-
|
|
1396
|
+
|
|
1345
1397
|
ps.unprepare(err => {
|
|
1346
1398
|
// ... error checks
|
|
1347
1399
|
})
|
|
@@ -1374,9 +1426,9 @@ ps.prepare('select @param as value', err => {
|
|
|
1374
1426
|
|
|
1375
1427
|
request.on('done', result => {
|
|
1376
1428
|
// Always emitted as the last one
|
|
1377
|
-
|
|
1429
|
+
|
|
1378
1430
|
console.log(result.rowsAffected) // Returns number of affected rows in case of INSERT, UPDATE or DELETE statement.
|
|
1379
|
-
|
|
1431
|
+
|
|
1380
1432
|
ps.unprepare(err => {
|
|
1381
1433
|
// ... error checks
|
|
1382
1434
|
})
|
|
@@ -1682,7 +1734,7 @@ More information about JSON support can be found in [official documentation](htt
|
|
|
1682
1734
|
|
|
1683
1735
|
## Handling Duplicate Column Names
|
|
1684
1736
|
|
|
1685
|
-
If your queries contain output columns with identical names, the default behaviour of `mssql` will only return column metadata for the last column with that name. You will also not always be able to re-assemble the order of output columns requested.
|
|
1737
|
+
If your queries contain output columns with identical names, the default behaviour of `mssql` will only return column metadata for the last column with that name. You will also not always be able to re-assemble the order of output columns requested.
|
|
1686
1738
|
|
|
1687
1739
|
Default behaviour:
|
|
1688
1740
|
```javascript
|
package/lib/datatypes.js
CHANGED
package/lib/shared.js
CHANGED
|
@@ -57,7 +57,6 @@ const getTypeByValue = function (value) {
|
|
|
57
57
|
return TYPES.NVarChar
|
|
58
58
|
|
|
59
59
|
case 'number':
|
|
60
|
-
case 'bigint':
|
|
61
60
|
if (value % 1 === 0) {
|
|
62
61
|
if (value < -2147483648 || value > 2147483647) {
|
|
63
62
|
return TYPES.BigInt
|
|
@@ -68,6 +67,13 @@ const getTypeByValue = function (value) {
|
|
|
68
67
|
return TYPES.Float
|
|
69
68
|
}
|
|
70
69
|
|
|
70
|
+
case 'bigint':
|
|
71
|
+
if (value < -2147483648n || value > 2147483647n) {
|
|
72
|
+
return TYPES.BigInt
|
|
73
|
+
} else {
|
|
74
|
+
return TYPES.Int
|
|
75
|
+
}
|
|
76
|
+
|
|
71
77
|
case 'boolean':
|
|
72
78
|
for (const item of Array.from(map)) {
|
|
73
79
|
if (item.js === Boolean) {
|
package/package.json
CHANGED
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"azure",
|
|
22
22
|
"node-mssql"
|
|
23
23
|
],
|
|
24
|
-
"version": "
|
|
24
|
+
"version": "11.0.1",
|
|
25
25
|
"main": "index.js",
|
|
26
26
|
"type": "commonjs",
|
|
27
27
|
"repository": "github:tediousjs/node-mssql",
|
|
@@ -32,21 +32,21 @@
|
|
|
32
32
|
"debug": "^4.3.3",
|
|
33
33
|
"rfdc": "^1.3.0",
|
|
34
34
|
"tarn": "^3.0.2",
|
|
35
|
-
"tedious": "^
|
|
35
|
+
"tedious": "^18.2.1"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"@commitlint/cli": "^19.0
|
|
39
|
-
"@commitlint/config-conventional": "^19.
|
|
40
|
-
"@semantic-release/commit-analyzer": "^
|
|
41
|
-
"@semantic-release/github": "^
|
|
42
|
-
"@semantic-release/npm": "^
|
|
43
|
-
"@semantic-release/release-notes-generator": "^
|
|
38
|
+
"@commitlint/cli": "^19.3.0",
|
|
39
|
+
"@commitlint/config-conventional": "^19.2.2",
|
|
40
|
+
"@semantic-release/commit-analyzer": "^11.1.0",
|
|
41
|
+
"@semantic-release/github": "^9.2.6",
|
|
42
|
+
"@semantic-release/npm": "^11.0.3",
|
|
43
|
+
"@semantic-release/release-notes-generator": "^12.1.0",
|
|
44
44
|
"mocha": "^10.0.0",
|
|
45
|
-
"semantic-release": "^
|
|
45
|
+
"semantic-release": "^22.0.12",
|
|
46
46
|
"standard": "^17.0.0"
|
|
47
47
|
},
|
|
48
48
|
"engines": {
|
|
49
|
-
"node": ">=
|
|
49
|
+
"node": ">=18"
|
|
50
50
|
},
|
|
51
51
|
"files": [
|
|
52
52
|
"lib/",
|