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 🙏

© 2025 – Pkg Stats / Ryan Hefner

mohican

v0.3.0

Published

General database managment interface

Downloads

23

Readme

Mohican

NPM Version NPM Downloads

Generalized database managment interface.

This is a collection of independent database managment systems, united by common interface, so it almost does not matter whether you use mongodb, mysql or postgresql.

Example

To use Mohican you must connect to existing database server:

// Connect to database
mohican.connect(
  url, //  string, database url, you are going to use
       //  'mongodb://...', 'mysql://...' etc.
  callback // function, err => {...}
);

And then do anything you need:

mc.open('someDatabase', (err, db) => {
  if (err) {
    console.error(err);
    return;
  }

  // Create something
  db.create(
    entry, // object
    callback // function, (err, entryId) => {...}
  );

  // Update something
  db.update(
   entry, // object, update parameters
   callback // function, err => {...}
  );

  // Delete something
  db.delete(
   id, // object, { id, category }
   callback // function, err => {...}
  );

  const cursor = db.select({
    /*
   Search mask
   */
  });

  cursor
   .clone()
   .map(fn1)
   .project(fn3)
   .fetch((err, data) => {...});
  });

Features

MySQL provider for Mohican has some additional functionality. It is easy now to create complex SQL queries.

Create table

Now you just need to specify options for each field(column) using object syntax. For example, this SQL query

CREATE TABLE IF NOT EXISTS table (id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(255), born DATETIME, foreignId INT, FOREIGN KEY(foreignId) REFERENCES anotherTable(id))

Will look like this:

const scheme = {
  // id could be skipped, this is default id meta info
  // RECOMENDED: don`t use 'AUTO_INCREMENT' option for it
  id: { type: 'INT', options: ['PRIMARY KEY'] },

  // specify type like string
  name: 'VARCHAR(255)',
  born: 'DATETIME',

  // or if you need more complex definition, use object definition
  foreignId: { type: 'INT', reference: 'anotherTable.id' },

  // create if not exists
  safe: true
};

mc.createTable(scheme, err => {
  if (err) {
    console.error(err);
  }
});

Nested selection

Nested selection in SQL:

SELECT * FROM someTable WHERE someField = (SELECT field FROM anotherTable WHERE id = 12345);

Using Mohican it will look like:

const somefieldCursor = mc
  .select({
    id: 12345,
    category: 'anotherTable'
  })
  .project('field');

mc
  .select({
    someField: somefieldCursor,
    category: 'someTable'
  })
  .fetch(/* err, data - callback */);

JOIN

You can also easy implement multiple JOIN operations. So this:

SELECT table.field, anotherTable.anotherField FROM table JOIN anotherTable ON table.id = anotherTable.id WHERE table.id > 10

Could be written like this:

mc
  .select({
    'table.id': { $gt: 10 },
    category: 'table'
  })
  .join({
    on: 'table.id = anotherTable.id',
    category: 'anotherTable'
  })
  .project(['table.field', 'anotherTable.anotherField'])
  .fetch(/* err, data - callback */);

See documentation for more info