Skip to content

Commit 25cc5a4

Browse files
authored
docs: update
1 parent 8331e09 commit 25cc5a4

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

README.md

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,17 @@
22

33
> Simple to use type-safe local JSON database 🦉
44
5+
Read or create `db.json`
6+
57
```js
6-
// Read or create db.json
78
const db = await JSONFilePreset('db.json', { posts: [] })
9+
```
810

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
1114
const post = { id: 1, title: 'lowdb is awesome', views: 100 }
1215
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)
2016
```
2117

2218
```js
@@ -28,6 +24,18 @@ const sortedPosts = posts.toSorted((a, b) => a.views - b.views)
2824
}
2925
```
3026

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+
3139
## Sponsors
3240

3341
<br>
@@ -49,7 +57,7 @@ const sortedPosts = posts.toSorted((a, b) => a.views - b.views)
4957
- **Lightweight**
5058
- **Minimalist**
5159
- **TypeScript**
52-
- **plain JavaScript**
60+
- **Plain JavaScript**
5361
- Safe atomic writes
5462
- Hackable:
5563
- Change storage, file format (JSON, YAML, ...) or add encryption via [adapters](#adapters)

0 commit comments

Comments
 (0)