w-serv-orm 1.0.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/.editorconfig +9 -0
- package/.eslintignore +3 -0
- package/.eslintrc.js +54 -0
- package/.jsdoc +25 -0
- package/LICENSE +21 -0
- package/README.md +74 -0
- package/SECURITY.md +5 -0
- package/babel.config.js +14 -0
- package/dist/w-serv-orm.umd.js +7 -0
- package/dist/w-serv-orm.umd.js.map +1 -0
- package/docs/WServOrm.html +582 -0
- package/docs/WServOrm.mjs.html +171 -0
- package/docs/fonts/Montserrat/Montserrat-Bold.eot +0 -0
- package/docs/fonts/Montserrat/Montserrat-Bold.ttf +0 -0
- package/docs/fonts/Montserrat/Montserrat-Bold.woff +0 -0
- package/docs/fonts/Montserrat/Montserrat-Bold.woff2 +0 -0
- package/docs/fonts/Montserrat/Montserrat-Regular.eot +0 -0
- package/docs/fonts/Montserrat/Montserrat-Regular.ttf +0 -0
- package/docs/fonts/Montserrat/Montserrat-Regular.woff +0 -0
- package/docs/fonts/Montserrat/Montserrat-Regular.woff2 +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.eot +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.svg +978 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.ttf +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.woff +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.woff2 +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.eot +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.svg +1049 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.ttf +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.woff +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.woff2 +0 -0
- package/docs/index.html +81 -0
- package/docs/scripts/collapse.js +20 -0
- package/docs/scripts/linenumber.js +25 -0
- package/docs/scripts/nav.js +12 -0
- package/docs/scripts/polyfill.js +4 -0
- package/docs/scripts/prettify/Apache-License-2.0.txt +202 -0
- package/docs/scripts/prettify/lang-css.js +2 -0
- package/docs/scripts/prettify/prettify.js +28 -0
- package/docs/scripts/search.js +83 -0
- package/docs/styles/jsdoc.css +765 -0
- package/docs/styles/prettify.css +79 -0
- package/g.mOrm.mjs +54 -0
- package/package.json +37 -0
- package/schema/gi.mjs +8 -0
- package/schema/index.mjs +16 -0
- package/schema/tables/tests.mjs +78 -0
- package/src/WServOrm.mjs +102 -0
- package/src/getDbBackupAndRecover.mjs +90 -0
- package/src/getMapOrm.mjs +298 -0
- package/src/getProc.mjs +176 -0
- package/src/getWoItems.mjs +69 -0
- package/test/all.test.mjs +10 -0
- package/toolg/addVersion.mjs +4 -0
- package/toolg/cleanFolder.mjs +4 -0
- package/toolg/gDistRollup.mjs +21 -0
- package/toolg/modifyReadme.mjs +4 -0
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
.pln {
|
|
2
|
+
color: #ddd;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
/* string content */
|
|
6
|
+
.str {
|
|
7
|
+
color: #61ce3c;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/* a keyword */
|
|
11
|
+
.kwd {
|
|
12
|
+
color: #fbde2d;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/* a comment */
|
|
16
|
+
.com {
|
|
17
|
+
color: #aeaeae;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/* a type name */
|
|
21
|
+
.typ {
|
|
22
|
+
color: #8da6ce;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/* a literal value */
|
|
26
|
+
.lit {
|
|
27
|
+
color: #fbde2d;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/* punctuation */
|
|
31
|
+
.pun {
|
|
32
|
+
color: #ddd;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/* lisp open bracket */
|
|
36
|
+
.opn {
|
|
37
|
+
color: #000000;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/* lisp close bracket */
|
|
41
|
+
.clo {
|
|
42
|
+
color: #000000;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/* a markup tag name */
|
|
46
|
+
.tag {
|
|
47
|
+
color: #8da6ce;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/* a markup attribute name */
|
|
51
|
+
.atn {
|
|
52
|
+
color: #fbde2d;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/* a markup attribute value */
|
|
56
|
+
.atv {
|
|
57
|
+
color: #ddd;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/* a declaration */
|
|
61
|
+
.dec {
|
|
62
|
+
color: #EF5050;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/* a variable name */
|
|
66
|
+
.var {
|
|
67
|
+
color: #c82829;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/* a function name */
|
|
71
|
+
.fun {
|
|
72
|
+
color: #4271ae;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/* Specify class=linenums on a pre to get line numbering */
|
|
76
|
+
ol.linenums {
|
|
77
|
+
margin-top: 0;
|
|
78
|
+
margin-bottom: 0;
|
|
79
|
+
}
|
package/g.mOrm.mjs
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import WOrm from 'w-orm-mongodb/src/WOrmMongodb.mjs' //自行選擇引用ORM
|
|
2
|
+
import ds from './schema/index.mjs' //先行建置schema
|
|
3
|
+
import WServOrm from './src/WServOrm.mjs'
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
//st
|
|
7
|
+
let st = {
|
|
8
|
+
dbUsername: 'username',
|
|
9
|
+
dbPassword: 'password',
|
|
10
|
+
dbName: 'wservorm',
|
|
11
|
+
dbIP: 'localhost',
|
|
12
|
+
dbPort: 27017,
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
//WServOrm
|
|
16
|
+
let opt = {
|
|
17
|
+
url: `mongodb://${st.dbUsername}:${st.dbPassword}@${st.dbIP}:${st.dbPort}`,
|
|
18
|
+
db: st.dbName,
|
|
19
|
+
getUserById: null,
|
|
20
|
+
bCheckUser: false,
|
|
21
|
+
bExcludeWhenNotAdmin: false,
|
|
22
|
+
}
|
|
23
|
+
let r = WServOrm(ds, WOrm, opt)
|
|
24
|
+
console.log(r) //回傳server用orm相關函數
|
|
25
|
+
// => {
|
|
26
|
+
// backup: [AsyncFunction: backup],
|
|
27
|
+
// recover: [AsyncFunction: recover],
|
|
28
|
+
// woItems: {
|
|
29
|
+
// tests: EventEmitter {
|
|
30
|
+
// _events: [Object: null prototype] {},
|
|
31
|
+
// _eventsCount: 0,
|
|
32
|
+
// _maxListeners: undefined,
|
|
33
|
+
// select: [AsyncFunction: select],
|
|
34
|
+
// insert: [AsyncFunction: insert],
|
|
35
|
+
// save: [AsyncFunction: save],
|
|
36
|
+
// del: [AsyncFunction: del],
|
|
37
|
+
// delAll: [AsyncFunction: delAll],
|
|
38
|
+
// selectGfs: [AsyncFunction: selectGfs],
|
|
39
|
+
// insertGfs: [AsyncFunction: insertGfs],
|
|
40
|
+
// delGfs: [AsyncFunction: delGfs],
|
|
41
|
+
// delAllGfs: [AsyncFunction: delAllGfs],
|
|
42
|
+
// [Symbol(kCapture)]: false
|
|
43
|
+
// }
|
|
44
|
+
// },
|
|
45
|
+
// addFunCheck: [Function: addFunCheck],
|
|
46
|
+
// addFunPreProcessing: [Function: addFunPreProcessing],
|
|
47
|
+
// addFunPostProcessing: [Function: addFunPostProcessing],
|
|
48
|
+
// procOrm: [AsyncFunction: procOrm]
|
|
49
|
+
// }
|
|
50
|
+
|
|
51
|
+
// export default r
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
//node --experimental-modules --es-module-specifier-resolution=node g.mOrm.mjs
|
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "w-serv-orm",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "An operator for orm in server.",
|
|
5
|
+
"main": "dist/w-serv-orm.umd.js",
|
|
6
|
+
"dependencies": {
|
|
7
|
+
"lodash": "^4.17.21",
|
|
8
|
+
"wsemi": "^1.6.55"
|
|
9
|
+
},
|
|
10
|
+
"devDependencies": {
|
|
11
|
+
"w-orm-mongodb": "^1.1.26",
|
|
12
|
+
"w-data-collector": "^1.0.13",
|
|
13
|
+
"w-package-tools": "^1.0.65"
|
|
14
|
+
},
|
|
15
|
+
"scripts": {
|
|
16
|
+
"test": "mocha --parallel --timeout 60000 --experimental-modules --es-module-specifier-resolution=node",
|
|
17
|
+
"deploy": "gh-pages -d docs"
|
|
18
|
+
},
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "git+https://github.com/yuda-lyu/w-serv-orm.git"
|
|
22
|
+
},
|
|
23
|
+
"keywords": [
|
|
24
|
+
"package",
|
|
25
|
+
"tool",
|
|
26
|
+
"operator",
|
|
27
|
+
"server",
|
|
28
|
+
"ORM",
|
|
29
|
+
"nodejs"
|
|
30
|
+
],
|
|
31
|
+
"author": "yuda-lyu(semisphere)",
|
|
32
|
+
"license": "MIT",
|
|
33
|
+
"bugs": {
|
|
34
|
+
"url": "https://github.com/yuda-lyu/w-serv-orm/issues"
|
|
35
|
+
},
|
|
36
|
+
"homepage": "https://github.com/yuda-lyu/w-serv-orm#readme"
|
|
37
|
+
}
|
package/schema/gi.mjs
ADDED
package/schema/index.mjs
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import tests from './tables/tests.mjs'
|
|
2
|
+
import build from 'w-data-collector/src/build.mjs'
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
let cs = {
|
|
6
|
+
tests,
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
//ds
|
|
10
|
+
let ds = {}
|
|
11
|
+
for (let k in cs) {
|
|
12
|
+
ds[k] = build(cs[k], { useCreateStorage: false })
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
export default ds
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import map from 'lodash/map'
|
|
2
|
+
import keys from 'lodash/keys'
|
|
3
|
+
import genID from 'wsemi/src/genID.mjs'
|
|
4
|
+
import dtmapping from 'wsemi/src/dtmapping.mjs'
|
|
5
|
+
import dtpick from 'wsemi/src/dtpick.mjs'
|
|
6
|
+
import nowms2str from 'wsemi/src/nowms2str.mjs'
|
|
7
|
+
import now2strp from 'wsemi/src/now2strp.mjs'
|
|
8
|
+
import isestr from 'wsemi/src/isestr'
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
let keyTable = 'tests'
|
|
12
|
+
let tableNameCht = 'Tests'
|
|
13
|
+
let tableNameEng = 'Tests'
|
|
14
|
+
|
|
15
|
+
let settings = {
|
|
16
|
+
'id': {
|
|
17
|
+
pk: true,
|
|
18
|
+
name: '主鍵',
|
|
19
|
+
type: 'STRING',
|
|
20
|
+
},
|
|
21
|
+
'timeCreate': {
|
|
22
|
+
name: '創建時間',
|
|
23
|
+
type: 'STRING',
|
|
24
|
+
},
|
|
25
|
+
'timeUpdate': {
|
|
26
|
+
name: '更新時間',
|
|
27
|
+
type: 'STRING',
|
|
28
|
+
},
|
|
29
|
+
'isActive': {
|
|
30
|
+
name: '是否有效',
|
|
31
|
+
type: 'STRING',
|
|
32
|
+
},
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
let funNew = (ndata = {}) => {
|
|
36
|
+
let o = dtmapping(ndata, keys(settings))
|
|
37
|
+
o.id = `${now2strp()}-${genID()}`
|
|
38
|
+
o.timeCreate = nowms2str()
|
|
39
|
+
o.timeUpdate = o.timeCreate
|
|
40
|
+
o.isActive = 'y'
|
|
41
|
+
return o
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
let funTest = () => {
|
|
45
|
+
let rs = map([
|
|
46
|
+
{
|
|
47
|
+
'id': 'id-for-tests-1',
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
'id': 'id-for-tests-2',
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
'id': 'id-for-tests-3',
|
|
54
|
+
},
|
|
55
|
+
], (item, k) => {
|
|
56
|
+
let v = funNew({ ...item, order: k })
|
|
57
|
+
v.id = item.id
|
|
58
|
+
if (isestr(item.timeUpdate)) {
|
|
59
|
+
v.timeUpdate = item.timeUpdate
|
|
60
|
+
}
|
|
61
|
+
v = dtpick(v, keys(settings))
|
|
62
|
+
return v
|
|
63
|
+
})
|
|
64
|
+
console.log(`已產生: {keyTable} 測試資料`, rs)
|
|
65
|
+
return rs
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
let tab = {
|
|
69
|
+
keyTable,
|
|
70
|
+
tableNameCht,
|
|
71
|
+
tableNameEng,
|
|
72
|
+
settings,
|
|
73
|
+
funNew,
|
|
74
|
+
funTest,
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
export default tab
|
package/src/WServOrm.mjs
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import getDbBackupAndRecover from './getDbBackupAndRecover.mjs'
|
|
2
|
+
import getWoItems from './getWoItems.mjs'
|
|
3
|
+
import getMapOrm from './getMapOrm.mjs'
|
|
4
|
+
import getProc from './getProc.mjs'
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* 產生伺服器ORM的支援物件
|
|
9
|
+
*
|
|
10
|
+
* @class
|
|
11
|
+
* @param {Object} ds 輸入資料表設定物件
|
|
12
|
+
* @param {Object} WOrm 輸入資料庫ORM物件
|
|
13
|
+
* @param {Object} [opt={}] 輸入設定物件,預設{}
|
|
14
|
+
* @param {String} [opt.url=''] 輸入資料庫連線位址字串,預設''
|
|
15
|
+
* @param {String} [opt.db=''] 輸入資料庫名稱字串,預設''
|
|
16
|
+
* @param {Boolean} [opt.bCheckUser=true] 輸入是否檢查使用者資訊布林值,預設true
|
|
17
|
+
* @param {Function} [opt.getUserById=null] 輸入當bCheckUser=true時依照使用者ID取得使用者資訊物件函數,預設null
|
|
18
|
+
* @param {Boolean} [opt.bExcludeWhenNotAdmin=true] 輸入使用ORM的select方法時是否自動刪除數據內isActive欄位之布林值,預設true
|
|
19
|
+
* @returns {Object} 回傳通訊物件,可監聽事件open、error、clientChange、execute、broadcast、deliver,可使用函數broadcast
|
|
20
|
+
* @example
|
|
21
|
+
*
|
|
22
|
+
* import WOrm from 'w-orm-mongodb/src/WOrmMongodb.mjs' //自行選擇引用ORM
|
|
23
|
+
* import ds from './schema/index.mjs' //先行建置schema
|
|
24
|
+
* import WServOrm from './src/WServOrm.mjs'
|
|
25
|
+
*
|
|
26
|
+
* //st
|
|
27
|
+
* let st = {
|
|
28
|
+
* dbUsername: 'username',
|
|
29
|
+
* dbPassword: 'password',
|
|
30
|
+
* dbName: 'wservorm',
|
|
31
|
+
* dbIP: 'localhost',
|
|
32
|
+
* dbPort: 27017,
|
|
33
|
+
* }
|
|
34
|
+
*
|
|
35
|
+
* //WServOrm
|
|
36
|
+
* let opt = {
|
|
37
|
+
* url: `mongodb://${st.dbUsername}:${st.dbPassword}@${st.dbIP}:${st.dbPort}`,
|
|
38
|
+
* db: st.dbName,
|
|
39
|
+
* getUserById: null,
|
|
40
|
+
* bCheckUser: false,
|
|
41
|
+
* bExcludeWhenNotAdmin: false,
|
|
42
|
+
* }
|
|
43
|
+
* let r = WServOrm(ds, WOrm, opt)
|
|
44
|
+
* console.log(r) //回傳server用orm相關函數
|
|
45
|
+
* // => {
|
|
46
|
+
* // backup: [AsyncFunction: backup],
|
|
47
|
+
* // recover: [AsyncFunction: recover],
|
|
48
|
+
* // woItems: {
|
|
49
|
+
* // tests: EventEmitter {
|
|
50
|
+
* // _events: [Object: null prototype] {},
|
|
51
|
+
* // _eventsCount: 0,
|
|
52
|
+
* // _maxListeners: undefined,
|
|
53
|
+
* // select: [AsyncFunction: select],
|
|
54
|
+
* // insert: [AsyncFunction: insert],
|
|
55
|
+
* // save: [AsyncFunction: save],
|
|
56
|
+
* // del: [AsyncFunction: del],
|
|
57
|
+
* // delAll: [AsyncFunction: delAll],
|
|
58
|
+
* // selectGfs: [AsyncFunction: selectGfs],
|
|
59
|
+
* // insertGfs: [AsyncFunction: insertGfs],
|
|
60
|
+
* // delGfs: [AsyncFunction: delGfs],
|
|
61
|
+
* // delAllGfs: [AsyncFunction: delAllGfs],
|
|
62
|
+
* // [Symbol(kCapture)]: false
|
|
63
|
+
* // }
|
|
64
|
+
* // },
|
|
65
|
+
* // addFunCheck: [Function: addFunCheck],
|
|
66
|
+
* // addFunPreProcessing: [Function: addFunPreProcessing],
|
|
67
|
+
* // addFunPostProcessing: [Function: addFunPostProcessing],
|
|
68
|
+
* // procOrm: [AsyncFunction: procOrm]
|
|
69
|
+
* // }
|
|
70
|
+
*
|
|
71
|
+
* // export default r
|
|
72
|
+
*
|
|
73
|
+
*/
|
|
74
|
+
function WServOrm(ds, WOrm, opt = {}) {
|
|
75
|
+
// url:'',
|
|
76
|
+
// db:'',
|
|
77
|
+
// bCheckUser: true,
|
|
78
|
+
// getUserById: null,
|
|
79
|
+
// bExcludeWhenNotAdmin: true,
|
|
80
|
+
|
|
81
|
+
//getWoItems
|
|
82
|
+
let woItems = getWoItems(ds, WOrm, opt)
|
|
83
|
+
// console.log('woItems', woItems)
|
|
84
|
+
|
|
85
|
+
//getMapOrm
|
|
86
|
+
let mapOrm = getMapOrm(ds, woItems)
|
|
87
|
+
// console.log('mapOrm', mapOrm)
|
|
88
|
+
|
|
89
|
+
//getProc
|
|
90
|
+
let proc = getProc(mapOrm, opt)
|
|
91
|
+
// console.log('proc', proc)
|
|
92
|
+
|
|
93
|
+
return {
|
|
94
|
+
...getDbBackupAndRecover,
|
|
95
|
+
woItems,
|
|
96
|
+
// mapOrm,
|
|
97
|
+
...proc,
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
export default WServOrm
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
// import path from 'path'
|
|
2
|
+
import fs from 'fs'
|
|
3
|
+
import trim from 'lodash/trim'
|
|
4
|
+
import size from 'lodash/size'
|
|
5
|
+
import pmSeries from 'wsemi/src/pmSeries.mjs'
|
|
6
|
+
import fsIsFile from 'wsemi/src/fsIsFile.mjs'
|
|
7
|
+
import iseobj from 'wsemi/src/iseobj.mjs'
|
|
8
|
+
import isfun from 'wsemi/src/isfun.mjs'
|
|
9
|
+
import isbol from 'wsemi/src/isbol.mjs'
|
|
10
|
+
import j2o from 'wsemi/src/j2o.mjs'
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
async function backup(woItems) {
|
|
14
|
+
|
|
15
|
+
//rs
|
|
16
|
+
let rs = await pmSeries(woItems, async (v, k) => {
|
|
17
|
+
console.log('backup...', k)
|
|
18
|
+
let r = await v.select()
|
|
19
|
+
return {
|
|
20
|
+
name: k,
|
|
21
|
+
data: r,
|
|
22
|
+
}
|
|
23
|
+
})
|
|
24
|
+
// console.log('backup rs', rs)
|
|
25
|
+
|
|
26
|
+
return rs
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
async function recover(fp, woItems, genModels, needCreateStorage = false) {
|
|
31
|
+
|
|
32
|
+
//check
|
|
33
|
+
if (!fsIsFile(fp)) {
|
|
34
|
+
console.log('fp', fp)
|
|
35
|
+
throw new Error('fp is not exist')
|
|
36
|
+
}
|
|
37
|
+
if (!iseobj(woItems)) {
|
|
38
|
+
console.log('woItems', woItems)
|
|
39
|
+
throw new Error('invalid woItems')
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
//genModels
|
|
43
|
+
if (!isfun(genModels)) {
|
|
44
|
+
genModels = null
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
//needCreateStorage
|
|
48
|
+
if (!isbol(needCreateStorage)) {
|
|
49
|
+
needCreateStorage = false
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
//readFileSync
|
|
53
|
+
let j = fs.readFileSync(fp, 'utf8')
|
|
54
|
+
j = trim(j) //去除bom
|
|
55
|
+
// console.log('j', j)
|
|
56
|
+
|
|
57
|
+
//rs
|
|
58
|
+
let rs = j2o(j)
|
|
59
|
+
// console.log('recover rs', rs)
|
|
60
|
+
|
|
61
|
+
//genModels
|
|
62
|
+
if (isfun(genModels)) {
|
|
63
|
+
genModels()
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
//funTest
|
|
67
|
+
await pmSeries(rs, async (v) => {
|
|
68
|
+
console.log('recover...', v.name)
|
|
69
|
+
if (needCreateStorage) {
|
|
70
|
+
console.log('needCreateStorage')
|
|
71
|
+
await woItems[v.name].createStorage()
|
|
72
|
+
}
|
|
73
|
+
// await woItems[v.name].delAll() //清空資料庫
|
|
74
|
+
let r = null
|
|
75
|
+
if (size(v.data) > 0) {
|
|
76
|
+
r = await woItems[v.name].insert(v.data) //需人工先清空資料庫, 用insert匯入比較快
|
|
77
|
+
}
|
|
78
|
+
return r
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
let getDbBackupAndRecover = {
|
|
85
|
+
backup,
|
|
86
|
+
recover,
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
export default getDbBackupAndRecover
|