w-orm-lowdb 1.0.0 → 1.0.2

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.
@@ -1,5 +1,6 @@
1
1
  import assert from 'assert'
2
- import wo from '../src/WOrmLowdb.mjs'
2
+ import WOrm from '../src/WOrmLowdb.mjs'
3
+ import w from 'wsemi'
3
4
 
4
5
 
5
6
  function isWindows() {
@@ -13,9 +14,9 @@ if (isWindows()) {
13
14
  let vans = {}
14
15
  let vget = {}
15
16
 
16
-
17
17
  before(async function () {
18
18
 
19
+ w.fsDeleteFile('./db.json')
19
20
 
20
21
  let opt = {
21
22
  url: './db.json',
@@ -23,7 +24,6 @@ if (isWindows()) {
23
24
  cl: 'users',
24
25
  }
25
26
 
26
-
27
27
  let rs = [
28
28
  {
29
29
  id: 'id-peter',
@@ -42,7 +42,6 @@ if (isWindows()) {
42
42
  },
43
43
  ]
44
44
 
45
-
46
45
  let rsm = [
47
46
  {
48
47
  id: 'id-peter',
@@ -58,24 +57,21 @@ if (isWindows()) {
58
57
  },
59
58
  ]
60
59
 
61
-
62
- //w
63
- let w = wo(opt)
64
-
60
+ //wo
61
+ let wo = WOrm(opt)
65
62
 
66
63
  //on
67
- w.on('change', function(mode, data, res) {
64
+ wo.on('change', function(mode, data, res) {
68
65
  // console.log('change', mode)
69
66
  })
70
67
 
71
-
72
68
  //delAll
73
69
  rt = null
74
70
  vans[1] = {
75
- nDeleted: 2,
71
+ nDeleted: 0,
76
72
  ok: 1,
77
73
  }
78
- await w.delAll()
74
+ await wo.delAll()
79
75
  .then(function(msg) {
80
76
  // console.log('delAll then', msg)
81
77
  //考慮可能有不同初始測試數據
@@ -93,11 +89,10 @@ if (isWindows()) {
93
89
  })
94
90
  vget[1] = rt
95
91
 
96
-
97
92
  //insert
98
93
  rt = null
99
94
  vans[2] = { n: 3, nInserted: 3, ok: 1 }
100
- await w.insert(rs)
95
+ await wo.insert(rs)
101
96
  .then(function(msg) {
102
97
  // console.log('insert then', msg)
103
98
  // insert then { n: 3, nInserted: 3, ok: 1 }
@@ -109,7 +104,6 @@ if (isWindows()) {
109
104
  })
110
105
  vget[2] = rt
111
106
 
112
-
113
107
  //save
114
108
  rt = null
115
109
  vans[3] = [
@@ -117,7 +111,7 @@ if (isWindows()) {
117
111
  { n: 1, nModified: 1, ok: 1 },
118
112
  { n: 0, nModified: 0, ok: 1 }
119
113
  ]
120
- await w.save(rsm, { autoInsert: false })
114
+ await wo.save(rsm, { autoInsert: false })
121
115
  .then(function(msg) {
122
116
  // console.log('save then', msg)
123
117
  // save then [
@@ -133,7 +127,6 @@ if (isWindows()) {
133
127
  })
134
128
  vget[3] = rt
135
129
 
136
-
137
130
  //select all
138
131
  rt = null
139
132
  vans[4] = [
@@ -145,7 +138,7 @@ if (isWindows()) {
145
138
  value: 456
146
139
  }
147
140
  ]
148
- await w.select()
141
+ await wo.select()
149
142
  .then(function(msg) {
150
143
  // console.log('select all then', msg)
151
144
  // select all [
@@ -172,11 +165,10 @@ if (isWindows()) {
172
165
  })
173
166
  vget[4] = rt
174
167
 
175
-
176
168
  //select
177
169
  rt = null
178
170
  vans[5] = [{ id: 'id-rosemary', name: 'rosemary(modify)', value: 123.456 }]
179
- await w.select({ id: 'id-rosemary' })
171
+ await wo.select({ id: 'id-rosemary' })
180
172
  .then(function(msg) {
181
173
  // console.log('select then', msg)
182
174
  // select [ { id: 'id-rosemary', name: 'rosemary(modify)', value: 123.456 } ]
@@ -188,11 +180,10 @@ if (isWindows()) {
188
180
  })
189
181
  vget[5] = rt
190
182
 
191
-
192
183
  //select by $and, $gt, $lt
193
184
  rt = null
194
185
  vans[6] = [{ id: 'id-rosemary', name: 'rosemary(modify)', value: 123.456 }]
195
- await w.select({ '$and': [{ value: { '$gt': 123 } }, { value: { '$lt': 200 } }] })
186
+ await wo.select({ '$and': [{ value: { '$gt': 123 } }, { value: { '$lt': 200 } }] })
196
187
  .then(function(msg) {
197
188
  // console.log('select by $and, $gt, $lt then', msg)
198
189
  // select by $and, $gt, $lt [ { id: 'id-rosemary', name: 'rosemary(modify)', value: 123.456 } ]
@@ -204,7 +195,6 @@ if (isWindows()) {
204
195
  })
205
196
  vget[6] = rt
206
197
 
207
-
208
198
  //select by $or, $gte, $lte
209
199
  rt = null
210
200
  vans[7] = [
@@ -214,7 +204,7 @@ if (isWindows()) {
214
204
  value: 456
215
205
  }
216
206
  ]
217
- await w.select({ '$or': [{ value: { '$lte': -1 } }, { value: { '$gte': 200 } }] })
207
+ await wo.select({ '$or': [{ value: { '$lte': -1 } }, { value: { '$gte': 200 } }] })
218
208
  .then(function(msg) {
219
209
  // console.log('select by $or, $gte, $lte then', msg)
220
210
  // select by $or, $gte, $lte [
@@ -237,7 +227,6 @@ if (isWindows()) {
237
227
  })
238
228
  vget[7] = rt
239
229
 
240
-
241
230
  //select by $or, $and, $ne, $in, $nin
242
231
  rt = null
243
232
  vans[8] = [
@@ -252,7 +241,7 @@ if (isWindows()) {
252
241
  value: 456
253
242
  }
254
243
  ]
255
- 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 } }] }] })
244
+ await wo.select({ '$or': [{ '$and': [{ value: { '$ne': 123 } }, { value: { '$in': [123, 321, 123.456, 456] } }, { value: { '$nin': [456, 654] } }] }, { '$or': [{ value: { '$lte': -1 } }, { value: { '$gte': 400 } }] }] })
256
245
  .then(function(msg) {
257
246
  // console.log('select by $or, $and, $ne, $in, $nin then', msg)
258
247
  // select by $or, $and, $ne, $in, $nin [
@@ -281,11 +270,10 @@ if (isWindows()) {
281
270
  })
282
271
  vget[8] = rt
283
272
 
284
-
285
273
  // //select by regex
286
274
  // rt = null
287
275
  // vans[9] = [{ id: 'id-peter', name: 'peter(modify)', value: 123 }]
288
- // await w.select({ name: { $regex: 'PeT', $options: '$i' } })
276
+ // await wo.select({ name: { $regex: 'PeT', $options: '$i' } })
289
277
  // .then(function(msg) {
290
278
  // // console.log('select by regex then', msg)
291
279
  // // selectReg [ { id: 'id-peter', name: 'peter(modify)', value: 123 } ]
@@ -297,15 +285,14 @@ if (isWindows()) {
297
285
  // })
298
286
  // vget[9] = rt
299
287
 
300
-
301
288
  //del
302
289
  rt = null
303
290
  vans[10] = [{ n: 1, nDeleted: 1, ok: 1 }]
304
- let ss = await w.select()
291
+ let ss = await wo.select()
305
292
  let d = ss.filter(function(v) {
306
293
  return v.name === 'kettle'
307
294
  })
308
- await w.del(d)
295
+ await wo.del(d)
309
296
  .then(function(msg) {
310
297
  // console.log('del then', msg)
311
298
  // del then [ { n: 1, nDeleted: 1, ok: 1 } ]
@@ -317,60 +304,48 @@ if (isWindows()) {
317
304
  })
318
305
  vget[10] = rt
319
306
 
320
-
321
307
  })
322
308
 
323
-
324
309
  it(`should get ${JSON.stringify(vans[1])} for delAll`, async function() {
325
310
  assert.strict.deepStrictEqual(vget[1], vans[1])
326
311
  })
327
312
 
328
-
329
313
  it(`should get ${JSON.stringify(vans[2])} for insert`, async function() {
330
314
  assert.strict.deepStrictEqual(vget[2], vans[2])
331
315
  })
332
316
 
333
-
334
317
  it(`should get ${JSON.stringify(vans[3])} for save`, async function() {
335
318
  assert.strict.deepStrictEqual(vget[3], vans[3])
336
319
  })
337
320
 
338
-
339
321
  it(`should get ${JSON.stringify(vans[4])} for select all`, async function() {
340
322
  assert.strict.deepStrictEqual(vget[4], vans[4])
341
323
  })
342
324
 
343
-
344
325
  it(`should get ${JSON.stringify(vans[5])} for select`, async function() {
345
326
  assert.strict.deepStrictEqual(vget[5], vans[5])
346
327
  })
347
328
 
348
-
349
329
  it(`should get ${JSON.stringify(vans[6])} for select by $and, $gt, $lt`, async function() {
350
330
  assert.strict.deepStrictEqual(vget[6], vans[6])
351
331
  })
352
332
 
353
-
354
333
  it(`should get ${JSON.stringify(vans[7])} for select by $or, $gte, $lte`, async function() {
355
334
  assert.strict.deepStrictEqual(vget[7], vans[7])
356
335
  })
357
336
 
358
-
359
337
  it(`should get ${JSON.stringify(vans[8])} for select by $or, $and, $ne, $in, $nin`, async function() {
360
338
  assert.strict.deepStrictEqual(vget[8], vans[8])
361
339
  })
362
340
 
363
-
364
341
  // it(`should get ${JSON.stringify(vans[9])} for select by regex`, async function() {
365
342
  // assert.strict.deepStrictEqual(vget[9], vans[9])
366
343
  // })
367
344
 
368
-
369
345
  it(`should get ${JSON.stringify(vans[10])} for del`, async function() {
370
346
  assert.strict.deepStrictEqual(vget[10], vans[10])
371
347
  })
372
348
 
373
-
374
349
  })
375
350
  }
376
351
 
@@ -13,10 +13,12 @@ rollupFiles({
13
13
  nameDistType: 'kebabCase',
14
14
  globals: {
15
15
  'events': 'events',
16
+ 'lowdb': 'lowdb',
16
17
  'mingo': 'mingo',
17
18
  },
18
19
  external: [
19
20
  'events',
21
+ 'lowdb',
20
22
  'mingo',
21
23
  ],
22
24
  })
package/db.json DELETED
@@ -1,14 +0,0 @@
1
- {
2
- "worm:users": [
3
- {
4
- "id": "id-peter",
5
- "name": "peter(modify)",
6
- "value": 123
7
- },
8
- {
9
- "id": "id-rosemary",
10
- "name": "rosemary(modify)",
11
- "value": 123.456
12
- }
13
- ]
14
- }
package/g.mjs DELETED
@@ -1,24 +0,0 @@
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