forked from typicode/lowdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoperations.js
54 lines (41 loc) · 998 Bytes
/
operations.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
const test = require('tape')
const low = require('../src/index.node')
test('operations', t => {
const db = low()
// Defaults
db.defaults({
foo: []
}).value()
// Create
db.get('foo').push({ a: 1 }).value()
t.equal(db.get('foo').size().value(), 1)
t.same(db.getState(), { foo: [{ a: 1 }]})
// Read
t.same(db.get('foo').find({ a: 1 }).value(), { a: 1 })
t.same(db.get('foo').find({ b: 2 }).value(), undefined)
// Update
db.get('foo')
.find({ a: 1 })
.assign({ a: 2 })
.value()
t.true(
!db.get('foo')
.find({ a: 2 })
.isUndefined()
.value()
)
// Delete
db.get('foo').remove({ a: 2 }).value()
t.true(db.get('foo').isEmpty())
t.end()
})
test('Issue #89', t => {
const db = low()
db.defaults({
foo: []
}).value()
db.get('foo').push({ id: 1, value: 1}).value()
t.equal(db.get('foo').find({ id: 1 }).value().value, 1)
t.deepEqual(db.get('foo').find({ id: 1 }).value(), { id: 1, value: 1})
t.end()
})