w-orm-reladb 1.0.32 → 1.0.36
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/.eslintrc.js +53 -49
- package/.github/workflows/ci-test.yml +2 -1
- package/README.md +40 -34
- package/SECURITY.md +5 -0
- package/dist/w-orm-reladb.umd.js +3 -3
- package/dist/w-orm-reladb.umd.js.map +1 -1
- package/docs/WOrmReladb.html +1 -1
- package/docs/WOrmReladb.mjs.html +5 -5
- package/docs/index.html +1 -1
- package/{sp-genModelsByTabs.mjs → g-genModelsByTabs.mjs} +1 -1
- package/{sp-mssql-concurrency.mjs → g-mssql-concurrency.mjs} +1 -1
- package/{sp-mssql-timerQuery.mjs → g-mssql-timerQuery.mjs} +1 -1
- package/{sp-mssql-transaction-commit.mjs → g-mssql-transaction-commit.mjs} +4 -3
- package/{sp-mssql-transaction-rollback.mjs → g-mssql-transaction-rollback.mjs} +5 -4
- package/{sp-mssql.mjs → g-mssql.mjs} +6 -5
- package/{sp-sqlite-concurrency.mjs → g-sqlite-concurrency.mjs} +2 -2
- package/g-sqlite-encryption-transaction-commit.mjs +196 -0
- package/{sp-sqlite-encryption-transaction-rollback.mjs → g-sqlite-encryption-transaction-rollback.mjs} +1 -1
- package/{sp-sqlite-encryption.mjs → g-sqlite-encryption.mjs} +6 -5
- package/{sp-sqlite-transaction-commit.mjs → g-sqlite-transaction-commit.mjs} +6 -5
- package/{sp-sqlite-transaction-rollback.mjs → g-sqlite-transaction-rollback.mjs} +6 -5
- package/{sp-sqlite.mjs → g-sqlite.mjs} +6 -5
- package/package.json +11 -11
- package/src/WOrmReladb.mjs +4 -4
- package/test/{all.test.js → all.test.mjs} +0 -0
- package/worm.sqlite +0 -0
- package/sp-sqlite-encryption-transaction-commit.mjs +0 -195
|
@@ -1,195 +0,0 @@
|
|
|
1
|
-
import wo from './src/WOrmReladb.mjs'
|
|
2
|
-
import fs from 'fs'
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
let username = 'username'
|
|
6
|
-
let password = 'password'
|
|
7
|
-
let opt = {
|
|
8
|
-
url: `sqlite://${username}:${password}`,
|
|
9
|
-
db: 'worm',
|
|
10
|
-
cl: 'users',
|
|
11
|
-
fdModels: './models',
|
|
12
|
-
// modelType: 'json',
|
|
13
|
-
// autoGenPK: false,
|
|
14
|
-
storage: './worm.sqlite',
|
|
15
|
-
useEncryption: true,
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
//因worm.sqlite可能為加密數據, 若有切換useEncryption時得先刪除, 再通過createStorage重新產生
|
|
19
|
-
if (fs.existsSync(opt.storage)) {
|
|
20
|
-
fs.unlinkSync(opt.storage)
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
let rs = [
|
|
24
|
-
{
|
|
25
|
-
id: 'id-peter',
|
|
26
|
-
name: 'peter',
|
|
27
|
-
value: 123,
|
|
28
|
-
},
|
|
29
|
-
{
|
|
30
|
-
id: 'id-rosemary',
|
|
31
|
-
name: 'rosemary',
|
|
32
|
-
value: 123.456,
|
|
33
|
-
},
|
|
34
|
-
{
|
|
35
|
-
id: '',
|
|
36
|
-
name: 'kettle',
|
|
37
|
-
value: 456,
|
|
38
|
-
},
|
|
39
|
-
]
|
|
40
|
-
|
|
41
|
-
let rsm = [
|
|
42
|
-
{
|
|
43
|
-
id: 'id-peter',
|
|
44
|
-
name: 'peter(modify)'
|
|
45
|
-
},
|
|
46
|
-
{
|
|
47
|
-
id: 'id-rosemary',
|
|
48
|
-
name: 'rosemary(modify)'
|
|
49
|
-
},
|
|
50
|
-
{
|
|
51
|
-
id: '',
|
|
52
|
-
name: 'kettle(modify)'
|
|
53
|
-
},
|
|
54
|
-
]
|
|
55
|
-
|
|
56
|
-
async function testCommit() {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
//w
|
|
60
|
-
let w = wo(opt)
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
//createStorage, create table for mssql
|
|
64
|
-
await w.createStorage()
|
|
65
|
-
console.log('createStorage')
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
//genModelsByDB, disable if got models
|
|
69
|
-
// await w.genModelsByDB({
|
|
70
|
-
// username,
|
|
71
|
-
// password,
|
|
72
|
-
// dialect: 'mssql', //default
|
|
73
|
-
// host: 'localhost', //default
|
|
74
|
-
// port: 1433, //default
|
|
75
|
-
// db: opt.db,
|
|
76
|
-
// fdModels: opt.fdModels,
|
|
77
|
-
// })
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
//on
|
|
81
|
-
w.on('change', function(mode, data, res) {
|
|
82
|
-
console.log('change', mode)
|
|
83
|
-
})
|
|
84
|
-
w.on('error', function(err) {
|
|
85
|
-
console.log('error', err)
|
|
86
|
-
})
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
//delAll
|
|
90
|
-
await w.delAll()
|
|
91
|
-
.then(function(msg) {
|
|
92
|
-
console.log('delAll then', msg)
|
|
93
|
-
})
|
|
94
|
-
.catch(function(msg) {
|
|
95
|
-
console.log('delAll catch', msg)
|
|
96
|
-
})
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
//connState
|
|
100
|
-
let instance = await w.init()
|
|
101
|
-
let transaction = await w.genTransaction()
|
|
102
|
-
let connState = {
|
|
103
|
-
instance, //可由外部初始化共用instance, 可單獨使用不另外給transaction
|
|
104
|
-
transaction, //若外部使用共用之transaction, 亦需使用共用instance
|
|
105
|
-
}
|
|
106
|
-
console.log('init')
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
//insert
|
|
110
|
-
await w.insert(rs, connState)
|
|
111
|
-
.then(function(msg) {
|
|
112
|
-
console.log('insert then', msg)
|
|
113
|
-
})
|
|
114
|
-
.catch(function(msg) {
|
|
115
|
-
console.log('insert catch', msg)
|
|
116
|
-
})
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
//save
|
|
120
|
-
await w.save(rsm, { ...connState, autoInsert: false })
|
|
121
|
-
.then(function(msg) {
|
|
122
|
-
console.log('save then', msg)
|
|
123
|
-
})
|
|
124
|
-
.catch(function(msg) {
|
|
125
|
-
console.log('save catch', msg)
|
|
126
|
-
})
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
//del
|
|
130
|
-
await w.del({ id: 'id-rosemary' }, connState)
|
|
131
|
-
.then(function(msg) {
|
|
132
|
-
console.log('del then', msg)
|
|
133
|
-
})
|
|
134
|
-
.catch(function(msg) {
|
|
135
|
-
console.log('del catch', msg)
|
|
136
|
-
})
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
//select all
|
|
140
|
-
let ssBeforeCommit = await w.select(null, connState)
|
|
141
|
-
console.log('select all (before commit)', ssBeforeCommit) //此時select可查到暫時有效的數據
|
|
142
|
-
// => [
|
|
143
|
-
// { id: 'id-peter', name: 'peter(modify)', value: 123 },
|
|
144
|
-
// { id: '{random id}', name: 'kettle', value: 456 }
|
|
145
|
-
// ]
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
//commit
|
|
149
|
-
await transaction.commit()
|
|
150
|
-
console.log('commit')
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
//close
|
|
154
|
-
await instance.close()
|
|
155
|
-
console.log('close')
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
//select all
|
|
159
|
-
let ssFinal = await w.select()
|
|
160
|
-
console.log('select all (final)', ssFinal)
|
|
161
|
-
// => [
|
|
162
|
-
// { id: 'id-peter', name: 'peter(modify)', value: 123 },
|
|
163
|
-
// { id: '{random id}', name: 'kettle', value: 456 }
|
|
164
|
-
// ]
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
//check
|
|
168
|
-
let rPeter = ssFinal.filter((v) => {
|
|
169
|
-
return v.name === 'peter(modify)'
|
|
170
|
-
})
|
|
171
|
-
let bPeter = rPeter?.[0]?.value === 123
|
|
172
|
-
|
|
173
|
-
let rRosemary = ssFinal.filter((v) => {
|
|
174
|
-
return v.name === 'rosemary(modify)'
|
|
175
|
-
})
|
|
176
|
-
let bRosemary = rRosemary?.[0]?.value === 123.456
|
|
177
|
-
|
|
178
|
-
let rKettle = ssFinal.filter((v) => {
|
|
179
|
-
return v.name === 'kettle'
|
|
180
|
-
})
|
|
181
|
-
let bKettle = rKettle?.[0]?.value === 456
|
|
182
|
-
|
|
183
|
-
if (bPeter && !bRosemary && bKettle) {
|
|
184
|
-
console.log('commit success')
|
|
185
|
-
}
|
|
186
|
-
else {
|
|
187
|
-
console.log('commit error')
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
}
|
|
192
|
-
testCommit()
|
|
193
|
-
// @journeyapps/sqlcipher can not support transaction.
|
|
194
|
-
|
|
195
|
-
//node --experimental-modules --es-module-specifier-resolution=node sp-sqlite-encryption-transaction-commit.mjs
|