Skip to content

Commit 70b2b50

Browse files
authored
Merge pull request #1845 from dhensby/docs/readme-accuracy
docs: fix README accuracy and add missing documentation
2 parents 62846c7 + 09c1e64 commit 70b2b50

1 file changed

Lines changed: 92 additions & 15 deletions

File tree

README.md

Lines changed: 92 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
**Microsoft SQL Server client for Node.js**
44

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)
5+
[![NPM Version][npm-image]][npm-url] [![NPM Downloads][downloads-image]][downloads-url]
66

77
Supported TDS drivers:
88

@@ -137,13 +137,17 @@ const config = {
137137
* [ConnectionPool](#connections-1)
138138
* [connect](#connect-callback)
139139
* [close](#close)
140+
* [Pool properties](#pool-properties)
141+
* [parseConnectionString](#connectionpoolparseconnectionstring-connectionstring)
140142

141143
### Requests
142144

143145
* [Request](#request)
144146
* [execute](#execute-procedure-callback)
145147
* [input](#input-name-type-value)
146148
* [output](#output-name-type-value)
149+
* [replaceInput](#replaceinput-name-type-value-1)
150+
* [replaceOutput](#replaceoutput-name-type-value)
147151
* [toReadableStream](#toReadableStream)
148152
* [pipe](#pipe-stream)
149153
* [query](#query-command-callback)
@@ -181,8 +185,10 @@ const config = {
181185
* [Metadata](#metadata)
182186
* [Data Types](#data-types)
183187
* [SQL injection](#sql-injection)
184-
* [Known Issues](#known-issues)
185188
* [Contributing](https://github.com/tediousjs/node-mssql/wiki/Contributing)
189+
* [11.x to 12.x changes](#11x-to-12x-changes)
190+
* [10.x to 11.x changes](#10x-to-11x-changes)
191+
* [9.x to 10.x changes](#9x-to-10x-changes)
186192
* [8.x to 9.x changes](#8x-to-9x-changes)
187193
* [7.x to 8.x changes](#7x-to-8x-changes)
188194
* [6.x to 7.x changes](#6x-to-7x-changes)
@@ -724,7 +730,7 @@ ___
724730

725731
### MSNodeSQLv8
726732

727-
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).
733+
Alternative driver for 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).
728734

729735
**To use this driver you must use this `require` statement:**
730736

@@ -816,6 +822,36 @@ __Example__
816822
pool.close()
817823
```
818824

825+
---------------------------------------
826+
827+
### Pool properties
828+
829+
These properties are available on a connected `ConnectionPool` instance (after `connect()` has resolved):
830+
831+
- **pool.healthy** - `Boolean` - Whether the pool is able to create new connections.
832+
- **pool.size** - `Number` - Total number of connections in the pool (free + used + pending creation).
833+
- **pool.available** - `Number` - Number of free connections in the pool.
834+
- **pool.pending** - `Number` - Number of pending connection acquisition requests.
835+
- **pool.borrowed** - `Number` - Number of connections currently in use.
836+
- **pool.connected** - `Boolean` - Whether the pool is connected.
837+
- **pool.connecting** - `Boolean` - Whether the pool is currently connecting.
838+
839+
---------------------------------------
840+
841+
### ConnectionPool.parseConnectionString (connectionString)
842+
843+
Parses a connection string into a configuration object. This is a static method.
844+
845+
__Arguments__
846+
847+
- **connectionString** - Classic or Azure AD connection string.
848+
849+
__Example__
850+
851+
```javascript
852+
const config = sql.ConnectionPool.parseConnectionString('Server=localhost,1433;Database=mydb;User Id=sa;Password=pwd')
853+
```
854+
819855
## Request
820856

821857
```javascript
@@ -903,6 +939,13 @@ __JS Data Type To SQL Data Type Map__
903939

904940
Default data type for unknown object is `sql.NVarChar`.
905941

942+
When a `Number` value is provided without an explicit type, the library inspects the value to choose the best SQL type:
943+
- Integers within the 32-bit signed range → `sql.Int`
944+
- Integers outside the 32-bit range → `sql.BigInt`
945+
- Non-integer numbers → `sql.Float`
946+
947+
JavaScript `bigint` primitives follow the same range logic (`sql.Int` for values within the 32-bit signed range, `sql.BigInt` otherwise).
948+
906949
You can define your own type map.
907950

908951
```javascript
@@ -946,6 +989,46 @@ __Errors__ (synchronous)
946989

947990
---------------------------------------
948991

992+
### replaceInput (name, type, value)
993+
994+
Replace an existing input parameter on the request. If the parameter was previously added with `input()`, it is removed and re-added with the new type and value. Useful when building queries dynamically or re-using a `Request` object.
995+
996+
__Arguments__
997+
998+
- **name** - Name of the input parameter without @ char.
999+
- **type** - SQL data type of input parameter.
1000+
- **value** - Input parameter value.
1001+
1002+
Unlike `input()`, `replaceInput()` requires an explicit SQL type — auto type inference is not supported.
1003+
1004+
__Example__
1005+
1006+
```javascript
1007+
request.input('myval', sql.Int, 1)
1008+
request.replaceInput('myval', sql.Int, 2)
1009+
```
1010+
1011+
---------------------------------------
1012+
1013+
### replaceOutput (name, type, [value])
1014+
1015+
Replace an existing output parameter on the request.
1016+
1017+
__Arguments__
1018+
1019+
- **name** - Name of the output parameter without @ char.
1020+
- **type** - SQL data type of output parameter.
1021+
- **value** - Output parameter value initial value. Optional.
1022+
1023+
__Example__
1024+
1025+
```javascript
1026+
request.output('myval', sql.Int)
1027+
request.replaceOutput('myval', sql.BigInt)
1028+
```
1029+
1030+
---------------------------------------
1031+
9491032
### toReadableStream
9501033

9511034
Convert request to a Node.js ReadableStream
@@ -1044,7 +1127,7 @@ request.query('select 1 as number; select 2 as number', (err, result) => {
10441127

10451128
### batch (batch, [callback])
10461129

1047-
Execute the SQL command. Unlike [query](#query-command-callback), it doesn't use `sp_executesql`, so is not likely that SQL Server will reuse the execution plan it generates for the SQL. Use this only in special cases, for example when you need to execute commands like `create procedure` which can't be executed with [query](#query-command-callback) or if you're executing statements longer than 4000 chars on SQL Server 2000. Also you should use this if you're plan to work with local temporary tables ([more information here](http://weblogs.sqlteam.com/mladenp/archive/2006/11/03/17197.aspx)).
1130+
Execute the SQL command. Unlike [query](#query-command-callback), it doesn't use `sp_executesql`, so is not likely that SQL Server will reuse the execution plan it generates for the SQL. Use this only in special cases, for example when you need to execute commands like `create procedure` which can't be executed with [query](#query-command-callback). Also you should use this if you plan to work with local temporary tables ([more information here](http://weblogs.sqlteam.com/mladenp/archive/2006/11/03/17197.aspx)).
10481131

10491132
NOTE: Table-Valued Parameter (TVP) is not supported in batch.
10501133

@@ -1072,8 +1155,6 @@ __Errors__
10721155
- ENOTBEGUN (`TransactionError`) - Transaction has not begun.
10731156
- EABORT (`TransactionError`) - Transaction was aborted (by user or because of an error).
10741157

1075-
You can enable multiple recordsets in queries with the `request.multiple = true` command.
1076-
10771158
---------------------------------------
10781159

10791160
### bulk (table, [options,] [callback])
@@ -2139,12 +2220,12 @@ request.query('select @myval as myval', (err, result) => {
21392220
})
21402221
```
21412222

2142-
## Known issues
2143-
2144-
### Tedious
2223+
## 11.x to 12.x changes
21452224

2146-
- 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))
2147-
- 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))
2225+
- Config objects are no longer cloned by the library. Mutating a config object after passing it to a `ConnectionPool` results in undefined behaviour.
2226+
- Removed `rfdc` dependency
2227+
- Upgraded to tedious version 19
2228+
- Upgraded `@tediousjs/connection-string` to 0.6.x
21482229

21492230
## 10.x to 11.x changes
21502231

@@ -2220,10 +2301,6 @@ to create new connections or not
22202301
[npm-url]: https://www.npmjs.com/package/mssql
22212302
[downloads-image]: https://img.shields.io/npm/dm/mssql.svg?style=flat-square
22222303
[downloads-url]: https://www.npmjs.com/package/mssql
2223-
[david-image]: https://img.shields.io/david/tediousjs/node-mssql.svg?style=flat-square
2224-
[david-url]: https://david-dm.org/tediousjs/node-mssql
2225-
[appveyor-image]: https://ci.appveyor.com/api/projects/status/e5gq1a0ujwams9t7/branch/master?svg=true
2226-
[appveyor-url]: https://ci.appveyor.com/project/tediousjs/node-mssql
22272304

22282305
[tedious-url]: https://www.npmjs.com/package/tedious
22292306
[msnodesqlv8-url]: https://www.npmjs.com/package/msnodesqlv8

0 commit comments

Comments
 (0)