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

@ahmed.noor/db-manager

v0.0.3

Published

Library to manage databases for my applications.

Readme

DB Manager

Library to manage databases for my applications. Documentation can be found in notion.

Functionality

  • Provides application level schema that can be used to create database tables.
  • Provides subtable functionanlity to expand on the main table (Can be used for common tables that required for a specific dataset)

Application Level Schema

Table:

interface TableSchema {
    name: string;
    columns: Array<ColumnSchema>;
}

Column:

enum Constraints {
    UNIQUE_KEY = "unique_key",
    PRIMARY_KEY = "primary_key",
    NOT_NULL = "not_null",
    AUTO_INCREMENT = "auto_increment"
}

interface ColumnSchema {
    name: string;
    type: {name: string, options: any};
    constraints: Array<Constraints>;
    foreign?: {table: string, column: string};
    default?: any;
}

"default" is of type "any" so we can pass knex functions as well especially for UUIDs and current time.

Datatypes

String:

const type = {
    name: "string",
    options: {
        limit: 255
    }
}

Number:

const type = {
    name: "number",
    options: {
        size: "tiny|small|medium|normal|big",
        type: "float|int"
        unsigned: false
    }
}

Enum:

const type = {
    name: "enum",
    options: {
        enums: ["string_1", "string_2"],
    }
}

Datetime:

const type = {
    name: "datetime"
}

Classes

DBConfig

Holds database configuration and provides a way to access knex database objects.

  • constructor({host, port, user, pass})
  • testConnection() throws error
    • If connection fails throws error
  • getDatabaseHandle: Knex (db_name: string)
    • Returns "Knex" object to interact with the database. Using "*" as the db_name will return "Knex" object without any database selected.
  • destroy(db_name?: string)
    • Destroys all "Knex" objects if db_name is not provided else destroys that particular db_name object.

SubTable

  • constructor(schema_handle: (parent_schema: TableSchema) => TableSchema)
  • createIfNotExists (parent_schema: TableSchema, knex_handle: Knex)
    • Creates a table using schema information of the parent table. It automatically changes the table name concating its parent's name as such: $(parent table name)_(subtable name).
    • If table exists, nothing will happen.

Table

  • constructor(table_schema: TableSchema, sub_tables: SubTable[])
  • createIfNotExists(db_name: string, db_config: DBConfig)
    • Creates a table using its table schema. Creates all sub tables as well.
    • If table exists, it will proceed to create sub tables.

NOTE

*Foreign keys are disabled for cloud scalability.

DB Manager is built on top of knex query builder. Any code solely written for db manager functionality will not and should not be used to run on production. At least not in this state where its highly unstable. The point of DB Manager is to provide internal functionality to the organization, it will only be used in development phase (when the table schema and all is not finalized) during maintanence to setup or upgrade the product.