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

passive-db

v1.0.2

Published

A light weight, simple passive Database that is easy on your CPU and RAM

Downloads

12

Readme

passive-db

A simple passive local DB that allows you to store as much data as your drive has free space.


Compatibility

  • ✅ Linux - Built for

  • ℹ️ Windows - You'll need WSL

  • ⚠️ Mac - Not tested

  • ✅ JS and TS

  • ✅ ES5 and ES6


Overview

This package offers very simple calls and convenient solutions.

Entry - A generic entry class that you can use to create new entries.

IMPORTANT NOTE: All nonSync functions of a pair are Promise based

Bind functions can be set to not update the parent entries automatically. In "target - source" functions target is the entry to edit and source is the referece

DB - The DB class that you'll manage your DB through.

.onready - A function that will be called when the db is set up, alternatively you can eyeball the delay with timeouts.

.getEntry - Returns an entry promise from the database from it's ID, which can be obtained from parent entries.

.getentriesync - .getEntry but synchronously. Uses fs.readFileSync

.setEntry - Writes/updates the passed entry to the database.

.setentriesync - .setEntry but synchronously. Uses fs.writeFileSync

.deleteEntry - Removes the passed entry/id from the database.

.deleteentriesync - .deleteEntry but synchronously. Uses fs.rmSync

.find - Pass an entry or entry id. The function will asynchronously iterate over the child entries and appeds them to a new array if the predicate is true and returns a promise for the finsihed list.

.bindEntry - Appends an entry to another entry.

.bindentriesync - .bindEntry but synchronously. Uses .setentriesync

.unbindEntry - Removes an entry from another entry.

.unbindentriesync - .unbindEntry but synchronously. Uses .setentriesync

.bindMaster - Appends an entry to the master record.

.bindMasterSync - .bindMaster but synchronously. Uses .updateMasterSync

.unbindMaster - Removes an entry from the master record.

.unbindMasterSync - .unbindMaster but synchronously. Uses .updateMasterSync

.updateMaster - Writes the master record to the database.

.updateMasterSync - .updateMaster but synchronously. Uses fs.writeFileSync


For example, let's save a message under a parent entry titled "messages":

JS es5

const passive = require("passive-db");

// initialize your new database
const db = new passive.DB("path-to-db");

db.onready = () => {
	
	// this will be our parent entry
	var messages = new Entry({name: "messages"})
	db.setEntrySync(messages);
	
	var message = new Entry({data: new Date().toString()});
	db.setEntrySync(message);
	
	// bind the entries to not loos them
	db.bindEntrySync(messages, message, true);
	db.bindMasterSync(messages, true);

};

To retrieve data use the find method:

TS es6

import { UUID } from "crypto";
import {DB, Entry} from "./src/main";

const db = new DB("path-to-db");

db.onready = async function () {

	const messages_parent = (
		// let's ask the db to search for an entry
		await db.find("master",
			// we're searching for an entry named "messages"
			(entry) => {return entry.name == "messages"},
			// stop after we found one
			1,
			// allow to search for a long time
			9000000,
			// tell the db that we want to get entries and not ids
			"Entry"
		)
	// pick the first one in the array
	)[0] as Entry<Message>;

	// iterate over the child entries
	messages_parent.records.forEach(async (id) => {
		var message_entry = await db.getEntry(id);
		// logs every message
		console.log(message_entry);
	})
};

Misc

What is the master record?

This passive DB works in a parent-child entry configuration where parent entries have child entries. The master record is a placeholder for your top level entries. If you dont bind your entry to anything and then save it in the database, then you have created an orphan entry, which are really hard to clean up.