npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@makeitrealcamp/db-mock

v1.1.0

Published

Simulates a database with one table that allows simple CRUD operations

Downloads

3

Readme

Database Mock

Simulates a database with one table that allow simple CRUD operations (Create, Read, Update, Delete).

Objects that are stored in memory and can represent anything (e.g. people, places, blog posts, invoices, movies, customers, products, etc.).

Mocks in programming are used to simulate other parts of a system. In this case we are simulating a database engine. It is not a real database engine because data is not persisted and lacks all the features that database engines offer.

Usage

First install the library:

npm install --save @makeitrealcamp/db-mock

Then require and use it in your code. For example:

// import table from "@makeitrealcamp/db-mock"
const table = require("@makeitrealcamp/db-mock")

// insert records - it returns the record with an id property
const r1 = table.insert({ name: "Pedro Perez" }) // { id: 1, name: "Pedro Perez" }
const r2 = table.insert({ name: "Maria Gomez" }) // { id: 2, name: "Maria Gomez" }

// find all records
const records = table.findAll() // returns an array with all the records

// find by id
const record = table.findById(1) // returns the record with id 1

API

This package exposes the following methods: findAll, findById, insert, update and remove.

findAll

Returns all the records that have been inserted. For example:

const records = table.findAll()

findById(id)

Receives an id and returns the record with that id. If no record exists returns null.

For example:

const record = table.find(1)

insert

Receives an object and returns a shallow copy of the object with an id property. The id is a number that starts with 1 and is incremented every time a record is inserted.

For example:

const record = table.insert({ name: "Pedro" })

update

Receives and object and replaces the record in the table. If the record doesn't have an id or the id is not found an error is raised.

This method doesn't return anything.

For example, assuming a record was already inserted, we can replace it:

table.update({ id: 1, name: "Maria" })

remove

Receives an id and deletes the record with that id.

This method doesn't return anything.

For example, if a record was already inserted, we can delete it:

table.delete(1)

TODO

We need to add some tests.