w-orm-lowdb 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.
Files changed (53) hide show
  1. package/.editorconfig +9 -0
  2. package/.eslintignore +3 -0
  3. package/.eslintrc.js +55 -0
  4. package/.jsdoc +25 -0
  5. package/LICENSE +21 -0
  6. package/README.md +162 -0
  7. package/SECURITY.md +5 -0
  8. package/babel.config.js +15 -0
  9. package/db.json +14 -0
  10. package/dist/w-orm-lowdb.umd.js +7 -0
  11. package/dist/w-orm-lowdb.umd.js.map +1 -0
  12. package/docs/WOrmLowdb.html +1406 -0
  13. package/docs/WOrmLowdb.mjs.html +644 -0
  14. package/docs/fonts/Montserrat/Montserrat-Bold.eot +0 -0
  15. package/docs/fonts/Montserrat/Montserrat-Bold.ttf +0 -0
  16. package/docs/fonts/Montserrat/Montserrat-Bold.woff +0 -0
  17. package/docs/fonts/Montserrat/Montserrat-Bold.woff2 +0 -0
  18. package/docs/fonts/Montserrat/Montserrat-Regular.eot +0 -0
  19. package/docs/fonts/Montserrat/Montserrat-Regular.ttf +0 -0
  20. package/docs/fonts/Montserrat/Montserrat-Regular.woff +0 -0
  21. package/docs/fonts/Montserrat/Montserrat-Regular.woff2 +0 -0
  22. package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.eot +0 -0
  23. package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.svg +978 -0
  24. package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.ttf +0 -0
  25. package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.woff +0 -0
  26. package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.woff2 +0 -0
  27. package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.eot +0 -0
  28. package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.svg +1049 -0
  29. package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.ttf +0 -0
  30. package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.woff +0 -0
  31. package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.woff2 +0 -0
  32. package/docs/index.html +84 -0
  33. package/docs/scripts/collapse.js +39 -0
  34. package/docs/scripts/commonNav.js +28 -0
  35. package/docs/scripts/linenumber.js +25 -0
  36. package/docs/scripts/nav.js +12 -0
  37. package/docs/scripts/polyfill.js +4 -0
  38. package/docs/scripts/prettify/Apache-License-2.0.txt +202 -0
  39. package/docs/scripts/prettify/lang-css.js +2 -0
  40. package/docs/scripts/prettify/prettify.js +28 -0
  41. package/docs/scripts/search.js +99 -0
  42. package/docs/styles/jsdoc.css +776 -0
  43. package/docs/styles/prettify.css +80 -0
  44. package/g-basic.mjs +178 -0
  45. package/g.mjs +24 -0
  46. package/package.json +32 -0
  47. package/script.txt +18 -0
  48. package/src/WOrmLowdb.mjs +572 -0
  49. package/test/basic.test.mjs +376 -0
  50. package/toolg/addVersion.mjs +4 -0
  51. package/toolg/cleanFolder.mjs +4 -0
  52. package/toolg/gDistRollup.mjs +23 -0
  53. package/toolg/modifyReadme.mjs +4 -0
