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

multiprocess-database

v1.2.0

Published

Multiprocess safe JSON database with conflict detection.

Downloads

2

Readme

multiprocess-database

Multiprocess safe JSON database with conflict detection.

Upgrade over UND with a cleaner API, written with import/export in mind.

Dictionary of Terms

  • Database
    • Stores Objects
    • Examples: Mongo, Maria, MySQL
  • Object
    • Entry in Database
    • Examples: UserAlice, Row, Document
  • Property
    • Property of Object
    • Examples: userEmail, Object Property, SQL Field, Excell Cell
  • Value

Programmer Friendly API


const mp = require('multiprocess-database');

API Overview


// CREATE, DELETE, UPDATE

// Upsert (Insert or Update) object with id alice.
const {meta, data} = await mp.set("users", "alice", {name:'alice'}, {deleted:false}); // also undeleted if previously deleted

// Upsert (Insert or Update) a property, merge objects.
const {meta, data} = await mp.set("users", "alice", {email:'[email protected]'});

// GET
// Get values from object with id alice.
// NOTE: you must check if meta.deleted is true
const {meta, data} = await mp.get("users", "alice");

// CHECK
// Check if object with id alice exists.
// NOTE: you must check if data is defined
const {meta, data} = await mp.get("users", "alice");

// ALL
// Get all objects from database users.
const allArray = await mp.all("users");

// FIND
// Get matching objects from database users.
const matchingArray = await mp.all("users").filter({meta} => meta.deleted);
const matchingArray = await mp.all("users").filter({meta} => !meta.deleted);

// Finding all aol users (note you must first filter out deleted objects)
const matchingArray = await mp.all("users")
  .filter({meta} => !meta.deleted)
  .filter({data} => data.email.includes('@aol.com'));

Object Structure

{

  // Database Data
  meta: {
       uuid: '50b55281-adb2-46d0-85d0-d8a80dcc6b92',
       user: '07791d11-125b-43f7-ad27-694bb7f10a48',
    inherit: ['User', 'Authenticated', 'Animal'],
       tags: ['red', 'green', 'blue'],
    version: '132-0677083e-5edd-4e4d-8e67-388c479fec51',
      order: '0000001-c9dc5f89-b4ef-4e5b-a736-0caa9c3d0f57',
    deleted: false,
  },

  // User Data
  data: {
      'text': 'Buy Socks'
  }

}

Todo

Move ensure into chain of operations

// Ensure database existence (create if does not exist, otherwise continue)
const {meta} = await mp.ensure('users', {cleanup:true});

Developer Notes

File Storage Strategy


const file = makeFilename(object);

// Check if the file exists in the current directory, and if it is writable.
fs.access(file, fs.constants.F_OK | fs.constants.W_OK, (err) => {
  if (err) {
    console.error(
      `${file} ${err.code === 'ENOENT' ? 'does not exist' : 'is read-only'}`);
  } else {
    console.log(`${file} exists, and it is writable`);
  }
});
fs.open('myfile', 'wx', (err, fd) => {
  if (err) {
    if (err.code === 'EEXIST') {
      console.error('myfile already exists');
      return;
    }

    throw err;
  }

  writeMyData(fd);
});