w-orm-reladb 1.0.44 → 1.0.46
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/dist/w-orm-reladb.umd.js +1 -1
- package/docs/WOrmReladb.html +1 -1
- package/docs/WOrmReladb.mjs.html +1 -1
- package/docs/index.html +1 -1
- package/package.json +4 -5
- package/test/api-mssql.test.mjs +105 -5
- package/toolg/cleanFolder.mjs +1 -0
- package/.github/workflows/ci.yml +0 -52
package/dist/w-orm-reladb.umd.js
CHANGED
package/docs/WOrmReladb.html
CHANGED
|
@@ -3763,7 +3763,7 @@
|
|
|
3763
3763
|
<br class="clear">
|
|
3764
3764
|
|
|
3765
3765
|
<footer>
|
|
3766
|
-
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a> on
|
|
3766
|
+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a> on Sat Aug 08 2026 00:11:08 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
|
3767
3767
|
</footer>
|
|
3768
3768
|
|
|
3769
3769
|
<script>prettyPrint();</script>
|
package/docs/WOrmReladb.mjs.html
CHANGED
|
@@ -1132,7 +1132,7 @@ export default WOrmReladb
|
|
|
1132
1132
|
<br class="clear">
|
|
1133
1133
|
|
|
1134
1134
|
<footer>
|
|
1135
|
-
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a> on
|
|
1135
|
+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a> on Sat Aug 08 2026 00:11:08 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
|
1136
1136
|
</footer>
|
|
1137
1137
|
|
|
1138
1138
|
<script>prettyPrint();</script>
|
package/docs/index.html
CHANGED
|
@@ -71,7 +71,7 @@
|
|
|
71
71
|
<br class="clear">
|
|
72
72
|
|
|
73
73
|
<footer>
|
|
74
|
-
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a> on
|
|
74
|
+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a> on Sat Aug 08 2026 00:11:08 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
|
75
75
|
</footer>
|
|
76
76
|
|
|
77
77
|
<script>prettyPrint();</script>
|
package/package.json
CHANGED
|
@@ -1,21 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "w-orm-reladb",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.46",
|
|
4
4
|
"main": "dist/w-orm-reladb.umd.js",
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"json5": "^2.2.3",
|
|
7
|
-
"lodash-es": "^4.18.1",
|
|
8
7
|
"sqlite3": "^6.0.1",
|
|
9
8
|
"tedious": "^19.2.2",
|
|
10
|
-
"w-auto-sequelize": "^1.0.
|
|
11
|
-
"wsemi": "^1.8.
|
|
9
|
+
"w-auto-sequelize": "^1.0.30",
|
|
10
|
+
"wsemi": "^1.8.68"
|
|
12
11
|
},
|
|
13
12
|
"dependenciesTemp": {
|
|
14
13
|
"@journeyapps/sqlcipher": "^5.3.1",
|
|
15
14
|
"msg": "install sqlcipher fo the protection when db=sqlite"
|
|
16
15
|
},
|
|
17
16
|
"devDependencies": {
|
|
18
|
-
"w-package-tools": "^1.1.
|
|
17
|
+
"w-package-tools": "^1.1.12"
|
|
19
18
|
},
|
|
20
19
|
"scripts": {
|
|
21
20
|
"test": "mocha --parallel --timeout 60000",
|
package/test/api-mssql.test.mjs
CHANGED
|
@@ -1,14 +1,100 @@
|
|
|
1
1
|
import assert from 'assert'
|
|
2
|
+
import net from 'net'
|
|
3
|
+
import { execFile } from 'child_process'
|
|
4
|
+
import { promisify } from 'util'
|
|
2
5
|
import wo from '../src/WOrmReladb.mjs'
|
|
3
6
|
import { genRs, genRsm, sortByName } from './api-fixtures.mjs'
|
|
4
7
|
|
|
5
8
|
|
|
6
|
-
|
|
9
|
+
//測試自行創建docker容器供MSSQL服務, 測試結束即銷毀, 故僅需環境已安裝docker
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
let execFileAsync = promisify(execFile)
|
|
13
|
+
|
|
14
|
+
let ctName = 'worm-test-mssql'
|
|
15
|
+
let ctImage = 'mcr.microsoft.com/mssql/server:2022-latest'
|
|
16
|
+
let saPassword = 'Worm#Mssql2026'
|
|
17
|
+
let ctPort = null //容器對外埠, 由getFreePort動態取得, 避免與既有MSSQL服務衝突
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
let delay = (ms) => {
|
|
21
|
+
return new Promise((resolve) => {
|
|
22
|
+
setTimeout(resolve, ms)
|
|
23
|
+
})
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
//getFreePort, 由系統配發空閒埠
|
|
27
|
+
let getFreePort = () => {
|
|
28
|
+
return new Promise((resolve, reject) => {
|
|
29
|
+
let srv = net.createServer()
|
|
30
|
+
srv.on('error', reject)
|
|
31
|
+
srv.listen(0, () => {
|
|
32
|
+
let port = srv.address().port
|
|
33
|
+
srv.close(() => {
|
|
34
|
+
resolve(port)
|
|
35
|
+
})
|
|
36
|
+
})
|
|
37
|
+
})
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
//docker, 以陣列傳參不經shell, 避免路徑與引號轉譯問題
|
|
41
|
+
let docker = (args) => {
|
|
42
|
+
return execFileAsync('docker', args)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
//sqlcmd, 於容器內以sa執行語句, -b令錯誤時回傳非0離開碼
|
|
46
|
+
let sqlcmd = (args) => {
|
|
47
|
+
return docker(['exec', ctName, '/opt/mssql-tools18/bin/sqlcmd', '-C', '-S', 'localhost', '-U', 'sa', '-P', saPassword, '-b', ...args])
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
//startContainer, 創建容器並等待服務就緒, 再建置測試用資料庫與帳號
|
|
51
|
+
let startContainer = async () => {
|
|
52
|
+
|
|
53
|
+
//check docker
|
|
54
|
+
await docker(['version', '--format', '{{.Server.Version}}'])
|
|
55
|
+
.catch(() => {
|
|
56
|
+
throw new Error('需先安裝並啟動docker才能執行mssql測試')
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
//清除前次殘留容器
|
|
60
|
+
await docker(['rm', '-f', ctName]).catch(() => {})
|
|
61
|
+
|
|
62
|
+
//run
|
|
63
|
+
ctPort = await getFreePort()
|
|
64
|
+
await docker(['run', '-d', '--rm', '--name', ctName, '-e', 'ACCEPT_EULA=Y', '-e', `MSSQL_SA_PASSWORD=${saPassword}`, '-p', `${ctPort}:1433`, ctImage])
|
|
65
|
+
|
|
66
|
+
//等待服務就緒, 首次需拉取映像故給予較長時間
|
|
67
|
+
let ready = false
|
|
68
|
+
for (let i = 0; i < 90; i++) {
|
|
69
|
+
let ok = await sqlcmd(['-Q', 'SELECT 1'])
|
|
70
|
+
.then(() => true)
|
|
71
|
+
.catch(() => false)
|
|
72
|
+
if (ok) {
|
|
73
|
+
ready = true
|
|
74
|
+
break
|
|
75
|
+
}
|
|
76
|
+
await delay(2000)
|
|
77
|
+
}
|
|
78
|
+
if (!ready) {
|
|
79
|
+
throw new Error('mssql容器啟動逾時')
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
//建置資料庫worm與帳號username/password(db_owner)
|
|
83
|
+
await sqlcmd(['-Q', 'CREATE DATABASE worm;'])
|
|
84
|
+
await sqlcmd(['-Q', `CREATE LOGIN username WITH PASSWORD='password', CHECK_POLICY=OFF, CHECK_EXPIRATION=OFF, DEFAULT_DATABASE=worm;`])
|
|
85
|
+
await sqlcmd(['-d', 'worm', '-Q', 'CREATE USER username FOR LOGIN username; ALTER ROLE db_owner ADD MEMBER username;'])
|
|
86
|
+
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
//stopContainer, 銷毀容器
|
|
90
|
+
let stopContainer = async () => {
|
|
91
|
+
await docker(['rm', '-f', ctName]).catch(() => {})
|
|
92
|
+
}
|
|
7
93
|
|
|
8
94
|
|
|
9
95
|
let genOpt = () => {
|
|
10
96
|
return {
|
|
11
|
-
url:
|
|
97
|
+
url: `mssql://username:password@localhost:${ctPort}`,
|
|
12
98
|
db: 'worm',
|
|
13
99
|
cl: 'users',
|
|
14
100
|
fdModels: './models',
|
|
@@ -16,11 +102,23 @@ let genOpt = () => {
|
|
|
16
102
|
}
|
|
17
103
|
|
|
18
104
|
|
|
105
|
+
before(async function() {
|
|
106
|
+
this.timeout(600000) //含拉取映像與服務啟動
|
|
107
|
+
await startContainer()
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
after(async function() {
|
|
111
|
+
this.timeout(120000)
|
|
112
|
+
await stopContainer()
|
|
113
|
+
})
|
|
114
|
+
|
|
115
|
+
|
|
19
116
|
describe('mssql crud', function() {
|
|
20
117
|
|
|
21
|
-
let w =
|
|
118
|
+
let w = null
|
|
22
119
|
|
|
23
120
|
before(async function() {
|
|
121
|
+
w = wo(genOpt())
|
|
24
122
|
await w.createStorage()
|
|
25
123
|
await w.delAll().catch(() => {})
|
|
26
124
|
})
|
|
@@ -109,10 +207,11 @@ describe('mssql crud', function() {
|
|
|
109
207
|
|
|
110
208
|
describe('mssql transaction commit', function() {
|
|
111
209
|
|
|
112
|
-
let w =
|
|
210
|
+
let w = null
|
|
113
211
|
let instance = null
|
|
114
212
|
|
|
115
213
|
before(async function() {
|
|
214
|
+
w = wo(genOpt())
|
|
116
215
|
await w.createStorage()
|
|
117
216
|
await w.delAll().catch(() => {})
|
|
118
217
|
})
|
|
@@ -163,10 +262,11 @@ describe('mssql transaction commit', function() {
|
|
|
163
262
|
|
|
164
263
|
describe('mssql transaction rollback', function() {
|
|
165
264
|
|
|
166
|
-
let w =
|
|
265
|
+
let w = null
|
|
167
266
|
let instance = null
|
|
168
267
|
|
|
169
268
|
before(async function() {
|
|
269
|
+
w = wo(genOpt())
|
|
170
270
|
await w.createStorage()
|
|
171
271
|
await w.delAll().catch(() => {})
|
|
172
272
|
})
|
package/toolg/cleanFolder.mjs
CHANGED
package/.github/workflows/ci.yml
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
name: test
|
|
2
|
-
|
|
3
|
-
on:
|
|
4
|
-
push:
|
|
5
|
-
branches: [master]
|
|
6
|
-
pull_request:
|
|
7
|
-
workflow_dispatch:
|
|
8
|
-
|
|
9
|
-
jobs:
|
|
10
|
-
test:
|
|
11
|
-
runs-on: ubuntu-latest
|
|
12
|
-
|
|
13
|
-
services:
|
|
14
|
-
mssql:
|
|
15
|
-
image: mcr.microsoft.com/mssql/server:2022-latest
|
|
16
|
-
env:
|
|
17
|
-
ACCEPT_EULA: Y
|
|
18
|
-
MSSQL_SA_PASSWORD: Worm#Mssql2026
|
|
19
|
-
ports:
|
|
20
|
-
- 1433:1433
|
|
21
|
-
|
|
22
|
-
steps:
|
|
23
|
-
- uses: actions/checkout@v4
|
|
24
|
-
|
|
25
|
-
- uses: actions/setup-node@v4
|
|
26
|
-
with:
|
|
27
|
-
node-version: 20
|
|
28
|
-
cache: npm
|
|
29
|
-
|
|
30
|
-
- name: Install dependencies
|
|
31
|
-
run: npm ci
|
|
32
|
-
|
|
33
|
-
- name: Wait for MSSQL ready
|
|
34
|
-
run: |
|
|
35
|
-
for i in $(seq 1 30); do
|
|
36
|
-
if docker exec ${{ job.services.mssql.id }} /opt/mssql-tools18/bin/sqlcmd -C -S localhost -U sa -P 'Worm#Mssql2026' -b -Q "SELECT 1" >/dev/null 2>&1; then
|
|
37
|
-
echo "mssql ready"
|
|
38
|
-
exit 0
|
|
39
|
-
fi
|
|
40
|
-
sleep 3
|
|
41
|
-
done
|
|
42
|
-
echo "mssql not ready in time"
|
|
43
|
-
exit 1
|
|
44
|
-
|
|
45
|
-
- name: Provision worm database and login
|
|
46
|
-
run: |
|
|
47
|
-
docker exec ${{ job.services.mssql.id }} /opt/mssql-tools18/bin/sqlcmd -C -S localhost -U sa -P 'Worm#Mssql2026' -b -Q "CREATE DATABASE worm;"
|
|
48
|
-
docker exec ${{ job.services.mssql.id }} /opt/mssql-tools18/bin/sqlcmd -C -S localhost -U sa -P 'Worm#Mssql2026' -b -Q "CREATE LOGIN username WITH PASSWORD='password', CHECK_POLICY=OFF, CHECK_EXPIRATION=OFF, DEFAULT_DATABASE=worm;"
|
|
49
|
-
docker exec ${{ job.services.mssql.id }} /opt/mssql-tools18/bin/sqlcmd -C -S localhost -U sa -P 'Worm#Mssql2026' -b -d worm -Q "CREATE USER username FOR LOGIN username; ALTER ROLE db_owner ADD MEMBER username;"
|
|
50
|
-
|
|
51
|
-
- name: Run tests
|
|
52
|
-
run: npm test
|