@wilfredlopez/fake-db
TypeScript icon, indicating that this package has built-in type declarations

2.0.0 • Public • Published

FakeDb

import FakeDb from '@wilfredlopez/fake-db'

interface User {
  _id: string
  firstname: string
  lastname: string
  email: string
  password: string
}
const userDb = new FakeDb<User>('users.json')

export default userDb

Create

import userDb from './userdb'

const user = userDb.create({
  _id: '',
  email: 'email',
  firstname: 'name',
  lastname: 'last',
  password: 'pass',
})
userDb.save()
console.log(user)

Find

import userDb from './userdb'
userDb.findById('1')
userDb.findOne({ email: 'useremail' }) // returns the first element that match or null.
const usersCalledName = userDb.find({ firstname: 'name' }) // returns an array with all elements that match.

UPDATE

import userDb from './userdb'
const user1 = userDb.findById('1')
user1.firstname = 'other'

userDb.updateOne(user1)

MORE

import userDb from './userdb'

userDb.getAll() // returns an array with all the values.
userDb.clearDatabase() // clears json file
const nameOfF1 = userDb.filter(u => u.firstname === 'f1') // returns an array of all elements that match the filter function.

Readme

Keywords

none

Package Sidebar

Install

npm i @wilfredlopez/fake-db

Weekly Downloads

0

Version

2.0.0

License

MIT

Unpacked Size

35 kB

Total Files

8

Last publish

Collaborators

  • wilfredlopez