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

db-mock

v0.0.9

Published

DB mock

Downloads

21

Readme

db-mock

What's better in this life than having a database mocking, for our api-mocking! db-mock, is an engine that is perfect for simulating a database, with a very simple setup, you can have a db-like and an api-mocks in matter of minutes. If you mock you api using Node and Express, db-mock will make your life 10x easier!

Features

  • handy data types (string, number, bool, date, array, object)
  • data type constraints (required, min, max)
  • one-to-one and one-to-many relations ($has, and $hasMany)S
  • injecting related resources optionally
  • handy resource apis (add, get, update, delete, list and query)
  • validations are everywhere to help you spot any conflicts (validating schema, and operations)
  • configurations for almost everything
  • colorful and informative logging
  • It can run in three different modes
    • as a node module, using: require('db-mock')
    • as a standalone module that communicates on sockets (still under development)
    • as a web-console that makes you manage everything visually, edit schema and browse the data (still under development)

Install

npm install db-mock --save-dev

Examples

Seed data

./node_modules/.bin/db-mock seed

Clean data

./node_modules/.bin/db-mock clean

Schema example

// profile.json
{
  "address": "string",
  "phone": "string"
}
// course.json
{
  "name": "string",
  "description": "string",
  "$has": {
    "many": [{
      "relationWith": "student",
      "inject": true
    }]
  }
}
// student.json
{
  "name": {
    "type": "string",
    "required": true
  },
  "age": {
    "type": "number",
    "min": 0,
    "max": 100
  },
  "dateOfBirth": "date",
  "married": "bool",
  "sons": {
    "type": "array",
    "required": true
  },
  "$has": {
    "one": [{
      "relationWith": "profile",
      "required": true,
      "inject": true
    }],
    "many": [
      "course"
    ]
  }
}

Seed example

// seed.js
var _ = require('lodash');

module.exports = function(db) {
  _.times(10, (i) => {
    let studentProfile = db.profile.add({
      address: 'address ' + i
    });

    db.student.add({
      name: 'student name ' + i,
      dateOfBirth: new Date(),
      profile_ID: studentProfile.ID
    });
  });
}

Getting started

If you know NodeJS and Express, then let's do few steps and have our api-mocks running just like real ones. I've created sample application for you to check and follow Here it is!

Data types

  • string
  • date
  • number
  • bool
  • array
  • object

Configurations

All optional! Create .dbmockrc on the root to configure any option.

Option | Default | Description ------------------------- | ------------------ | --------------------- socketsPort | 6789 | The port of engine when it runs in sockets mode webConsolePort | 6790 | The port of the web-console data | 'db-mock/data/' | The directory of data (should be git ignored) schema | 'db-mock/schema/' | Directory of the schema seed | 'db-mock/seed.js' | File location of seed script IDProperty | 'ID' | ID property foreignIDSuffix | '_ID' | How should foreign IDs be. (classID, classId, class_id, or classID) enableCreatedAtProperty | true | Auto insert 'created at' field createdAtProperty | '_createdAt' | Name of 'created at' property if enabled enableUpdatedAtProperty | true | Auto insert 'updated at' field updatedAtProperty | '_updatedAt' | Name of 'updated at' property injectResourceName | true | Whether to inject the resource name at retrieval, (student resource will has '$name'='student' property) resourceNameProperty | '_name' | resource name property

Sample

{
  "data": "db-mock-data/data/",
  "schema": "db-mock-data/schema/",
  "seed": "db-mock-data/seed.js",
  "foreignIDSuffix": "ID"
}

License

MIT