-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathpooling.ts
71 lines (59 loc) · 1.69 KB
/
pooling.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import { Error, PoolOptions, Query, SqlClient, QueryDescription, Pool, PoolStatusRecord } from 'msnodesqlv8/types'
const sql: SqlClient = require('msnodesqlv8')
const { TestEnv } = require('../../../test/env/test-env')
const env = new TestEnv()
const str = env.connectionString
const pool: Pool = new sql.Pool({
connectionString: str
})
pool.on('open', (options: PoolOptions) => {
console.log(`ready options = ${JSON.stringify(options, null, 4)}`)
})
pool.on('debug', (msg: string) => {
console.log(`\t\t\t\t\t\t${new Date().toLocaleTimeString()} <pool.debug> ${msg}`)
})
pool.on('status', (s: PoolStatusRecord) => {
console.log(`status = ${JSON.stringify(s, null, 4)}`)
})
pool.on('error', (e: Error) => {
console.log(e)
})
const testSql = 'waitfor delay \'00:00:10\';'
function submit (sql: string): Query {
const q: Query = pool.query(sql)
const timeStr = new Date().toLocaleTimeString()
console.log(`send ${timeStr}, sql = ${sql}`)
q.on('submitted', (d: QueryDescription) => {
console.log(`query submitted ${timeStr}, sql = ${d.query_str}`)
q.on('done', () => console.log(`query done ${timeStr}`))
})
return q
}
for (let i = 0; i < 7; ++i) {
const q: Query = submit(testSql)
switch (i) {
case 5:
console.log('cancel a query')
q.cancelQuery()
break
case 6:
q.pauseQuery()
setTimeout(() => {
console.log('resume a paused query')
q.resumeQuery()
}, 50000)
break
default:
break
}
}
setInterval(() => {
submit(testSql)
}, 60000)
pool.open((e: Error, options: PoolOptions) => {
if (e != null) {
console.log(`Error ${e.message}`)
} else {
console.log(JSON.stringify(options, null, 4))
}
})