-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsketch.js
48 lines (44 loc) · 1.66 KB
/
sketch.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
async function main () {
const memento = new Memento({
directory: path.join(__dirname, 'test/tmp/sketch')
comparators: {
'custom': (left, right) => +left - +right
}
})
const presidents = memento.open('presidents', async schema => {
switch (schema.version) {
case 1:
await schema.store('presidents', { firstTerm: Number })
await schema.index('presidents', 'name', { lastName: 1, firstName 1 })
schema.set('presidents', {
firstName: 'George', lastName: 'Washington', firstTerm: 1, state: 'VA'
})
break
}
}, 1)
presidents.mutate(async mutator => {
mutator.set('employee', { firstName: 'John', lastName: 'Adams', state: 'MA' })
mutator.set('employee', { firstName: 'Thomas', lastName: 'Jefferson', state: 'VA' })
mutator.rollback()
})
presidents.mutate(async mutator => {
mutator.set('employee', { firstName: 'John', lastName: 'Adams', state: 'MA' })
mutator.set('employee', { firstName: 'Thomas', lastName: 'Jefferson', state: 'VA' })
for await (const presidents of mutator.forward([ 'presidents', 'name' ])) {
for (const president of presidents) {
if (employee.state != 'MA') {
break
}
}
}
})
presidents.snapshot(async snapshot => {
for await (const presidents of snapshot.forward([ 'presidents', 'name' ])) {
for (const president of presidents) {
if (employee.state != 'MA') {
break
}
}
}
})
}