jok-mango
Simplified way to work with MongoDB
Last updated 12 days ago by ezeki .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install jok-mango 
SYNC missed versions from official npm registry.

jok-mango CircleCI

Simplified way to work with MongoDB

platform: jokio npm version codecov


Features

✅ 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

✅ Every document has createdAt and updatedAt props

✅ Soft Delete & Hard Delete ability for documents



How to use

  1. Declare data structure
import { DocumentBase } from 'jok-mango'

export interface User extends DocumentBase {
	email: string
	passwordHash: string
	fullname?: string
}
  1. Create repository object for declared type
import { getRepository } from 'jok-mango'

const connectionString = `mongodb://mongo:mongo@localhost:27017/test?authSource=admin`
const client = new MongoClient(connectionString, { useNewUrlParser: true })

await client.connect()

const db = client.db()

const users = getRepository<User>(db, 'users')
  1. Use repository object
const user = await users.create({
	email: 'test@jok.io',
	passwordHash: 'strong-hash',
})


const { id, version } = user

const updatedUser = await users.update(
	{ id, version },
	{
		email: 'tester@jok.io',
	},
)

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.

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

Current Tags

  • 1.13.0                                ...           latest (12 days ago)

30 Versions

  • 1.13.0                                ...           12 days ago
  • 1.12.3                                ...           15 days ago
  • 1.12.2                                ...           a month ago
  • 1.12.1                                ...           a month ago
  • 1.12.0                                ...           4 months ago
  • 1.11.1                                ...           6 months ago
  • 1.11.0                                ...           6 months ago
  • 1.10.0                                ...           6 months ago
  • 1.9.2                                ...           6 months ago
  • 1.8.0                                ...           7 months ago
  • 1.7.3                                ...           9 months ago
  • 1.7.2                                ...           9 months ago
  • 1.7.1                                ...           9 months ago
  • 1.7.0                                ...           9 months ago
  • 1.6.0                                ...           a year ago
  • 1.5.6                                ...           a year ago
  • 1.5.5                                ...           a year ago
  • 1.5.4                                ...           a year ago
  • 1.5.3                                ...           a year ago
  • 1.5.2                                ...           a year ago
  • 1.5.1                                ...           a year ago
  • 1.5.0                                ...           a year ago
  • 1.4.0                                ...           a year ago
  • 1.3.0                                ...           a year ago
  • 1.2.0                                ...           a year ago
  • 1.1.1                                ...           a year ago
  • 1.1.0                                ...           a year ago
  • 1.0.2                                ...           a year ago
  • 1.0.1                                ...           a year ago
  • 1.0.0                                ...           a year ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 31
Last Day 0
Last Week 0
Last Month 49
Dependencies (2)
Dev Dependencies (10)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |