-
Notifications
You must be signed in to change notification settings - Fork 1
/
lazy.ts
29 lines (22 loc) · 1.1 KB
/
lazy.ts
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
/**
* Run example:
* deno run --allow-read=. --allow-write=. https://raw.githubusercontent.com/felixblaschke/storeosaurus/master/examples/lazy.ts
*/
import {Store} from '../mod.ts';
interface Diary {
entries: string[]
}
const diary = Store.open<Diary>({
name: 'diary',
encrypt: 'secret-phrase',
lazyWrite: true, // <-- add lazy write mode
default: {entries: []}
});
const lorem = () => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam diam orci, ornare in auctor placerat, tincidunt porta est. Sed a justo accumsan, tempor nunc et, vulputate ligula. Maecenas nec egestas nunc. Suspendisse molestie erat nibh, eu fringilla ex finibus ac. Phasellus vulputate ac sapien non accumsan. Vivamus sollicitudin, nulla non gravida interdum, arcu arcu sodales risus, non tincidunt odio elit id felis. Fusce ac lacus eu urna bibendum sodales vitae auctor mi.';
for (let i = 0; i < 100; i++) {
const data = diary.get();
data.entries.push(lorem());
diary.set(data);
}
console.log(`Diary now has ${diary.get().entries.length} entries`);
diary.sync(); // <-- sync store to disk