@@ -0,0 +1,80 @@
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
+ padding-bottom: 2px;
80
+ }
package/g-basic.mjs ADDED
@@ -0,0 +1,178 @@
1
+ import wo from './src/WOrmLowdb.mjs'
2
+ //import wo from './dist/w-orm-lowdb.umd.js'
3
+ // import w from 'wsemi'
4
+
5
+
6
+ // w.fsDeleteFile('./db.json')
7
+
8
+ let opt = {
9
+ url: './db.json',
10
+ db: 'worm',
11
+ cl: 'users',
12
+ }
13
+
14
+ let rs = [
15
+ {
16
+ id: 'id-peter',
17
+ name: 'peter',
18
+ value: 123,
19
+ },
20
+ {
21
+ id: 'id-rosemary',
22
+ name: 'rosemary',
23
+ value: 123.456,
24
+ },
25
+ {
26
+ id: '',
27
+ name: 'kettle',
28
+ value: 456,
29
+ },
30
+ ]
31
+
32
+ let rsm = [
33
+ {
34
+ id: 'id-peter',
35
+ name: 'peter(modify)'
36
+ },
37
+ {
38
+ id: 'id-rosemary',
39
+ name: 'rosemary(modify)'
40
+ },
41
+ {
42
+ id: '',
43
+ name: 'kettle(modify)'
44
+ },
45
+ ]
46
+
47
+ async function test() {
48
+
49
+
50
+ //w
51
+ let w = wo(opt)
52
+
53
+
54
+ //on
55
+ w.on('change', function(mode, data, res) {
56
+ console.log('change', mode)
57
+ })
58
+
59
+
60
+ //delAll
61
+ await w.delAll()
62
+ .then(function(msg) {
63
+ console.log('delAll then', msg)
64
+ })
65
+ .catch(function(msg) {
66
+ console.log('delAll catch', msg)
67
+ })
68
+
69
+
70
+ //insert
71
+ await w.insert(rs)
72
+ .then(function(msg) {
73
+ console.log('insert then', msg)
74
+ })
75
+ .catch(function(msg) {
76
+ console.log('insert catch', msg)
77
+ })
78
+
79
+
80
+ //save
81
+ await w.save(rsm, { autoInsert: false })
82
+ .then(function(msg) {
83
+ console.log('save then', msg)
84
+ })
85
+ .catch(function(msg) {
86
+ console.log('save catch', msg)
87
+ })
88
+
89
+
90
+ //select all
91
+ let ss = await w.select()
92
+ console.log('select all', ss)
93
+
94
+
95
+ //select
96
+ let so = await w.select({ id: 'id-rosemary' })
97
+ console.log('select', so)
98
+
99
+
100
+ //select by $and, $gt, $lt
101
+ let spa = await w.select({ '$and': [{ value: { '$gt': 123 } }, { value: { '$lt': 200 } }] })
102
+ console.log('select by $and, $gt, $lt', spa)
103
+
104
+
105
+ //select by $or, $gte, $lte
106
+ let spb = await w.select({ '$or': [{ value: { '$lte': -1 } }, { value: { '$gte': 200 } }] })
107
+ console.log('select by $or, $gte, $lte', spb)
108
+
109
+
110
+ //select by $or, $and, $ne, $in, $nin
111
+ let spc = await w.select({ '$or': [{ '$and': [{ value: { '$ne': 123 } }, { value: { '$in': [123, 321, 123.456, 456] } }, { value: { '$nin': [456, 654] } }] }, { '$or': [{ value: { '$lte': -1 } }, { value: { '$gte': 400 } }] }] })
112
+ console.log('select by $or, $and, $ne, $in, $nin', spc)
113
+
114
+
115
+ // //select by regex //mingo不支援regex
116
+ // let sr = await w.select({ name: { $regex: 'PeT', $options: '$i' } })
117
+ // console.log('selectReg', sr)
118
+
119
+
120
+ //del
121
+ let d = ss.filter(function(v) {
122
+ return v.name === 'kettle'
123
+ })
124
+ await w.del(d)
125
+ .then(function(msg) {
126
+ console.log('del then', msg)
127
+ })
128
+ .catch(function(msg) {
129
+ console.log('del catch', msg)
130
+ })
131
+
132
+
133
+ }
134
+ test()
135
+ // change delAll
136
+ // delAll then { n: 2, nDeleted: 2, ok: 1 }
137
+ // change insert
138
+ // insert then { n: 3, nInserted: 3, ok: 1 }
139
+ // change save
140
+ // save then [
141
+ // { n: 1, nModified: 1, ok: 1 },
142
+ // { n: 1, nModified: 1, ok: 1 },
143
+ // { n: 0, nModified: 0, ok: 1 }
144
+ // ]
145
+ // select all [
146
+ // { id: 'id-peter', name: 'peter(modify)', value: 123 },
147
+ // { id: 'id-rosemary', name: 'rosemary(modify)', value: 123.456 },
148
+ // {
149
+ // id: {random id},
150
+ // name: 'kettle',
151
+ // value: 456
152
+ // }
153
+ // ]
154
+ // select [ { id: 'id-rosemary', name: 'rosemary(modify)', value: 123.456 } ]
155
+ // select by $and, $gt, $lt [ { id: 'id-rosemary', name: 'rosemary(modify)', value: 123.456 } ]
156
+ // select by $or, $gte, $lte [
157
+ // {
158
+ // id: {random id},
159
+ // name: 'kettle',
160
+ // value: 456
161
+ // }
162
+ // ]
163
+ // select by $or, $and, $ne, $in, $nin [
164
+ // {
165
+ // id: 'id-rosemary',
166
+ // name: 'rosemary(modify)',
167
+ // value: 123.456
168
+ // },
169
+ // {
170
+ // id: {random id},
171
+ // name: 'kettle',
172
+ // value: 456
173
+ // }
174
+ // ]
175
+ // change del
176
+ // del then [ { n: 1, nDeleted: 1, ok: 1 } ]
177
+
178
+ //node --experimental-modules g-basic.mjs
package/g.mjs ADDED
@@ -0,0 +1,24 @@
1
+ import WOrmLowdb from './src/WOrmLowdb.mjs'
2
+
3
+ async function run() {
4
+ const orm = await WOrmLowdb('db.json', 'users')
5
+
6
+ // 插入資料
7
+ await orm.insert({ id: 1, name: 'Alice' })
8
+
9
+ // 查詢資料
10
+ console.log(await orm.select())
11
+
12
+ // 更新資料
13
+ await orm.save(user => user.id === 1, { name: 'Alice Updated' })
14
+
15
+ // 刪除資料
16
+ await orm.del(user => user.id === 1)
17
+
18
+ // 清空資料表
19
+ await orm.delAll()
20
+ }
21
+
22
+ run()
23
+
24
+ //node --experimental-modules g.mjs
package/package.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "w-orm-lowdb",
3
+ "version": "1.0.0",
4
+ "main": "dist/w-orm-lowdb.umd.js",
5
+ "dependencies": {
6
+ "lodash-es": "^4.17.21",
7
+ "lowdb": "^7.0.1",
8
+ "mingo": "^6.5.3",
9
+ "wsemi": "^1.7.70"
10
+ },
11
+ "devDependencies": {
12
+ "w-package-tools": "^1.0.82"
13
+ },
14
+ "scripts": {
15
+ "test": "mocha --parallel --timeout 60000 --experimental-modules",
16
+ "deploy": "gh-pages -d docs"
17
+ },
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "git+https://github.com/yuda-lyu/w-orm-lowdb.git"
21
+ },
22
+ "keywords": [
23
+ "package",
24
+ "tool",
25
+ "operator",
26
+ "lowdb",
27
+ "ORM",
28
+ "nodejs"
29
+ ],
30
+ "author": "yuda-lyu(semisphere)",
31
+ "license": "MIT"
32
+ }
package/script.txt ADDED
@@ -0,0 +1,18 @@
1
+ #node --experimental-modules toolg/addVersion.mjs
2
+ node --experimental-modules toolg/modifyReadme.mjs
3
+
4
+ node --experimental-modules toolg/cleanFolder.mjs
5
+ ./node_modules/.bin/jsdoc -c .jsdoc
6
+
7
+ node --experimental-modules toolg/gDistRollup.mjs
8
+
9
+ git add . -A
10
+ git commit -m 'modify: '
11
+ git push origin master:master
12
+
13
+ npm run deploy
14
+
15
+ #npm test
16
+
17
+ #npm publish
18
+