Skip to content

Commit 6fc49cc

Browse files
authored
Update README.md
1 parent 31458f3 commit 6fc49cc

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

README.md

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,25 @@
11
# lowdb [![](http://img.shields.io/npm/dm/lowdb.svg?style=flat)](https://www.npmjs.org/package/lowdb) [![Node.js CI](https://github.com/typicode/lowdb/actions/workflows/node.js.yml/badge.svg)](https://github.com/typicode/lowdb/actions/workflows/node.js.yml)
22

33
> Simple to use type-safe local JSON database 🦉
4+
>
5+
> If you know JavaScript, you know how to use lowdb.
46
57
Read or create `db.json`
68

79
```js
810
const db = await JSONFilePreset('db.json', { posts: [] })
911
```
1012

11-
Update data using `Array.prototype.*` and automatically write to `db.json`
13+
Use plain JavaScript to change data
1214

1315
```js
1416
const post = { id: 1, title: 'lowdb is awesome', views: 100 }
17+
18+
// In two steps
19+
db.data.posts.push(post)
20+
await db.write()
21+
22+
// Or in one
1523
await db.update(({ posts }) => posts.push(post))
1624
```
1725

@@ -24,17 +32,18 @@ await db.update(({ posts }) => posts.push(post))
2432
}
2533
```
2634

27-
In the same spirit, query using native `Array.prototype.*`
35+
In the same spirit, query using native `Array` functions:
2836

2937
```js
3038
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)
39+
40+
posts.at(0) // First post
41+
posts.filter((post) => post.title.includes('lowdb')) // Filter by title
42+
posts.find((post) => post.id === 1) // Find by id
43+
posts.toSorted((a, b) => a.views - b.views) // Sort by views
3544
```
3645

37-
It's that simple.
46+
It's that simple. `db.data` is just a JavaScript object, no magic.
3847

3948
## Sponsors
4049

0 commit comments

Comments
 (0)