mssql 4.0.4 → 4.1.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/CHANGELOG.txt CHANGED
@@ -1,3 +1,10 @@
1
+ v4.1.0 (2017-09-29)
2
+ -------------------
3
+ [new] Adding support for the MultiSubnetFailover option in connection strings (Paul Kehrer)
4
+ [new] Add request timeout support for msnodesqlv8 queries (Michael Parque)
5
+ [fix] Fix type inference of non-integer numbers (Andrew Crites)
6
+ [fix] Set acquireTimeout on generic pool (Karl Wiggisser)
7
+
1
8
  v4.0.4 (2017-04-25)
2
9
  -------------------
3
10
  [fix] Fix auto-closing of idle connections
package/README.md CHANGED
@@ -40,7 +40,7 @@ If you're on Windows Azure, add `?encrypt=true` to your connection string. See [
40
40
 
41
41
  ### Examples
42
42
 
43
- * [Async/Await](#async-await)
43
+ * [Async/Await](#asyncawait)
44
44
  * [Promises](#promises)
45
45
  * [ES6 Tagged template literals](#es6-tagged-template-literals)
46
46
  * [Callbacks](#callbacks)
@@ -59,7 +59,7 @@ If you're on Windows Azure, add `?encrypt=true` to your connection string. See [
59
59
 
60
60
  ### Connections
61
61
 
62
- * [ConnectionPool](#connectionpool)
62
+ * [ConnectionPool](#connections-1)
63
63
  * [connect](#connect-callback)
64
64
  * [close](#close)
65
65
 
@@ -189,7 +189,7 @@ sql.on('error', err => {
189
189
 
190
190
  Native Promise is used by default. You can easily change this with `sql.Promise = require('myownpromisepackage')`.
191
191
 
192
- **ES6 Tagged template literals**
192
+ ### ES6 Tagged template literals
193
193
 
194
194
  ```javascript
195
195
  const sql = require('mssql')
@@ -316,7 +316,7 @@ const pool2 = new sql.ConnectionPool(config, err => {
316
316
  })
317
317
  })
318
318
 
319
- pool1.on('error', err => {
319
+ pool2.on('error', err => {
320
320
  // ... error handler
321
321
  })
322
322
  ```
@@ -360,7 +360,7 @@ const config = {
360
360
  - **domain** - Once you set domain, driver will connect to SQL Server using domain login.
361
361
  - **database** - Database to connect to (default: dependent on server configuration).
362
362
  - **connectionTimeout** - Connection timeout in ms (default: `15000`).
363
- - **requestTimeout** - Request timeout in ms (default: `15000`).
363
+ - **requestTimeout** - Request timeout in ms (default: `15000`). NOTE: msnodesqlv8 driver doesn't support timeouts < 1 second.
364
364
  - **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.
365
365
  - **parseJSON** - Parse JSON recordsets to JS objects (default: `false`). For more information please see section [JSON support](#json-support).
366
366
  - **pool.max** - The maximum number of connections there can be in the pool (default: `10`).
@@ -727,7 +727,7 @@ You can enable multiple recordsets in queries with the `request.multiple = true`
727
727
 
728
728
  ---------------------------------------
729
729
 
730
- ### bulk(table, [callback])
730
+ ### bulk (table, [callback])
731
731
 
732
732
  Perform a bulk insert.
733
733
 
package/lib/base.js CHANGED
@@ -66,14 +66,12 @@ let getTypeByValue = function (value) {
66
66
  return TYPES.NVarChar
67
67
 
68
68
  case 'number':
69
- for (item of Array.from(map)) {
70
- if (item.js === Number) {
71
- return item.sql
72
- }
69
+ if (value % 1 === 0) {
70
+ return TYPES.Int
71
+ } else {
72
+ return TYPES.Float
73
73
  }
74
74
 
75
- return TYPES.Int
76
-
77
75
  case 'boolean':
78
76
  for (item of Array.from(map)) {
79
77
  if (item.js === Boolean) {
@@ -253,6 +251,7 @@ class ConnectionPool extends EventEmitter {
253
251
  }, Object.assign({
254
252
  max: 10,
255
253
  min: 0,
254
+ acquireTimeoutMillis: this.config.connectionTimeout || this.config.timeout || 15000,
256
255
  evictionRunIntervalMillis: 1000,
257
256
  idleTimeoutMillis: 30000,
258
257
  testOnBorrow: true
@@ -1558,7 +1557,8 @@ module.exports = {
1558
1557
  ISOLATION_LEVEL,
1559
1558
  TYPES,
1560
1559
  MAX: 65535, // (1 << 16) - 1
1561
- map
1560
+ map,
1561
+ getTypeByValue
1562
1562
  }
1563
1563
  }
1564
1564
 
@@ -75,7 +75,7 @@ const parseConnectionString = function (string) {
75
75
  const parsed = {}
76
76
  const original = {}
77
77
 
78
- Object.defineProperty(parsed, '__original__', {value: original})
78
+ Object.defineProperty(parsed, '__original__', { value: original })
79
79
  Object.defineProperty(parsed, 'toString', {
80
80
  value () {
81
81
  const out = []
@@ -96,7 +96,7 @@ const parseConnectionString = function (string) {
96
96
  if (parsing === 'name') {
97
97
  buffer = buffer.trim()
98
98
  param = buffer.toLowerCase()
99
- original[param] = {name: buffer}
99
+ original[param] = { name: buffer }
100
100
  parsing = 'value'
101
101
  buffer = ''
102
102
  } else {
@@ -210,10 +210,10 @@ const resolveConnectionString = function (string, driver) {
210
210
  parsed.driver = 'SQL Server Native Client 11.0'
211
211
 
212
212
  if (parsed.__original__) {
213
- parsed.__original__.driver = {name: 'Driver', escape: ['{', '}']}
213
+ parsed.__original__.driver = { name: 'Driver', escape: ['{', '}'] }
214
214
  }
215
215
 
216
- return {connectionString: parsed.toString()}
216
+ return { connectionString: parsed.toString() }
217
217
  }
218
218
 
219
219
  let user = parsed.uid || parsed.uid || parsed['user id']
@@ -241,6 +241,10 @@ const resolveConnectionString = function (string, driver) {
241
241
  config.requestTimeout = parseInt(config.requestTimeout, 10)
242
242
  }
243
243
 
244
+ if (parsed.multisubnetfailover != null) {
245
+ config.options.multiSubnetFailover = parsed.multisubnetfailover.toLowerCase() === 'true'
246
+ }
247
+
244
248
  if (/^(.*)\\(.*)$/.exec(user)) {
245
249
  config.domain = RegExp.$1
246
250
  user = RegExp.$2
@@ -151,6 +151,10 @@ class ConnectionPool extends base.ConnectionPool {
151
151
  defaultConnectionString = CONNECTION_STRING_NAMED_INSTANCE
152
152
  }
153
153
 
154
+ if (this.config.requestTimeout == null) {
155
+ this.config.requestTimeout = 15000
156
+ }
157
+
154
158
  const cfg = {
155
159
  conn_str: this.config.connectionString || defaultConnectionString,
156
160
  conn_timeout: (this.config.connectionTimeout || 15000) / 1000
@@ -423,7 +427,10 @@ class Request extends base.Request {
423
427
  }
424
428
  }
425
429
 
426
- const req = connection.queryRaw(command, params)
430
+ const req = connection.queryRaw({
431
+ query_str: command,
432
+ query_timeout: config.requestTimeout / 1000 // msnodesqlv8 timeouts are in seconds (<1 second not supported)
433
+ }, params)
427
434
  req.on('meta', metadata => {
428
435
  if (row) {
429
436
  if (isChunkedRecordset) {
package/package.json CHANGED
@@ -21,7 +21,7 @@
21
21
  "azure",
22
22
  "node-mssql"
23
23
  ],
24
- "version": "4.0.4",
24
+ "version": "4.1.0",
25
25
  "main": "index.js",
26
26
  "repository": {
27
27
  "type": "git",
package/.npmignore DELETED
@@ -1,4 +0,0 @@
1
- node_modules
2
- .DS_Store
3
- .vscode
4
- test