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

simpledatabases

v1.1.30

Published

This package is a system that will allow you to storage your objects in a database without having to deal with anything regarding the database itsself. We manage everything with tables and adding/updating/removing data for you.

Downloads

79

Readme

SimpleDatabases

This package is a system that will allow you to storage your objects in a database without having to deal with anything regarding the database itsself. We manage everything with tables and adding/updating/removing data for you.

How to use

To get started with SimpleDatabases you need to create a StorageHolder, which will keep track of all your storages. A storage is a collection of all of your objects of ONE specific type. Then to store the data in the database you will need to create a database object. The currently implemented ones are MySQLDatabase, MongoDBDatabase and FlatFileDatabase.

const holder: StorageHolder = new StorageHolder();
const mysqldatabase: MySQLDatabase = new MySQLDatabase({database: "simpledb", user: "simpledb", password: "simpledb"});
const mongo: MongoDBDatabase = new MongoDBDatabase("simpledb", "mongodb://localhost:27017/", { auth: { user: "simpledb", password: "simpledb" } });
const flatfile: FlatFileDatabase = new FlatFileDatabase();

At this point you need to create an object you want to store. This must extend an AbstractBody. The currently implemented ones are MySQLBody, MongoDBBody and FlatFileBody.


class ExampleObject extends MySQLBody {

    id: string;
    prefix: string;
    level: number;

    constructor(storage: MySQLStorage<MySQLBody>, database: MySQLDatabase) {
        super(storage, database);

        // Store default values here in constructor
        this.prefix = "!";
        this.level = 0;
    }

    getCollection = () => "tablename";
    getIdentifier = () => "id";
    getIdentifierValues = () => this.id;

    getColumns = () => new Map()
        .set("id", ColumnType.VARCHAR50)
        .set("prefix", ColumnType.TINYTEXT)
        .set("level", ColumnType.INT);

    serialize(data: SerializedData) {
        data.write("id", this.id);
        data.write("prefix", this.prefix);
        data.write("level", this.level)
    }

    deserialize(data: SerializedData) {
        this.id = data.get("id");
        this.prefix = data.get("prefix");
        this.level = data.get("level", "number"); // Because we pass "number" as the second parameter, we call parseInt on the data to make sure its a number
    }
}

Now we need a holder which will hold our ExampleObject's. This needs to extend AbstractStorage. The currently implemented ones are MySQLStorage, MongoDBStorage and FlatFileStorage. This is mainly used to implement your own way of caching data (if you want to cache data, otherwise just have empty functions.)

class DataHolder extends MySQLStorage<DataObject> {

    cached: Map<string, DataObject>;

    constructor(holder: StorageHolder, database: MySQLDatabase) {
        super(holder, database, DataObject);
        this.cached = new Map();
    }

    onRemove(object: DataObject): Promise<void> {
        this.cached.delete(object.getIdentifierValues()); // Remove from cache
        return;
    }

    onAdd(object: DataObject): Promise<void> {
        this.cached.set(object.getIdentifierValues(), object); // Add to cache
        return;
    }

    getValues(): DataObject[] {
        return Array.from(this.cached.values());
    }
}

Now that we have our dataholder we need to create one. By creating an instance of the class we automatically register it in our storage holder.

const holder: StorageHolder = new StorageHolder();
const database: MySQLDatabase = new MySQLDatabase({database: "simpledb", user: "simpledb", password: "simpledb"});

const dataHolder: DataHolder = new DataHolder(holder,database);

Now everything is set up for us to start creating and storing objects.


const holder: StorageHolder = new StorageHolder();
const database: MySQLDatabase = new MySQLDatabase({database: "simpledb", user: "simpledb", password: "simpledb"});

const dataHolder: DataHolder = new DataHolder(holder,database);

const dataHolderReference: DataHolder = holder.get("tablename"); // This is another way of getting a reference to the data holder

const obj = dataHolder.getOrCreate({id: 1});
obj.prefix = ".";
obj.level = 5;
await obj.save(); // Save this object

const obj2 = dataHolder.getOrCreate({id: 2});
obj2.prefix = "/";

const obj3 = dataHolder.getOrCreate({id: 3});
obj3.level = 6;

await dataHolder.save(); // Save all objects in cache