mssql 7.1.3 → 8.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/CHANGELOG.txt CHANGED
@@ -1,3 +1,25 @@
1
+ v8.0.0 (2022-01-30)
2
+ -------------------
3
+ [new] Add table.rows.clear() method to allow for chunking updates ([#1094](https://github.com/tediousjs/node-mssql/pull/1094))
4
+ [new] Add valueHandler map to store callbacks that are used to process row values ([#1356](https://github.com/tediousjs/node-mssql/pull/1356))
5
+ [change] msnodesqlv8 driver detects os platform and attempts to pick correct connections string for it ((#1318)[https://github.com/tediousjs/node-mssql/pull/1318])
6
+ [change] Updated to latest Tedious 14 ((#1312)[https://github.com/tediousjs/node-mssql/pull/1312])
7
+ [change] Errors for bad bulk load parameters have slightly different error messages ((#1318)[https://github.com/tediousjs/node-mssql/pull/1318])
8
+ [change] Options provided to the driver via the config.options object will not be overridden with other values if set explicitly ((#1340)[https://github.com/tediousjs/node-mssql/pull/1340])
9
+ [change] Duplicate column names will now be presented as an array even if the values are empty ((#1240)[https://github.com/tediousjs/node-mssql/pull/1240])
10
+ [change] Update tarn pool dependency ((#1344)[https://github.com/tediousjs/node-mssql/pull/1344])
11
+ [removed] Remove connection string parser helpers ((#1342)[https://github.com/tediousjs/node-mssql/pull/1342])
12
+
13
+ v7.2.1 (2021-08-19)
14
+ -------------------
15
+ [fix] Fix issue with bulk insert of dates ((#1298)[https://github.com/tediousjs/node-mssql/pull/1298])
16
+
17
+ v7.2.0 (2021-07-29)
18
+ -------------------
19
+ [new] Update Geography field parsing to provide lat/lng props from Geography Point ((#1282)[https://github.com/tediousjs/node-mssql/pull/1282])
20
+ [fix] Handle errors when adding rows to bulk operations ((#1264)[https://github.com/tediousjs/node-mssql/pull/1264])
21
+ [fix] Input/Output parameter passing fix for msnodesqlv8 driver ((#1275)[https://github.com/tediousjs/node-mssql/pull/1275])
22
+
1
23
  v7.1.3 (2021-06-11)
2
24
  -------------------
3
25
  [fix] Request timeout settings now respect value parsed from connection strings ((#1257)[https://github.com/tediousjs/node-mssql/pull/1257)
@@ -237,7 +259,7 @@ v4.0.4 (2017-04-25)
237
259
 
238
260
  v4.0.3 (2017-04-25)
239
261
  -------------------
240
- [fix] Fixed broken CLI & debugging
262
+ [fix] Fixed broken CLI & debugging
241
263
 
242
264
  v4.0.2 (2017-04-19)
243
265
  -------------------
@@ -258,7 +280,7 @@ v4.0.0 (2017-04-01)
258
280
  [change] Removed verbose and debug mode
259
281
  [change] Removed 'driver' from options
260
282
  [change] Removed Transaction and Prepared Statement queues
261
- [change] Removed 'multiple' directive
283
+ [change] Removed 'multiple' directive
262
284
  [change] Connection renamed to ConnectionPool
263
285
  [change] Updated to latest Tedious 2.0.0
264
286
 
package/README.md CHANGED
@@ -140,7 +140,7 @@ async () => {
140
140
  * [SQL injection](#sql-injection)
141
141
  * [Known Issues](#known-issues)
142
142
  * [Contributing](https://github.com/tediousjs/node-mssql/wiki/Contributing)
143
- * [6.x to 7.x changes (pre-release)](#6x-to-7x-changes-pre-release)
143
+ * [6.x to 7.x changes](#6x-to-7x-changes)
144
144
  * [5.x to 6.x changes](#5x-to-6x-changes)
145
145
  * [4.x to 5.x changes](#4x-to-5x-changes)
146
146
  * [3.x to 4.x changes](#3x-to-4x-changes)
@@ -370,264 +370,169 @@ function processRows() {
370
370
  }
371
371
  ```
372
372
 
373
- ## Pool Management
374
-
375
- An important concept to understand when using this library is [Connection Pooling](https://en.wikipedia.org/wiki/Connection_pool)
376
- as this library uses connection pooling extensively.
373
+ ## Connection Pools
377
374
 
378
- As one Node JS process is able to handle multiple requests at once, we can take advantage of this long running process
379
- to create a pool of database connections for reuse; this saves overhead of connecting to the database for each request
375
+ An important concept to understand when using this library is [Connection Pooling](https://en.wikipedia.org/wiki/Connection_pool) as this library uses connection pooling extensively. As one Node JS process is able to handle multiple requests at once, we can take advantage of this long running process to create a pool of database connections for reuse; this saves overhead of connecting to the database for each request
380
376
  (as would be the case in something like PHP, where one process handles one request).
381
377
 
382
- With the advantages of pooling comes some added complexities, but these are mostly just conceptual and once you understand
383
- how the pooling is working, it is simple to make use of it efficiently and effectively.
378
+ With the advantages of pooling comes some added complexities, but these are mostly just conceptual and once you understand how the pooling is working, it is simple to make use of it efficiently and effectively.
384
379
 
385
- ### The Global Connection (Pool)
380
+ ### The Global Connection Pool
386
381
 
387
- To assist with pool management in your application there is the global `connect()` function that is available for use. As of
388
- v6 of this library a developer can make repeated calls to this function to obtain the global connection pool. This means you
389
- do not need to keep track of the pool in your application (as used to be the case). If the global pool is already connected,
390
- it will resolve to the connected pool. For example:
382
+ To assist with pool management in your application there is the `sql.connect()` function that is used to connect to the global connection pool. You can make repeated calls to this function, and if the global pool is already connected, it will resolve to the connected pool. The following example obtains the global connection pool by running `sql.connect()`, and then runs the query against the pool.
383
+
384
+ NB: It's important to note that there can only be one global connection pool connected at a time. Providing a different connection config to the `connect()` function will not create a new connection if it is already connected.
391
385
 
392
386
  ```js
393
387
  const sql = require('mssql')
388
+ const config = { ... }
394
389
 
395
390
  // run a query against the global connection pool
396
391
  function runQuery(query) {
397
392
  // sql.connect() will return the existing global pool if it exists or create a new one if it doesn't
398
- return sql.connect().then((pool) => {
393
+ return sql.connect(config).then((pool) => {
399
394
  return pool.query(query)
400
395
  })
401
396
  }
402
-
403
397
  ```
404
398
 
405
- Here we obtain the global connection pool by running `sql.connect()` and we then run the query against the pool.
406
- We also do *not* close the pool after the query is executed and that is because other queries may need to be run against
407
- this pool and closing it will add an overhead to running the query. We should only ever close the pool when our application
408
- is finished. For example, if we are running some kind of CLI tool or a CRON job:
399
+ Awaiting or `.then`-ing the pool creation is a safe way to ensure that the pool is always ready, without knowing where it is needed first. In practice, once the pool is created then there will be no delay for the next `connect()` call.
409
400
 
410
- ```js
411
- const sql = require('mssql')
401
+ Also notice that we do *not* close the global pool by calling `sql.close()` after the query is executed, because other queries may need to be run against this pool and closing it will add additional overhead to running subsequent queries. You should only ever close the global pool if you're certain the application is finished. Or for example, if you are running some kind of CLI tool or a CRON job you can close the pool at the end of the script.
412
402
 
413
- (() => {
414
- sql.connect().then(pool => {
415
- return pool.query('SELECT 1')
416
- }).then(result => {
417
- // do something with result
418
- }).then(() => {
419
- return sql.close()
420
- })
421
- })()
422
- ```
423
-
424
- Here the connection will be closed and the node process will exit once the queries and other application logic has completed.
425
- You should aim to only close the pool once in your application, when it is exiting or you know your application will never make
426
- another SQL query.
427
-
428
- ### Advanced Pool Management
403
+ ### Global Pool Single Instance
429
404
 
430
- In some instances you will not want to use the connection pool, you may have multiple databases to connect to or you may have
431
- one pool for read-only operations and another pool for read-write. In this instance you will need to implement your own pool
432
- management.
405
+ The ability to call `connect()` and `close()` repeatedly on the global pool is intended to make pool management easier, however it is better to maintain your own reference to the pool, where `connect()` is called **once**, and the resulting global pool's connection promise is re-used throughout the entire application.
433
406
 
434
- That could look something like this:
407
+ For example, in Express applications, the following approach uses a single global pool instance added to the `app.locals` so the application has access to it when needed. The server start is then chained inside the `connect()` promise.
435
408
 
436
409
  ```js
437
- const { ConnectionPool } = require('mssql')
438
- const POOLS = {}
439
-
440
- function createPool(config, name) {
441
- if (getPool(name)) {
442
- return Promise.reject(new Error('Pool with this name already exists'))
443
- }
444
- return (new ConnectionPool(config)).connect().then((pool) => {
445
- return POOLS[name] = pool
410
+ const express = require('express')
411
+ const sql = require('mssql')
412
+ const config = {/*...*/}
413
+ //instantiate a connection pool
414
+ const appPool = new sql.ConnectionPool(config)
415
+ //require route handlers and use the same connection pool everywhere
416
+ const route1 = require('./routes/route1')
417
+ const app = express()
418
+ app.get('/path', route1)
419
+
420
+ //connect the pool and start the web server when done
421
+ appPool.connect().then(function(pool) {
422
+ app.locals.db = pool;
423
+ const server = app.listen(3000, function () {
424
+ const host = server.address().address
425
+ const port = server.address().port
426
+ console.log('Example app listening at http://%s:%s', host, port)
446
427
  })
447
- }
448
-
449
- function closePool(name) {
450
- const pool = getPool(name)
451
- if (pool) {
452
- delete POOLS[name]
453
- return pool.close()
454
- }
455
- return Promise.resolve()
456
- }
457
-
458
- function getPool(name) {
459
- if (Object.prototype.hasOwnProperty.apply(POOLS, name)) {
460
- return POOLS[name]
461
- }
462
- }
463
-
464
- module.exports = {
465
- closePool,
466
- createPool,
467
- getPool
468
- }
428
+ }).catch(function(err) {
429
+ console.error('Error creating connection pool', err)
430
+ });
469
431
  ```
470
432
 
471
- This helper file can then be used in your application to create, fetch and close your pools. As with the global pools, you
472
- should aim to only close a pool when you know it will never be needed by the application again; typically this will be when
473
- your application is shutting down.
474
-
475
- ## Connection Pools
476
-
477
- Using a single connection pool for your application/service is recommended.
478
- Instantiating a pool with a callback, or immediately calling `.connect`, is asynchronous to ensure a connection can be
479
- established before returning. From that point, you're able to acquire connections as normal:
480
-
481
- ```javascript
482
- const sql = require('mssql')
483
-
484
- // async/await style:
485
- const pool1 = new sql.ConnectionPool(config);
486
- const pool1Connect = pool1.connect();
487
-
488
- pool1.on('error', err => {
489
- // ... error handler
490
- })
433
+ Then the route uses the connection pool in the `app.locals` object:
491
434
 
492
- async function messageHandler() {
493
- await pool1Connect; // ensures that the pool has been created
494
- try {
495
- const request = pool1.request(); // or: new sql.Request(pool1)
496
- const result = await request.query('select 1 as number')
497
- console.dir(result)
498
- return result;
499
- } catch (err) {
500
- console.error('SQL error', err);
435
+ ```js
436
+ // ./routes/route1.js
437
+ const sql = require('mssql');
438
+
439
+ module.exports = function(req, res) {
440
+ req.locals.db.query('SELECT TOP 10 * FROM table_name', function(err, recordset) {
441
+ if (err) {
442
+ console.error(err)
443
+ res.status(500).send('SERVER ERROR')
444
+ return
501
445
  }
502
- }
503
-
504
- // promise style:
505
- const pool2 = new sql.ConnectionPool(config)
506
- const pool2Connect = pool2.connect()
507
-
508
- pool2.on('error', err => {
509
- // ... error handler
510
- })
511
-
512
- function runStoredProcedure() {
513
- return pool2Connect.then((pool) => {
514
- pool.request() // or: new sql.Request(pool2)
515
- .input('input_parameter', sql.Int, 10)
516
- .output('output_parameter', sql.VarChar(50))
517
- .execute('procedure_name', (err, result) => {
518
- // ... error checks
519
- console.dir(result)
520
- })
521
- }).catch(err => {
522
- // ... error handler
523
- })
446
+ res.status(200).json({ message: 'success' })
447
+ })
524
448
  }
525
449
  ```
526
450
 
527
- Awaiting or `.then`ing the pool creation is a safe way to ensure that the pool is always ready, without knowing where it
528
- is needed first. In practice, once the pool is created then there will be no delay for the next operation.
529
-
530
- As of v6.1.0 you can make repeat calls to `ConnectionPool.connect()` and `ConnectonPool.close()` without an error being
531
- thrown, allowing for the safe use of `mssql.connect().then(...)` throughout your code as well as making multiple calls to
532
- close when your application is shutting down.
451
+ ### Advanced Pool Management
533
452
 
534
- The ability to call `connect()` repeatedly is intended to make pool management easier, however it is still recommended
535
- to follow the example above where `connect()` is called once and using the original resolved connection promise.
536
- Repeatedly calling `connect()` when running queries risks running into problems when `close()` is called on the pool.
453
+ For some use-cases you may want to implement your own connection pool management, rather than using the global connection pool. Reasons for doing this include:
537
454
 
538
- **ES6 Tagged template literals**
455
+ * Supporting connections to multiple databases
456
+ * Creation of separate pools for read vs read/write operations
539
457
 
540
- ```javascript
541
- new sql.ConnectionPool(config).connect().then(pool => {
542
- return pool.query`select * from mytable where id = ${value}`
543
- }).then(result => {
544
- console.dir(result)
545
- }).catch(err => {
546
- // ... error checks
547
- })
548
- ```
458
+ The following code is an example of a custom connection pool implementation.
549
459
 
550
- All values are automatically sanitized against sql injection.
460
+ ```js
461
+ // pool-manager.js
462
+ const mssql = require('mssql')
463
+ const pools = new Map();
551
464
 
552
- ### Managing connection pools
465
+ module.exports = {
466
+ /**
467
+ * Get or create a pool. If a pool doesn't exist the config must be provided.
468
+ * If the pool does exist the config is ignored (even if it was different to the one provided
469
+ * when creating the pool)
470
+ *
471
+ * @param {string} name
472
+ * @param {{}} [config]
473
+ * @return {Promise.<mssql.ConnectionPool>}
474
+ */
475
+ get: (name, config) => {
476
+ if (!pools.has(name)) {
477
+ if (!config) {
478
+ throw new Error('Pool does not exist');
479
+ }
480
+ const pool = new mssql.ConnectionPool(config);
481
+ // automatically remove the pool from the cache if `pool.close()` is called
482
+ const close = pool.close.bind(pool);
483
+ pool.close = (...args) => {
484
+ pools.delete(name);
485
+ return close(...args);
486
+ }
487
+ pools.set(name, pool.connect());
488
+ }
489
+ return pools.get(name);
490
+ },
491
+ /**
492
+ * Closes all the pools and removes them from the store
493
+ *
494
+ * @return {Promise<mssql.ConnectionPool[]>}
495
+ */
496
+ closeAll: () => Promise.all(Array.from(pools.values()).map((connect) => {
497
+ return connect.then((pool) => pool.close());
498
+ })),
499
+ };
500
+ ```
553
501
 
554
- Most applications will only need a single `ConnectionPool` that can be shared throughout the code. To aid the sharing
555
- of a single pool this library exposes a set of functions to access a single global connection. eg:
502
+ This file can then be used in your application to create, fetch, and close pools.
556
503
 
557
504
  ```js
558
- // as part of your application's boot process
505
+ const { get } = require('./pool-manager')
559
506
 
560
- const sql = require('mssql')
561
- const poolPromise = sql.connect()
507
+ async function example() {
508
+ const pool = await get('default')
509
+ return pool.request().query('SELECT 1')
510
+ }
511
+ ```
562
512
 
563
- // during your applications runtime
513
+ Similar to the global connection pool, you should aim to only close a pool when you know it will never be needed by the application again. Typically this will only be when your application is shutting down.
564
514
 
565
- poolPromise.then(() => {
566
- return sql.query('SELECT 1')
567
- }).then(result => {
568
- console.dir(result)
569
- })
515
+ ### Result value manipulation
570
516
 
571
- // when your application exits
572
- poolPromise.then(() => {
573
- return sql.close()
574
- })
575
- ```
517
+ In some instances it is desirable to manipulate the record data as it is returned from the database, this may be to cast it as a particular object (eg: `moment` object instead of `Date`) or similar.
576
518
 
577
- If you require multiple pools per application (perhaps you have many DBs you need to connect to or you want a read-only
578
- pool), then you will need to manage your pools yourself. The best way to do this is to create a shared library file that
579
- can hold references to the pools for you. For example:
519
+ In v8.0.0+ it is possible to register per-datatype handlers:
580
520
 
581
521
  ```js
582
522
  const sql = require('mssql')
583
523
 
584
- const pools = {}
585
-
586
- // manage a set of pools by name (config will be required to create the pool)
587
- // a pool will be removed when it is closed
588
- async function getPool(name, config) {
589
- if (!Object.prototype.hasOwnProperty.call(pools, name)) {
590
- const pool = new sql.ConnectionPool(config)
591
- const close = pool.close.bind(pool)
592
- pool.close = (...args) => {
593
- delete pools[name]
594
- return close(...args)
595
- }
596
- await pool.connect()
597
- pools[name] = pool
598
- }
599
- return pools[name]
600
- }
601
-
602
- // close all pools
603
- function closeAll() {
604
- return Promise.all(Object.values(pools).map((pool) => {
605
- return pool.close()
606
- }))
607
- }
608
-
609
- module.exports = {
610
- closeAll,
611
- getPool
612
- }
613
- ```
614
-
615
- You can then use this library file in your code to get a connected pool when you need it:
524
+ // in this example all integer values will return 1 more than their actual value in the database
525
+ sql.valueHandler.set(sql.TYPES.Int, (value) => value + 1)
616
526
 
617
- ```js
618
- const { getPool } = require('./path/to/file')
619
-
620
- // run a query
621
- async function runQuery(query, config) {
622
- // pool will always be connected when the promise has resolved - may reject if the connection config is invalid
623
- const pool = await getPool('default', config)
624
- const result = await pool.request().query(query)
625
- return result
626
- }
527
+ sql.query('SELECT * FROM [example]').then((result) => {
528
+ // all `int` columns will return a manipulated value as per the callback above
529
+ })
627
530
  ```
628
531
 
629
532
  ## Configuration
630
533
 
534
+ The following is an example configuration object:
535
+
631
536
  ```javascript
632
537
  const config = {
633
538
  user: '...',
@@ -693,11 +598,14 @@ require('mssql').connect({...config, beforeConnect: conn => {
693
598
  - **options.tdsVersion** - The version of TDS to use (default: `7_4`, available: `7_1`, `7_2`, `7_3_A`, `7_3_B`, `7_4`).
694
599
  - **options.appName** - Application name used for SQL server logging.
695
600
  - **options.abortTransactionOnError** - A boolean determining whether to rollback a transaction automatically if any error is encountered during the given transaction's execution. This sets the value for `XACT_ABORT` during the initial SQL phase of a connection.
696
- - **options.authentication** - An object with authentication settings, according to the [Tedious Documentation](https://tediousjs.github.io/tedious/api-connection.html). Passing this object will override `options.user`, `options.password`, `options.domain` settings.
697
- - **options.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`
698
- - **options.authentication.options** - Options of the authentication required by the `tedious` driver, depends on `options.authentication.type`. For more details, check [Tedious Authentication Interfaces](https://github.com/tediousjs/tedious/blob/master/src/connection.ts#L237)
699
601
 
602
+ **Authentication:**
603
+
604
+ On top of the extra options, an `authentication` property can be added to the pool config option
700
605
 
606
+ - **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.
607
+ - **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`
608
+ - **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)
701
609
 
702
610
  More information about Tedious specific options: http://tediousjs.github.io/tedious/api-connection.html
703
611
 
@@ -1511,32 +1419,65 @@ If you omit config path argument, mssql will try to load it from current working
1511
1419
 
1512
1420
  ## Geography and Geometry
1513
1421
 
1514
- node-mssql has built-in serializer for Geography and Geometry CLR data types.
1422
+ node-mssql has built-in deserializer for Geography and Geometry CLR data types.
1423
+
1424
+ ### Geography
1425
+
1426
+ Geography types can be constructed several different ways. Refer carefully to documentation to verify the coordinate ordering; the ST methods tend to order parameters as longitude (x) then latitude (y), while custom CLR methods tend to prefer to order them as latitude (y) then longitude (x).
1427
+
1428
+ The query:
1515
1429
 
1516
1430
  ```sql
1517
- select geography::STGeomFromText('LINESTRING(-122.360 47.656, -122.343 47.656 )', 4326)
1518
- select geometry::STGeomFromText('LINESTRING (100 100 10.3 12, 20 180, 180 180)', 0)
1431
+ select geography::STGeomFromText(N'POLYGON((1 1, 3 1, 3 1, 1 1))',4326)
1519
1432
  ```
1520
1433
 
1521
- Results in:
1434
+ results in:
1522
1435
 
1523
1436
  ```javascript
1524
- { srid: 4326,
1525
- version: 1,
1526
- points: [ { x: 47.656, y: -122.36 }, { x: 47.656, y: -122.343 } ],
1437
+ {
1438
+ srid: 4326,
1439
+ version: 2,
1440
+ points: [
1441
+ Point { lat: 1, lng: 1, z: null, m: null },
1442
+ Point { lat: 1, lng: 3, z: null, m: null },
1443
+ Point { lat: 1, lng: 3, z: null, m: null },
1444
+ Point { lat: 1, lng: 1, z: null, m: null }
1445
+ ],
1527
1446
  figures: [ { attribute: 1, pointOffset: 0 } ],
1528
- shapes: [ { parentOffset: -1, figureOffset: 0, type: 2 } ],
1529
- segments: [] }
1447
+ shapes: [ { parentOffset: -1, figureOffset: 0, type: 3 } ],
1448
+ segments: []
1449
+ }
1450
+ ```
1451
+
1452
+ **NOTE:** You will also see `x` and `y` coordinates in parsed Geography points,
1453
+ they are not recommended for use. They have thus been omitted from this example.
1454
+ For compatibility, they remain flipped (x, the horizontal offset, is instead used for latitude, the vertical), and thus risk misleading you.
1455
+ Prefer instead to use the `lat` and `lng` properties.
1456
+
1457
+ ### Geometry
1530
1458
 
1531
- { srid: 0,
1459
+ Geometry types can also be constructed in several ways. Unlike Geographies, they are consistent in always placing x before y. node-mssql decodes the result of this query:
1460
+
1461
+ ```sql
1462
+ select geometry::STGeomFromText(N'POLYGON((1 1, 3 1, 3 7, 1 1))',4326)
1463
+ ```
1464
+
1465
+ into the JavaScript object:
1466
+
1467
+ ```javascript
1468
+ {
1469
+ srid: 4326,
1532
1470
  version: 1,
1533
- points:
1534
- [ { x: 100, y: 100, z: 10.3, m: 12 },
1535
- { x: 20, y: 180, z: NaN, m: NaN },
1536
- { x: 180, y: 180, z: NaN, m: NaN } ],
1537
- figures: [ { attribute: 1, pointOffset: 0 } ],
1538
- shapes: [ { parentOffset: -1, figureOffset: 0, type: 2 } ],
1539
- segments: [] }
1471
+ points: [
1472
+ Point { x: 1, y: 1, z: null, m: null },
1473
+ Point { x: 1, y: 3, z: null, m: null },
1474
+ Point { x: 7, y: 3, z: null, m: null },
1475
+ Point { x: 1, y: 1, z: null, m: null }
1476
+ ],
1477
+ figures: [ { attribute: 2, pointOffset: 0 } ],
1478
+ shapes: [ { parentOffset: -1, figureOffset: 0, type: 3 } ],
1479
+ segments: []
1480
+ }
1540
1481
  ```
1541
1482
 
1542
1483
  ## Table-Valued Parameter (TVP)
@@ -1580,6 +1521,20 @@ request.execute('MyCustomStoredProcedure', (err, result) => {
1580
1521
 
1581
1522
  **TIP**: You can also create Table variable from any recordset with `recordset.toTable()`. You can optionally specify table type name in the first argument.
1582
1523
 
1524
+ You can clear the table rows for easier batching by using `table.rows.clear()`
1525
+
1526
+ ```js
1527
+ const tvp = new sql.Table() // You can optionally specify table type name in the first argument.
1528
+
1529
+ // Columns must correspond with type we have created in database.
1530
+ tvp.columns.add('a', sql.VarChar(50))
1531
+ tvp.columns.add('b', sql.Int)
1532
+
1533
+ // Add rows
1534
+ tvp.rows.add('hello tvp', 777) // Values are in same order as columns.
1535
+ tvp.rows.clear()
1536
+ ```
1537
+
1583
1538
  ## Response Schema
1584
1539
 
1585
1540
  An object returned from a `sucessful` basic query would look like the following.
@@ -2058,11 +2013,15 @@ request.query('select @myval as myval', (err, result) => {
2058
2013
  - 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))
2059
2014
  - 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))
2060
2015
 
2061
- ## 6.x to 7.x changes (pre-release)
2016
+ ## 6.x to 7.x changes
2062
2017
 
2063
- - Upgraded tedious version to v8
2018
+ - Upgraded tedious version to v11
2019
+ - Upgraded msnodesqlv8 version support to v2
2020
+ - Upgraded tarn.js version to v3
2064
2021
  - Requests in stream mode that pipe into other streams no longer pass errors up the stream chain
2022
+ - Request.pipe now pipes a true node stream for better support of backpressure
2065
2023
  - tedious config option `trustServerCertificate` defaults to `false` if not supplied
2024
+ - Dropped support for Node < 10
2066
2025
 
2067
2026
  ## 5.x to 6.x changes
2068
2027
 
@@ -7,7 +7,7 @@ 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 deepclone = require('rfdc/default')
10
+ const clone = require('rfdc/default')
11
11
 
12
12
  /**
13
13
  * Class ConnectionPool.
@@ -44,7 +44,7 @@ class ConnectionPool extends EventEmitter {
44
44
 
45
45
  if (typeof config === 'string') {
46
46
  try {
47
- this.config = this.parseConnectionString(config)
47
+ this.config = this.constructor.parseConnectionString(config)
48
48
  } catch (ex) {
49
49
  if (typeof callback === 'function') {
50
50
  return setImmediate(callback, ex)
@@ -52,7 +52,7 @@ class ConnectionPool extends EventEmitter {
52
52
  throw ex
53
53
  }
54
54
  } else {
55
- this.config = deepclone(config)
55
+ this.config = clone(config)
56
56
  }
57
57
 
58
58
  // set defaults
@@ -85,11 +85,11 @@ class ConnectionPool extends EventEmitter {
85
85
  return this._healthy
86
86
  }
87
87
 
88
- parseConnectionString (connectionString) {
88
+ static parseConnectionString (connectionString) {
89
89
  return this._parseConnectionString(connectionString)
90
90
  }
91
91
 
92
- _parseConnectionString (connectionString) {
92
+ static _parseConnectionString (connectionString) {
93
93
  const parsed = parseSqlConnectionString(connectionString, true, true)
94
94
  return Object.entries(parsed).reduce((config, [key, value]) => {
95
95
  switch (key) {
package/lib/base/index.js CHANGED
@@ -54,6 +54,13 @@ Object.defineProperty(module.exports, 'Promise', {
54
54
  }
55
55
  })
56
56
 
57
+ Object.defineProperty(module.exports, 'valueHandler', {
58
+ enumerable: true,
59
+ value: shared.valueHandler,
60
+ writable: false,
61
+ configurable: false
62
+ })
63
+
57
64
  for (const key in TYPES) {
58
65
  const value = TYPES[key]
59
66
  module.exports.exports[key] = value
@@ -6,9 +6,11 @@ const BaseConnectionPool = require('../base/connection-pool')
6
6
  const { IDS, INCREMENT } = require('../utils')
7
7
  const shared = require('../shared')
8
8
  const ConnectionError = require('../error/connection-error')
9
+ const { platform } = require('os')
9
10
 
10
- const CONNECTION_STRING_PORT = 'Driver=SQL Server Native Client 11.0;Server=#{server},#{port};Database=#{database};Uid=#{user};Pwd=#{password};Trusted_Connection=#{trusted};Encrypt=#{encrypt};'
11
- const CONNECTION_STRING_NAMED_INSTANCE = 'Driver=SQL Server Native Client 11.0;Server=#{server}\\#{instance};Database=#{database};Uid=#{user};Pwd=#{password};Trusted_Connection=#{trusted};Encrypt=#{encrypt};'
11
+ const CONNECTION_DRIVER = ['darwin', 'linux'].includes(platform()) ? 'ODBC Driver 17 for SQL Server' : 'SQL Server Native Client 11.0'
12
+ const CONNECTION_STRING_PORT = `Driver=${CONNECTION_DRIVER};Server=#{server},#{port};Database=#{database};Uid=#{user};Pwd=#{password};Trusted_Connection=#{trusted};Encrypt=#{encrypt};`
13
+ const CONNECTION_STRING_NAMED_INSTANCE = `Driver=${CONNECTION_DRIVER};Server=#{server}\\#{instance};Database=#{database};Uid=#{user};Pwd=#{password};Trusted_Connection=#{trusted};Encrypt=#{encrypt};`
12
14
 
13
15
  class ConnectionPool extends BaseConnectionPool {
14
16
  _poolCreate () {
@@ -22,6 +22,13 @@ Object.defineProperty(module.exports, 'Promise', {
22
22
  }
23
23
  })
24
24
 
25
+ Object.defineProperty(module.exports, 'valueHandler', {
26
+ enumerable: true,
27
+ value: base.valueHandler,
28
+ writable: false,
29
+ configurable: false
30
+ })
31
+
25
32
  base.driver.name = 'msnodesqlv8'
26
33
  base.driver.ConnectionPool = ConnectionPool
27
34
  base.driver.Transaction = Transaction