Skip to content

Commit

Permalink
feat!: update mongodb driver to the latest version which has breaking…
Browse files Browse the repository at this point in the history
… change

BREAKING CHANGE: move mongodb to peer dependencies
  • Loading branch information
playerx committed Jun 13, 2020
1 parent 7da5fc3 commit a31112d
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# jok-mango [![CircleCI](https://circleci.com/gh/jokio/jok-mango.svg?style=svg)](https://circleci.com/gh/jokio/jok-mango)

Simplified way to work with MongoDB

[![platform: jokio](https://img.shields.io/badge/platform-%F0%9F%83%8F%20jok-44cc11.svg)](https://github.com/jokio/jok-cli)
Expand All @@ -7,9 +8,9 @@ Simplified way to work with MongoDB

<br/>


## Features
✅ Stores `_id: ObjectId` field, but wraps it to the `id: string`

✅ Stores `_id: ObjectId` field, but wraps it to the `id: string`

✅ Documents have `version: number` out of the box, and its increased by `1` every time you call update

Expand All @@ -18,9 +19,11 @@ Simplified way to work with MongoDB
✅ Soft Delete & Hard Delete ability for documents

<br/>

<br/>

## How to use

1. Declare data structure

```ts
Expand All @@ -34,6 +37,7 @@ export interface User extends DocumentBase {
```

2. Create repository object for declared type

```ts
import { getRepository } from 'jok-mango'

Expand All @@ -47,15 +51,14 @@ const db = client.db()
const users = getRepository<User>(db, 'users')
```


3. Use repository object

```ts
const user = await users.create({
email: 'test@jok.io',
passwordHash: 'strong-hash',
})


const { id, version } = user

const updatedUser = await users.update(
Expand All @@ -66,7 +69,6 @@ const updatedUser = await users.update(
)
```


## Performance Cost

Library calls `_id.toHexString()` for all retrieved items to have `id: string` and make developers life easier, so logical quetion is: How expensive operation is it.
Expand All @@ -75,8 +77,8 @@ _Hardware:
MacBook Pro (Retina, 15-inch, Mid 2014)
Processor: 2.2 GHz Intel Core i7_

| Number of Operations | Duration |
|---------------------: |---------------- |
| 1 | ~20 μs |
| 1 000 | ~829 μs |
| 1 000 000 | ~250 ms |
| Number of Operations | Duration |
| -------------------: | -------- |
| 1 | ~20 μs |
| 1 000 | ~829 μs |
| 1 000 000 | ~250 ms |

0 comments on commit a31112d

Please sign in to comment.