2
2
3
3
> Simple to use type-safe local JSON database 🦉
4
4
5
+ Read or create ` db.json `
6
+
5
7
``` js
6
- // Read or create db.json
7
8
const db = await JSONFilePreset (' db.json' , { posts: [] })
9
+ ```
8
10
9
- // Update data using Array.prototype.push
10
- // and automatically write to db.json
11
+ Update data using ` Array.prototype.* ` and automatically write to ` db.json `
12
+
13
+ ``` js
11
14
const post = { id: 1 , title: ' lowdb is awesome' , views: 100 }
12
15
await db .update (({ posts }) => posts .push (post))
13
-
14
- // Query using Array.prototype.*
15
- const { posts } = db .data
16
- const first = posts .at (0 )
17
- const results = posts .filter ((post ) => post .title .includes (' lowdb' ))
18
- const post1 = posts .find ((post ) => post .id === 1 )
19
- const sortedPosts = posts .toSorted ((a , b ) => a .views - b .views )
20
16
```
21
17
22
18
``` js
@@ -28,6 +24,18 @@ const sortedPosts = posts.toSorted((a, b) => a.views - b.views)
28
24
}
29
25
```
30
26
27
+ In the same spirit, query using native ` Array.prototype.* `
28
+
29
+ ``` js
30
+ const { posts } = db .data
31
+ const first = posts .at (0 )
32
+ const results = posts .filter ((post ) => post .title .includes (' lowdb' ))
33
+ const post1 = posts .find ((post ) => post .id === 1 )
34
+ const sortedPosts = posts .toSorted ((a , b ) => a .views - b .views )
35
+ ```
36
+
37
+ It's that simple.
38
+
31
39
## Sponsors
32
40
33
41
<br >
@@ -49,7 +57,7 @@ const sortedPosts = posts.toSorted((a, b) => a.views - b.views)
49
57
- ** Lightweight**
50
58
- ** Minimalist**
51
59
- ** TypeScript**
52
- - ** plain JavaScript**
60
+ - ** Plain JavaScript**
53
61
- Safe atomic writes
54
62
- Hackable:
55
63
- Change storage, file format (JSON, YAML, ...) or add encryption via [ adapters] ( #adapters )
0 commit comments