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 🙏

© 2026 – Pkg Stats / Ryan Hefner

modelite

v1.5.4

Published

Model for MySQL and MongoDB

Readme

Modelite

Model for MySQL and MongoDB

Engines

Usage

Options (Object):

  • engine (required, Set(MongoDB))
  • credentials (required, Object)

Credentials (Object):

  • user (optional, String)
  • password (optional, String)
  • database (optional, String)
  • protocol (optional, String, default mongodb for MongoDB)
  • host (optional, String, default localhost)
const Modelite = require('modelite')({
  engine: 'MongoDB',
  credentials: {
    user: process.env.DB_USER,
    password: process.env.DB_PASSWORD,
    database: process.env.DB_DATABASE,
    protocol: process.env.DB_PROTOCOL,
    host: process.env.DB_HOST,
  },
});

Legend

Model

A Model is an instance of Class modelite.

You can pass the following options (as an Object):

  • name (required, String)
  • fields (required, ModelFields)
  • table (optional, String, fallback name)

Example:

const ModelDB = require('modelite')({
  engine: 'MongoDB',
  credentials: {
    user: process.env.DB_USER,
    password: process.env.DB_PASSWORD,
    database: process.env.DB_DATABASE,
    protocol: process.env.DB_PROTOCOL,
    host: process.env.DB_HOST,
  },
});

const Model = new ModelDB({
  name: 'users',
  fields: {
    schema: {
      name: {
        type: String,
      },
      entity: {
        type: Array,
      },
    },
  },
});

Parameters

An object that filters Entitys.

Follows design on Mongoose Query Filters.

Example:

cosnt entity = users.get({
  id: '5cdc267dd56b5662b7b7cc0c',
  age: { $gt: '50' }
});

Entity

An Entity is a single item of a Model.

Example:

const ModelDB = require('./model');

const users = new ModelDB({
  name: 'users',
  fields: {
    schema: {
      name: {
        type: String,
      },
      entity: {
        type: Array,
      },
    },
  },
});

cosnt entity = users.get();

Field

An object that specifies the type of the Model's field.

A field can contain:

  • type (required, Type)
  • required (optional, Boolean, default false)
  • hidden (optional, Boolean, default false)

Example:

const field = {
    type: String,
    required: true,
};
const polygon = {
    type: 'Polygon',
};

ModelFields

An object that contains the fields of the Model.

Can contain:

  • schema (required, Object[Field])
  • view (optional, Object[Field], fallback schema)
  • add (optional, Object[Field])
  • edit (optional, Object[Field])

Example:

const modelFields = {
    schema: {
        name: {
            type: String,
        },
        entity: {
            type: Array,
        },
    },
    view: {
        name: {
            type: String,
        },
        entity: {
            type: Array,
        },
    },
};

Control

An object that specifies the type of the Model's control.

A control can contain:

  • type (required, Set(submit,button))
  • method (optional, Set(GET,POST,PUT,DELETE))
  • action (optional, String)
  • hidden (optional, Boolean, default false)

Example:

const control = {
    type: 'submit',
    method: 'POST',
    action: '/profile/photos',
};

ModelControls

An object that contains the controls of the Model.

Can contain:

  • many (optional, Object[Control])
  • rowControls (optional, Object[Control])

Example:

const modelControls = {
    many: {
        new: {
            action: '/create',
        },
    },
    rowControls: {
        edit: {
            action: '/:id/',
        },
        delete: {
            method: 'DELETE',
            action: '/:id/',
        },
    },
};

You can pass parameters in a action of rowControls that will be replaced afterwards (:id will be replaced with row's id, for example)

ModelFilters

An object that contains many Field to be displayed like filters on model page.

Example:

const modelFilters = {
    query: {
        type: String,
    },
};

Default filters for a model is the above example.

MongoDB

create(Entity item)

Creates a single item

Returns id

createMultiple(Array[Entity] items)

Creates multiple items

Returns Array[id]

createAndUpdateMultiple(Array[Entity] items, String field)

Creates multiple items while updating overwriting the existing ones. Optionally you can pass field to compare (fallback is id). For example if you want to update entities on field referenceID, instead of id.

Returns Array[id]

getFields()

Returns ModelFields

getFilters()

Returns ModelFilters

getControls()

Returns ModelControls

get(Parameters params, String fieldsToGet)

Returns an Entity

fieldsToGet is an optional parameter and contains an array with fields.

Example:

fieldsToGet = ['name', 'email', 'date'];

getMany(Parameters params, String fieldsToGet, Object options)

Options can contain:

  • limit Number
  • page Number
  • sortBy Object

fieldsToGet is an optional parameter and contains a string with fields separated by commas.

Example:

fieldsToGet = 'name, email, date';

sortBy is an key-value object with fields to order. Example:

sortBy: {
  arg: 'asc',
  arg2: 'desc'
}

Returns Array[Entity]

count(Parameters params)

Counts documents of model to display for pagination

Returns Number

edit(Parameters params, Object fieldsToEdit)

Edits a single Entity

Returns Promise

editMany(Parameters params, Object fieldsToEdit)

Edits multiple Entities

Returns Promise

delete(Parameters params)

Deletes a single Entity

Returns Promise

deleteMany(Parameters params)

Deletes multiple Entities

Returns Promise