mssql 8.0.0 → 8.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 +34 -0
- package/README.md +18 -1
- package/bin/mssql +129 -1
- package/lib/base/connection-pool.js +0 -35
- package/lib/base/prepared-statement.js +4 -0
- package/lib/base/request.js +13 -11
- package/lib/base/transaction.js +4 -0
- package/package.json +8 -7
- package/lib/cli.js +0 -113
- package/test.js +0 -40
package/CHANGELOG.txt
CHANGED
|
@@ -1,3 +1,18 @@
|
|
|
1
|
+
v8.1.0 (2022-04-06)
|
|
2
|
+
-------------------
|
|
3
|
+
[new] MSSQL CLI tool now accepts some options to allow overriding config file ((#1381](https://github.com/tediousjs/node-mssql/pull/1381))
|
|
4
|
+
[fix] nodemsqlv8 driver tests working against Node 10 ([#1368](https://github.com/tediousjs/node-mssql/pull/1368))
|
|
5
|
+
|
|
6
|
+
v8.0.2 (2022-02-07)
|
|
7
|
+
-------------------
|
|
8
|
+
Merge up missing fixes from v7.3.0
|
|
9
|
+
[new] Transaction/PreparedStatements expose the config from their parent connection ([#1338](https://github.com/tediousjs/node-mssql/pull/1338))
|
|
10
|
+
[fix] Fix inherited request configs from the pool. Specifically stream and arrayRowMode now inherit accurately from the connection config ([#1338](https://github.com/tediousjs/node-mssql/pull/1338))
|
|
11
|
+
|
|
12
|
+
v8.0.1 (2022-01-30)
|
|
13
|
+
-------------------
|
|
14
|
+
Re-release of v8.0.0
|
|
15
|
+
|
|
1
16
|
v8.0.0 (2022-01-30)
|
|
2
17
|
-------------------
|
|
3
18
|
[new] Add table.rows.clear() method to allow for chunking updates ([#1094](https://github.com/tediousjs/node-mssql/pull/1094))
|
|
@@ -9,6 +24,16 @@ v8.0.0 (2022-01-30)
|
|
|
9
24
|
[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
25
|
[change] Update tarn pool dependency ((#1344)[https://github.com/tediousjs/node-mssql/pull/1344])
|
|
11
26
|
[removed] Remove connection string parser helpers ((#1342)[https://github.com/tediousjs/node-mssql/pull/1342])
|
|
27
|
+
[removed] Remove deprecated pool properties ((#1359)[https://github.com/tediousjs/node-mssql/pull/1359])
|
|
28
|
+
|
|
29
|
+
v7.3.1 (2022-02-24)
|
|
30
|
+
-------------------
|
|
31
|
+
[fix] Bump debug dependency ([#1361](https://github.com/tediousjs/node-mssql/pull/1361))
|
|
32
|
+
|
|
33
|
+
v7.3.0 (2021-11-18)
|
|
34
|
+
-------------------
|
|
35
|
+
[new] Transaction/PreparedStatements expose the config from their parent connection ([#1338](https://github.com/tediousjs/node-mssql/pull/1338))
|
|
36
|
+
[fix] Fix inherited request configs from the pool. Specifically stream and arrayRowMode now inherit accurately from the connection config ([#1338](https://github.com/tediousjs/node-mssql/pull/1338))
|
|
12
37
|
|
|
13
38
|
v7.2.1 (2021-08-19)
|
|
14
39
|
-------------------
|
|
@@ -56,6 +81,15 @@ v7.0.0 (2021-05-06)
|
|
|
56
81
|
[fix] Connection config objects are now deep cloned when stored against a connection pool ([#1217](https://github.com/tediousjs/node-mssql/pull/1217))
|
|
57
82
|
[removed] Support for connection uri format has been removed (eg: `mssql://user:password@host/?params=values`)
|
|
58
83
|
|
|
84
|
+
v6.4.1 (2022-02-24)
|
|
85
|
+
-------------------
|
|
86
|
+
[fix] Bump debug dependency ([#1361](https://github.com/tediousjs/node-mssql/pull/1361))
|
|
87
|
+
|
|
88
|
+
v6.4.0 (2021-11-18)
|
|
89
|
+
-------------------
|
|
90
|
+
[new] Transaction/PreparedStatements expose the config from their parent connection
|
|
91
|
+
[fix] Fix inherited request configs from the pool. Specifically stream and arrayRowMode now inherit accurately from the connection config ([#1338](https://github.com/tediousjs/node-mssql/pull/1338))
|
|
92
|
+
|
|
59
93
|
v6.3.2 (2021-05-13)
|
|
60
94
|
-------------------
|
|
61
95
|
[fix] Bump various dependencies for security fixes
|
package/README.md
CHANGED
|
@@ -1380,7 +1380,7 @@ __Errors__
|
|
|
1380
1380
|
|
|
1381
1381
|
## CLI
|
|
1382
1382
|
|
|
1383
|
-
|
|
1383
|
+
If you want to add the MSSQL CLI tool to your path, you must install it globally with `npm install -g mssql`.
|
|
1384
1384
|
|
|
1385
1385
|
__Setup__
|
|
1386
1386
|
|
|
@@ -1417,6 +1417,18 @@ Results in:
|
|
|
1417
1417
|
|
|
1418
1418
|
If you omit config path argument, mssql will try to load it from current working directory.
|
|
1419
1419
|
|
|
1420
|
+
__Overriding config settings__
|
|
1421
|
+
|
|
1422
|
+
You can override some config settings via CLI options (`--user`, `--password`, `--server`, `--database`, `--port`).
|
|
1423
|
+
|
|
1424
|
+
```shell
|
|
1425
|
+
echo "select * from mytable" | mssql /path/to/config --database anotherdatabase
|
|
1426
|
+
```
|
|
1427
|
+
Results in:
|
|
1428
|
+
```json
|
|
1429
|
+
[[{"username":"onotheruser","password":"quiteeasy"}]]
|
|
1430
|
+
```
|
|
1431
|
+
|
|
1420
1432
|
## Geography and Geometry
|
|
1421
1433
|
|
|
1422
1434
|
node-mssql has built-in deserializer for Geography and Geometry CLR data types.
|
|
@@ -2013,6 +2025,11 @@ request.query('select @myval as myval', (err, result) => {
|
|
|
2013
2025
|
- 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))
|
|
2014
2026
|
- 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))
|
|
2015
2027
|
|
|
2028
|
+
## 7.x to 8.x changes
|
|
2029
|
+
|
|
2030
|
+
- Upgraded to tedious version 14
|
|
2031
|
+
- Removed internal library for connection string parsing. Connection strings can be resolved using the static method `parseConnectionString` on ConnectionPool
|
|
2032
|
+
|
|
2016
2033
|
## 6.x to 7.x changes
|
|
2017
2034
|
|
|
2018
2035
|
- Upgraded tedious version to v11
|
package/bin/mssql
CHANGED
|
@@ -1,3 +1,131 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
const { Command } = require('commander')
|
|
3
|
+
const { version } = require('../package.json')
|
|
4
|
+
const { resolve: resolvePath } = require('path')
|
|
5
|
+
const { constants: { R_OK } } = require('fs')
|
|
6
|
+
const { ConnectionPool } = require('../')
|
|
7
|
+
const { lstat, access, readFile } = require('fs').promises
|
|
8
|
+
Buffer.prototype.toJSON = () => {
|
|
9
|
+
return `0x${this.toString('hex')}`
|
|
10
|
+
}
|
|
2
11
|
|
|
3
|
-
|
|
12
|
+
/**
|
|
13
|
+
* @param {Readable} stream
|
|
14
|
+
* @returns {Promise<Buffer>}
|
|
15
|
+
*/
|
|
16
|
+
async function streamToBuffer (stream) {
|
|
17
|
+
const chunks = []
|
|
18
|
+
return new Promise((resolve, reject) => {
|
|
19
|
+
stream.on('data', (chunk) => {
|
|
20
|
+
chunks.push(chunk)
|
|
21
|
+
})
|
|
22
|
+
stream.on('end', () => {
|
|
23
|
+
resolve(Buffer.concat(chunks))
|
|
24
|
+
})
|
|
25
|
+
stream.on('error', reject)
|
|
26
|
+
})
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
async function resolveConfig (opts, cfgFile) {
|
|
30
|
+
const cfg = Object.entries({
|
|
31
|
+
options: {
|
|
32
|
+
encrypt: opts.encrypt,
|
|
33
|
+
trustServerCertificate: opts.trustServerCertificate
|
|
34
|
+
},
|
|
35
|
+
user: opts.user,
|
|
36
|
+
password: opts.password,
|
|
37
|
+
server: opts.server,
|
|
38
|
+
database: opts.database,
|
|
39
|
+
port: opts.port
|
|
40
|
+
}).reduce((config, [key, value]) => {
|
|
41
|
+
if (value) {
|
|
42
|
+
Object.assign(config, {
|
|
43
|
+
[key]: value
|
|
44
|
+
})
|
|
45
|
+
}
|
|
46
|
+
return config
|
|
47
|
+
}, {})
|
|
48
|
+
let cfgPath = cfgFile || process.cwd()
|
|
49
|
+
const stat = await lstat(resolvePath(cfgPath))
|
|
50
|
+
if (stat.isDirectory()) {
|
|
51
|
+
cfgPath = resolvePath(cfgPath, opts.config)
|
|
52
|
+
}
|
|
53
|
+
const configAccess = await access(cfgPath, R_OK).then(() => true).catch(() => false)
|
|
54
|
+
if (!configAccess) {
|
|
55
|
+
return cfg;
|
|
56
|
+
}
|
|
57
|
+
const config = await (readFile(cfgPath))
|
|
58
|
+
.then((content) => JSON.parse(content.toString()))
|
|
59
|
+
|
|
60
|
+
return {
|
|
61
|
+
...config,
|
|
62
|
+
...cfg,
|
|
63
|
+
options: {
|
|
64
|
+
...(config.options || {}),
|
|
65
|
+
...cfg.options
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const program = new Command()
|
|
71
|
+
|
|
72
|
+
program
|
|
73
|
+
.name('mssql')
|
|
74
|
+
.argument('[configPath]')
|
|
75
|
+
.description('CLI tools for node-mssql')
|
|
76
|
+
.version(version)
|
|
77
|
+
.option('--config <file>', 'Configuration file for the connection', './.mssql.json')
|
|
78
|
+
.option('--user <user>', 'User for the database connection')
|
|
79
|
+
.option('--password <password>', 'Password for the database connection')
|
|
80
|
+
.option('--server <server>', 'Server for the database connection')
|
|
81
|
+
.option('--database <database>', 'Database for the database connection')
|
|
82
|
+
.option('--port <port>', 'Port for the database connection', parseInt)
|
|
83
|
+
.option('--encrypt', 'Use the encrypt option for this connection', false)
|
|
84
|
+
.option('--trust-server-certificate', 'Trust the server certificate for this connection', false)
|
|
85
|
+
// .option('--format <format>', 'The output format to use, eg: JSON', 'json')
|
|
86
|
+
.action(async function (configPath, opts) {
|
|
87
|
+
const [config, statement] = await Promise.all([
|
|
88
|
+
resolveConfig(opts, configPath),
|
|
89
|
+
streamToBuffer(process.stdin).then((stmt) => stmt.toString().trim())
|
|
90
|
+
])
|
|
91
|
+
if (!statement.length) {
|
|
92
|
+
throw new Error('Statement is empty.')
|
|
93
|
+
}
|
|
94
|
+
const pool = await (new ConnectionPool(config)).connect()
|
|
95
|
+
const request = pool.request()
|
|
96
|
+
request.stream = true
|
|
97
|
+
let started = false
|
|
98
|
+
request.on('error', (e) => {
|
|
99
|
+
pool.close()
|
|
100
|
+
throw e
|
|
101
|
+
})
|
|
102
|
+
request.on('recordset', () => {
|
|
103
|
+
if (started) {
|
|
104
|
+
process.stdout.write('],')
|
|
105
|
+
} else {
|
|
106
|
+
process.stdout.write('[')
|
|
107
|
+
}
|
|
108
|
+
started = false
|
|
109
|
+
})
|
|
110
|
+
request.on('row', (row) => {
|
|
111
|
+
if (!started) {
|
|
112
|
+
started = true
|
|
113
|
+
process.stdout.write('[')
|
|
114
|
+
} else {
|
|
115
|
+
process.stdout.write(',')
|
|
116
|
+
}
|
|
117
|
+
process.stdout.write(JSON.stringify(row))
|
|
118
|
+
})
|
|
119
|
+
request.on('done', () => {
|
|
120
|
+
if (started) {
|
|
121
|
+
process.stdout.write(']]')
|
|
122
|
+
}
|
|
123
|
+
process.stdout.write('\n')
|
|
124
|
+
pool.close()
|
|
125
|
+
})
|
|
126
|
+
request.query(statement)
|
|
127
|
+
})
|
|
128
|
+
|
|
129
|
+
program.parseAsync(process.argv).catch((e) => {
|
|
130
|
+
program.error(e.message, { exitCode: 1 });
|
|
131
|
+
})
|
|
@@ -388,41 +388,6 @@ class ConnectionPool extends EventEmitter {
|
|
|
388
388
|
propagateCreateError: true
|
|
389
389
|
}, this.config.pool)
|
|
390
390
|
)
|
|
391
|
-
const self = this
|
|
392
|
-
Object.defineProperties(this.pool, {
|
|
393
|
-
size: {
|
|
394
|
-
get: () => {
|
|
395
|
-
const message = 'the `size` property on pool is deprecated, access it directly on the `ConnectionPool`'
|
|
396
|
-
self.emit('debug', message)
|
|
397
|
-
process.emitWarning(message)
|
|
398
|
-
return self.size
|
|
399
|
-
}
|
|
400
|
-
},
|
|
401
|
-
available: {
|
|
402
|
-
get: () => {
|
|
403
|
-
const message = 'the `available` property on pool is deprecated, access it directly on the `ConnectionPool`'
|
|
404
|
-
self.emit('debug', message)
|
|
405
|
-
process.emitWarning(message)
|
|
406
|
-
return self.available
|
|
407
|
-
}
|
|
408
|
-
},
|
|
409
|
-
pending: {
|
|
410
|
-
get: () => {
|
|
411
|
-
const message = 'the `pending` property on pool is deprecate, access it directly on the `ConnectionPool`'
|
|
412
|
-
self.emit('debug', message)
|
|
413
|
-
process.emitWarning(message)
|
|
414
|
-
return self.pending
|
|
415
|
-
}
|
|
416
|
-
},
|
|
417
|
-
borrowed: {
|
|
418
|
-
get: () => {
|
|
419
|
-
const message = 'the `borrowed` property on pool is deprecated, access it directly on the `ConnectionPool`'
|
|
420
|
-
self.emit('debug', message)
|
|
421
|
-
process.emitWarning(message)
|
|
422
|
-
return self.borrowed
|
|
423
|
-
}
|
|
424
|
-
}
|
|
425
|
-
})
|
|
426
391
|
|
|
427
392
|
this._connecting = false
|
|
428
393
|
this._connected = true
|
package/lib/base/request.js
CHANGED
|
@@ -26,7 +26,7 @@ class Request extends EventEmitter {
|
|
|
26
26
|
/**
|
|
27
27
|
* Create new Request.
|
|
28
28
|
*
|
|
29
|
-
* @param {Connection|ConnectionPool|Transaction|PreparedStatement} parent If
|
|
29
|
+
* @param {Connection|ConnectionPool|Transaction|PreparedStatement} parent If omitted, global connection is used instead.
|
|
30
30
|
*/
|
|
31
31
|
|
|
32
32
|
constructor (parent) {
|
|
@@ -39,6 +39,8 @@ class Request extends EventEmitter {
|
|
|
39
39
|
this._paused = false
|
|
40
40
|
this.parent = parent || globalConnection.pool
|
|
41
41
|
this.parameters = {}
|
|
42
|
+
this.stream = null
|
|
43
|
+
this.arrayRowMode = null
|
|
42
44
|
}
|
|
43
45
|
|
|
44
46
|
get paused () {
|
|
@@ -224,8 +226,8 @@ class Request extends EventEmitter {
|
|
|
224
226
|
*/
|
|
225
227
|
|
|
226
228
|
batch (batch, callback) {
|
|
227
|
-
if (this.stream
|
|
228
|
-
if (this.arrayRowMode
|
|
229
|
+
if (this.stream === null && this.parent) this.stream = this.parent.config.stream
|
|
230
|
+
if (this.arrayRowMode === null && this.parent) this.arrayRowMode = this.parent.config.arrayRowMode
|
|
229
231
|
this.rowsAffected = 0
|
|
230
232
|
|
|
231
233
|
if (typeof callback === 'function') {
|
|
@@ -288,11 +290,11 @@ class Request extends EventEmitter {
|
|
|
288
290
|
*/
|
|
289
291
|
|
|
290
292
|
_batch (batch, callback) {
|
|
291
|
-
if (!this.
|
|
293
|
+
if (!this.parent) {
|
|
292
294
|
return setImmediate(callback, new RequestError('No connection is specified for that request.', 'ENOCONN'))
|
|
293
295
|
}
|
|
294
296
|
|
|
295
|
-
if (!this.
|
|
297
|
+
if (!this.parent.connected) {
|
|
296
298
|
return setImmediate(callback, new ConnectionError('Connection is closed.', 'ECONNCLOSED'))
|
|
297
299
|
}
|
|
298
300
|
|
|
@@ -317,8 +319,8 @@ class Request extends EventEmitter {
|
|
|
317
319
|
options = {}
|
|
318
320
|
}
|
|
319
321
|
|
|
320
|
-
if (this.stream
|
|
321
|
-
if (this.arrayRowMode
|
|
322
|
+
if (this.stream === null && this.parent) this.stream = this.parent.config.stream
|
|
323
|
+
if (this.arrayRowMode === null && this.parent) this.arrayRowMode = this.parent.config.arrayRowMode
|
|
322
324
|
|
|
323
325
|
if (this.stream || typeof callback === 'function') {
|
|
324
326
|
this._bulk(table, options, (err, rowsAffected) => {
|
|
@@ -419,8 +421,8 @@ class Request extends EventEmitter {
|
|
|
419
421
|
*/
|
|
420
422
|
|
|
421
423
|
query (command, callback) {
|
|
422
|
-
if (this.stream
|
|
423
|
-
if (this.arrayRowMode
|
|
424
|
+
if (this.stream === null && this.parent) this.stream = this.parent.config.stream
|
|
425
|
+
if (this.arrayRowMode === null && this.parent) this.arrayRowMode = this.parent.config.arrayRowMode
|
|
424
426
|
this.rowsAffected = 0
|
|
425
427
|
|
|
426
428
|
if (typeof callback === 'function') {
|
|
@@ -508,8 +510,8 @@ class Request extends EventEmitter {
|
|
|
508
510
|
*/
|
|
509
511
|
|
|
510
512
|
execute (command, callback) {
|
|
511
|
-
if (this.stream
|
|
512
|
-
if (this.arrayRowMode
|
|
513
|
+
if (this.stream === null && this.parent) this.stream = this.parent.config.stream
|
|
514
|
+
if (this.arrayRowMode === null && this.parent) this.arrayRowMode = this.parent.config.arrayRowMode
|
|
513
515
|
this.rowsAffected = 0
|
|
514
516
|
|
|
515
517
|
if (typeof callback === 'function') {
|
package/lib/base/transaction.js
CHANGED
package/package.json
CHANGED
|
@@ -21,12 +21,13 @@
|
|
|
21
21
|
"azure",
|
|
22
22
|
"node-mssql"
|
|
23
23
|
],
|
|
24
|
-
"version": "8.
|
|
24
|
+
"version": "8.1.0",
|
|
25
25
|
"main": "index.js",
|
|
26
26
|
"repository": "github:tediousjs/node-mssql",
|
|
27
27
|
"license": "MIT",
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@tediousjs/connection-string": "^0.3.0",
|
|
30
|
+
"commander": "^9.1.0",
|
|
30
31
|
"debug": "^4.3.3",
|
|
31
32
|
"rfdc": "^1.3.0",
|
|
32
33
|
"tarn": "^3.0.2",
|
|
@@ -42,16 +43,16 @@
|
|
|
42
43
|
"files": [
|
|
43
44
|
"lib/",
|
|
44
45
|
"bin/",
|
|
45
|
-
"
|
|
46
|
-
"
|
|
46
|
+
"tedious.js",
|
|
47
|
+
"msnodesqlv8.js"
|
|
47
48
|
],
|
|
48
49
|
"scripts": {
|
|
49
50
|
"test": "npm run lint && npm run test-unit",
|
|
50
51
|
"lint": "standard",
|
|
51
|
-
"test-unit": "
|
|
52
|
-
"test-tedious": "
|
|
53
|
-
"test-msnodesqlv8": "
|
|
54
|
-
"test-cli": "
|
|
52
|
+
"test-unit": "mocha --exit -t 15000 test/common/unit.js",
|
|
53
|
+
"test-tedious": "mocha --exit -t 15000 test/tedious",
|
|
54
|
+
"test-msnodesqlv8": "mocha --exit -t 15000 test/msnodesqlv8",
|
|
55
|
+
"test-cli": "mocha --exit -t 15000 test/common/cli.js"
|
|
55
56
|
},
|
|
56
57
|
"bin": {
|
|
57
58
|
"mssql": "./bin/mssql"
|
package/lib/cli.js
DELETED
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const fs = require('fs')
|
|
4
|
-
const path = require('path')
|
|
5
|
-
const sql = require('./tedious')
|
|
6
|
-
|
|
7
|
-
const exit = process.exit
|
|
8
|
-
const write = text => process.stdout.write(text)
|
|
9
|
-
Buffer.prototype.toJSON = () => {
|
|
10
|
-
return `0x${this.toString('hex')}`
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
// Resolve config path
|
|
14
|
-
|
|
15
|
-
let cfgPath = path.resolve(process.argv[2] || process.cwd())
|
|
16
|
-
if (fs.lstatSync(cfgPath).isDirectory()) {
|
|
17
|
-
cfgPath = path.resolve(cfgPath, './.mssql.json')
|
|
18
|
-
}
|
|
19
|
-
if (!fs.existsSync(cfgPath)) {
|
|
20
|
-
console.error('Config file not found.')
|
|
21
|
-
exit(1)
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
// Config checks & parse
|
|
25
|
-
|
|
26
|
-
let config
|
|
27
|
-
try {
|
|
28
|
-
config = fs.readFileSync(cfgPath)
|
|
29
|
-
} catch (err) {
|
|
30
|
-
console.error(`Failed to load config file. ${err.message}`)
|
|
31
|
-
exit(1)
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
try {
|
|
35
|
-
config = JSON.parse(config)
|
|
36
|
-
} catch (err) {
|
|
37
|
-
console.error(`Failed to parse config file. ${err.message}`)
|
|
38
|
-
exit(1)
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// Read stdin
|
|
42
|
-
|
|
43
|
-
const buffer = []
|
|
44
|
-
|
|
45
|
-
process.stdin.setEncoding('utf8')
|
|
46
|
-
process.stdin.on('readable', () => buffer.push(process.stdin.read()))
|
|
47
|
-
|
|
48
|
-
process.stdin.on('end', () => {
|
|
49
|
-
const statement = buffer.join('')
|
|
50
|
-
let rst = 0
|
|
51
|
-
let index = 0
|
|
52
|
-
|
|
53
|
-
if (!statement.length) {
|
|
54
|
-
console.error('Statement is empty.')
|
|
55
|
-
exit(1)
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
sql.connect(config, err => {
|
|
59
|
-
if (err) {
|
|
60
|
-
console.error(err.message)
|
|
61
|
-
exit(1)
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
write('[')
|
|
65
|
-
|
|
66
|
-
const request = new sql.Request()
|
|
67
|
-
request.stream = true
|
|
68
|
-
request.on('recordset', () => {
|
|
69
|
-
index = 0
|
|
70
|
-
if (rst++ > 0) {
|
|
71
|
-
write('],')
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
return write('[')
|
|
75
|
-
})
|
|
76
|
-
|
|
77
|
-
request.on('error', err => {
|
|
78
|
-
console.error(err.message)
|
|
79
|
-
sql.close()
|
|
80
|
-
return exit(1)
|
|
81
|
-
})
|
|
82
|
-
|
|
83
|
-
request.on('row', row => {
|
|
84
|
-
if (index++ > 0) {
|
|
85
|
-
write(',')
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
return write(JSON.stringify(row))
|
|
89
|
-
})
|
|
90
|
-
|
|
91
|
-
request.on('done', () => {
|
|
92
|
-
if (rst > 0) {
|
|
93
|
-
write(']')
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
write(']\n')
|
|
97
|
-
sql.close()
|
|
98
|
-
return exit(0)
|
|
99
|
-
})
|
|
100
|
-
|
|
101
|
-
request.query(statement)
|
|
102
|
-
})
|
|
103
|
-
})
|
|
104
|
-
|
|
105
|
-
process.on('uncaughtException', err => {
|
|
106
|
-
if (err.code === 'EPIPE') {
|
|
107
|
-
console.error('Failed to pipe output stream.')
|
|
108
|
-
} else {
|
|
109
|
-
console.error(err.message)
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
exit(1)
|
|
113
|
-
})
|
package/test.js
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
const mssql = require('./')
|
|
3
|
-
|
|
4
|
-
const [, , max] = process.argv
|
|
5
|
-
|
|
6
|
-
const sqlConfig = {
|
|
7
|
-
password: 'P@ssw0rd',
|
|
8
|
-
database: 'test',
|
|
9
|
-
stream: false,
|
|
10
|
-
// driver: 'msnodesqlv8',
|
|
11
|
-
options: {
|
|
12
|
-
trustServerCertificate: true,
|
|
13
|
-
enableArithAbort: true,
|
|
14
|
-
encrypt: true,
|
|
15
|
-
abortTransactionOnError: false
|
|
16
|
-
},
|
|
17
|
-
pool: {
|
|
18
|
-
max: max ? parseInt(max) : 10,
|
|
19
|
-
min: 0
|
|
20
|
-
},
|
|
21
|
-
port: 1433,
|
|
22
|
-
user: 'sa',
|
|
23
|
-
server: 'localhost',
|
|
24
|
-
arrayRowMode: true
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
mssql.connect(sqlConfig).then((pool) => {
|
|
28
|
-
console.log('Connected to SQL server')
|
|
29
|
-
const request = pool.request()
|
|
30
|
-
request.stream = true
|
|
31
|
-
request.on('error', (err) => {
|
|
32
|
-
console.error('good', err)
|
|
33
|
-
})
|
|
34
|
-
return request.query('SELECT * FROM nontable')
|
|
35
|
-
}).catch((err) => {
|
|
36
|
-
console.error('bad', err)
|
|
37
|
-
}).then(() => {
|
|
38
|
-
console.log('Disconnecting from SQL server')
|
|
39
|
-
return mssql.close()
|
|
40
|
-
}).then(() => console.log('Disconnected'))
|