mssql 11.0.0 → 12.0.0

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 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] [![Join the chat at https://gitter.im/patriksimek/node-mssql](https://badges.gitter.im/Join%20Chat.svg)](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][msnodesqlv8-url] (v2 native - Windows or Linux/macOS 64 bits only)
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
- npm install mssql
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
- * [Microsoft / Contributors Node V8 Driver for Node.js for SQL Server](#microsoft--contributors-node-v8-driver-for-nodejs-for-sql-server)
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
 
@@ -310,7 +351,7 @@ sql.on('error', err => {
310
351
 
311
352
  ### Streaming
312
353
 
313
- 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.
354
+ 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. Events must be attached before the query completes, but can be attached while in-flight.
314
355
 
315
356
  ```javascript
316
357
  const sql = require('mssql')
@@ -320,7 +361,6 @@ sql.connect(config, err => {
320
361
 
321
362
  const request = new sql.Request()
322
363
  request.stream = true // You can set streaming differently for each request
323
- request.query('select * from verylargetable') // or request.execute(procedure)
324
364
 
325
365
  request.on('recordset', columns => {
326
366
  // Emitted once for each recordset in a query
@@ -342,6 +382,8 @@ sql.connect(config, err => {
342
382
  request.on('done', result => {
343
383
  // Always emitted as the last one
344
384
  })
385
+
386
+ request.query('select * from verylargetable') // or request.execute(procedure)
345
387
  })
346
388
 
347
389
  sql.on('error', err => {
@@ -580,7 +622,7 @@ In addition to configuration object there is an option to pass config as a conne
580
622
  ```
581
623
  Server=localhost,1433;Database=database;User Id=username;Password=password;Encrypt=true
582
624
  ```
583
- ###### Standard configuration using msnodesqlv8 driver
625
+ ###### Standard configuration using MSNodeSQLv8 driver
584
626
  ```
585
627
  Driver=msnodesqlv8;Server=(local)\INSTANCE;Database=database;UID=DOMAIN\username;PWD=password;Encrypt=true
586
628
  ```
@@ -648,12 +690,21 @@ On top of the extra options, an `authentication` property can be added to the po
648
690
  - **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
691
  - **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
692
  - **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)
693
+ - `tedious` does not support Windows Authentication/Trusted Connection, however the `msnodesqlv8` driver does.
651
694
 
652
695
  More information about Tedious specific options: http://tediousjs.github.io/tedious/api-connection.html
653
696
 
654
- ### Microsoft / Contributors Node V8 Driver for Node.js for SQL Server
697
+ ___
698
+
699
+ ### MSNodeSQLv8
655
700
 
656
- **Requires Node.js v10+ or newer. Windows 32-64 bits or Linux/macOS 64 bits only.** This driver is not part of the default package and must be installed separately by `npm install msnodesqlv8@^2`. To use this driver, use this require syntax: `const sql = require('mssql/msnodesqlv8')`.
701
+ 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).
702
+
703
+ **To use this driver you must use this `require` statement:**
704
+
705
+ ```javascript
706
+ const sql = require('mssql/msnodesqlv8')
707
+ ```
657
708
 
658
709
  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
710
 
@@ -678,6 +729,8 @@ Driver={SQL Server Native Client 11.0};Server={#{server}\\#{instance}};Database=
678
729
 
679
730
  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
731
 
732
+ ___
733
+
681
734
  ## Connections
682
735
 
683
736
  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 +1394,7 @@ ps.prepare('select @param as value', err => {
1341
1394
 
1342
1395
  console.log(result.recordset[0].value) // return 12345
1343
1396
  console.log(result.rowsAffected) // Returns number of affected rows in case of INSERT, UPDATE or DELETE statement.
1344
-
1397
+
1345
1398
  ps.unprepare(err => {
1346
1399
  // ... error checks
1347
1400
  })
@@ -1374,9 +1427,9 @@ ps.prepare('select @param as value', err => {
1374
1427
 
1375
1428
  request.on('done', result => {
1376
1429
  // Always emitted as the last one
1377
-
1430
+
1378
1431
  console.log(result.rowsAffected) // Returns number of affected rows in case of INSERT, UPDATE or DELETE statement.
1379
-
1432
+
1380
1433
  ps.unprepare(err => {
1381
1434
  // ... error checks
1382
1435
  })
@@ -1682,7 +1735,7 @@ More information about JSON support can be found in [official documentation](htt
1682
1735
 
1683
1736
  ## Handling Duplicate Column Names
1684
1737
 
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.
1738
+ 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
1739
 
1687
1740
  Default behaviour:
1688
1741
  ```javascript
@@ -2067,6 +2120,16 @@ request.query('select @myval as myval', (err, result) => {
2067
2120
  - If you're facing problems with connecting SQL Server 2000, try setting the default TDS version to 7.1 with `config.options.tdsVersion = '7_1'` ([issue](https://github.com/tediousjs/node-mssql/issues/36))
2068
2121
  - If you're executing a statement longer than 4000 chars on SQL Server 2000, always use [batch](#batch-batch-callback) instead of [query](#query-command-callback) ([issue](https://github.com/tediousjs/node-mssql/issues/68))
2069
2122
 
2123
+ ## 10.x to 11.x changes
2124
+
2125
+ - Upgraded to tedious version 18
2126
+ - Dropped support for Node version <=16
2127
+
2128
+ ## 9.x to 10.x changes
2129
+
2130
+ - Upgraded to tedious version 16
2131
+ - Dropped support for Node version <= 14
2132
+
2070
2133
  ## 8.x to 9.x changes
2071
2134
 
2072
2135
  - Upgraded to tedious version 15
package/index.js CHANGED
@@ -1 +1,3 @@
1
+ 'use strict'
2
+
1
3
  module.exports = require('./lib/tedious')
@@ -7,7 +7,6 @@ const tarn = require('tarn')
7
7
  const { IDS } = require('../utils')
8
8
  const ConnectionError = require('../error/connection-error')
9
9
  const shared = require('../shared')
10
- const clone = require('rfdc/default')
11
10
  const { MSSQLError } = require('../error')
12
11
 
13
12
  /**
@@ -53,7 +52,7 @@ class ConnectionPool extends EventEmitter {
53
52
  throw ex
54
53
  }
55
54
  } else {
56
- this.config = clone(config)
55
+ this.config = config
57
56
  }
58
57
 
59
58
  // set defaults
@@ -53,6 +53,7 @@ class Request extends EventEmitter {
53
53
  * @param {Template literal} template
54
54
  * @return {String}
55
55
  */
56
+
56
57
  template () {
57
58
  const values = Array.prototype.slice.call(arguments)
58
59
  const strings = values.shift()
@@ -101,7 +102,7 @@ class Request extends EventEmitter {
101
102
  * Add an input parameter to the request.
102
103
  *
103
104
  * @param {String} name Name of the input parameter without @ char.
104
- * @param {*} [type] SQL data type of input parameter. If you omit type, module automaticaly decide which SQL data type should be used based on JS data type.
105
+ * @param {*} [type] SQL data type of input parameter. If you omit type, module automatically decides which SQL data type should be used based on JS data type.
105
106
  * @param {*} value Input parameter value. `undefined` and `NaN` values are automatically converted to `null` values.
106
107
  * @return {Request}
107
108
  */
@@ -147,7 +148,7 @@ class Request extends EventEmitter {
147
148
  * Replace an input parameter on the request.
148
149
  *
149
150
  * @param {String} name Name of the input parameter without @ char.
150
- * @param {*} [type] SQL data type of input parameter. If you omit type, module automaticaly decide which SQL data type should be used based on JS data type.
151
+ * @param {*} [type] SQL data type of input parameter. If you omit type, module automatically decides which SQL data type should be used based on JS data type.
151
152
  * @param {*} value Input parameter value. `undefined` and `NaN` values are automatically converted to `null` values.
152
153
  * @return {Request}
153
154
  */
@@ -253,7 +254,7 @@ class Request extends EventEmitter {
253
254
  return this
254
255
  }
255
256
 
256
- // Check is method was called as tagged template
257
+ // Check if method was called as tagged template
257
258
  if (typeof batch === 'object') {
258
259
  const values = Array.prototype.slice.call(arguments)
259
260
  const strings = values.shift()
@@ -376,6 +377,7 @@ class Request extends EventEmitter {
376
377
  * @param {Object} streamOptions - optional options to configure the readable stream with like highWaterMark
377
378
  * @return {Stream}
378
379
  */
380
+
379
381
  toReadableStream (streamOptions = {}) {
380
382
  this.stream = true
381
383
  this.pause()
@@ -407,6 +409,7 @@ class Request extends EventEmitter {
407
409
  * @param {Stream} stream Stream to pipe data into.
408
410
  * @return {Stream}
409
411
  */
412
+
410
413
  pipe (writableStream) {
411
414
  const readableStream = this.toReadableStream()
412
415
  return readableStream.pipe(writableStream)
@@ -450,7 +453,7 @@ class Request extends EventEmitter {
450
453
  return this
451
454
  }
452
455
 
453
- // Check is method was called as tagged template
456
+ // Check if method was called as tagged template
454
457
  if (typeof command === 'object') {
455
458
  const values = Array.prototype.slice.call(arguments)
456
459
  const strings = values.shift()
package/lib/datatypes.js CHANGED
@@ -1,4 +1,5 @@
1
1
  'use strict'
2
+
2
3
  const objectHasProperty = require('./utils').objectHasProperty
3
4
  const inspect = Symbol.for('nodejs.util.inspect.custom')
4
5
 
package/lib/shared.js CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict'
2
2
 
3
- const TYPES = require('./datatypes').TYPES
3
+ const { TYPES } = require('./datatypes')
4
4
  const Table = require('./table')
5
5
 
6
6
  let PromiseLibrary = Promise
@@ -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/lib/utils.js CHANGED
@@ -1,3 +1,5 @@
1
+ 'use strict'
2
+
1
3
  const IDS = new WeakMap()
2
4
  const INCREMENT = {
3
5
  Connection: 1,
package/msnodesqlv8.js CHANGED
@@ -1 +1,3 @@
1
+ 'use strict'
2
+
1
3
  module.exports = require('./lib/msnodesqlv8')
package/package.json CHANGED
@@ -21,27 +21,33 @@
21
21
  "azure",
22
22
  "node-mssql"
23
23
  ],
24
- "version": "11.0.0",
24
+ "version": "12.0.0",
25
25
  "main": "index.js",
26
26
  "type": "commonjs",
27
- "repository": "github:tediousjs/node-mssql",
27
+ "repository": {
28
+ "type": "git",
29
+ "url": "git+https://github.com/tediousjs/node-mssql.git"
30
+ },
31
+ "homepage": "https://github.com/tediousjs/node-mssql#readme",
32
+ "bugs": {
33
+ "url": "https://github.com/tediousjs/node-mssql/issues"
34
+ },
28
35
  "license": "MIT",
29
36
  "dependencies": {
30
- "@tediousjs/connection-string": "^0.5.0",
37
+ "@tediousjs/connection-string": "^0.6.0",
31
38
  "commander": "^11.0.0",
32
39
  "debug": "^4.3.3",
33
- "rfdc": "^1.3.0",
34
40
  "tarn": "^3.0.2",
35
- "tedious": "^18.2.1"
41
+ "tedious": "^19.0.0"
36
42
  },
37
43
  "devDependencies": {
38
- "@commitlint/cli": "^19.3.0",
39
- "@commitlint/config-conventional": "^19.2.2",
44
+ "@commitlint/cli": "^20.0.0",
45
+ "@commitlint/config-conventional": "^20.0.0",
40
46
  "@semantic-release/commit-analyzer": "^11.1.0",
41
47
  "@semantic-release/github": "^9.2.6",
42
48
  "@semantic-release/npm": "^11.0.3",
43
49
  "@semantic-release/release-notes-generator": "^12.1.0",
44
- "mocha": "^10.0.0",
50
+ "mocha": "^11.0.1",
45
51
  "semantic-release": "^22.0.12",
46
52
  "standard": "^17.0.0"
47
53
  },
@@ -64,6 +70,6 @@
64
70
  "test-cli": "mocha --exit -t 15000 test/common/cli.js"
65
71
  },
66
72
  "bin": {
67
- "mssql": "./bin/mssql"
73
+ "mssql": "bin/mssql"
68
74
  }
69
75
  }
package/tedious.js CHANGED
@@ -1 +1,3 @@
1
+ 'use strict'
2
+
1
3
  module.exports = require('./lib/tedious')