Skip to content

Commit

Permalink
docs: update
Browse files Browse the repository at this point in the history
  • Loading branch information
typicode authored Dec 26, 2023
1 parent 8331e09 commit 25cc5a4
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,17 @@

> Simple to use type-safe local JSON database 🦉
Read or create `db.json`

```js
// Read or create db.json
const db = await JSONFilePreset('db.json', { posts: [] })
```

// Update data using Array.prototype.push
// and automatically write to db.json
Update data using `Array.prototype.*` and automatically write to `db.json`

```js
const post = { id: 1, title: 'lowdb is awesome', views: 100 }
await db.update(({ posts }) => posts.push(post))

// Query using Array.prototype.*
const { posts } = db.data
const first = posts.at(0)
const results = posts.filter((post) => post.title.includes('lowdb'))
const post1 = posts.find((post) => post.id === 1)
const sortedPosts = posts.toSorted((a, b) => a.views - b.views)
```

```js
Expand All @@ -28,6 +24,18 @@ const sortedPosts = posts.toSorted((a, b) => a.views - b.views)
}
```

In the same spirit, query using native `Array.prototype.*`

```js
const { posts } = db.data
const first = posts.at(0)
const results = posts.filter((post) => post.title.includes('lowdb'))
const post1 = posts.find((post) => post.id === 1)
const sortedPosts = posts.toSorted((a, b) => a.views - b.views)
```

It's that simple.

## Sponsors

<br>
Expand All @@ -49,7 +57,7 @@ const sortedPosts = posts.toSorted((a, b) => a.views - b.views)
- **Lightweight**
- **Minimalist**
- **TypeScript**
- **plain JavaScript**
- **Plain JavaScript**
- Safe atomic writes
- Hackable:
- Change storage, file format (JSON, YAML, ...) or add encryption via [adapters](#adapters)
Expand Down

0 comments on commit 25cc5a4

Please sign in to comment.