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

readdb

v1.0.1

Published

A tool for read Databases metadata

Downloads

6

Readme

readdb

Get your database metadata info

readdb is a package to get database metadata such as tables, fields, foreign and primary keys.

install

On your console, run

npm install readdb --save

usage

First, you may require the readdb package

const readdb = require( 'readdb');

Then, instantiate a new readdb object and connect to your database usign the credentials like this

new readdb( 'database', 'user', 'password' )

To finally use the readdb class, you need to call the method setup. This method returns a promise with the configured readdb object

readdb.setup().then( readdb => {
    
    // now you con navigate through your database
    readdb.onTables( table => {
        
        // look, a table that i found
        console.log( table.name );
    });
})
.catch( err => {
    
    // something went wrong ......
    console.log( err );
});

Check the full exemple code

const readdb = require( 'readdb');

new readdb( 'database', 'user', 'password' ).setup().then( readdb => {
    
    // now you con navigate through your database
    readdb.onTables( table => {
        
        // look, a table that i found
        console.log( table.name );
    });
})
.catch( err => {
    
    // something went wrong ......
    console.log( err );
});

Reference

readb class

setup() set the database mapping onTables( callback ) executes a function for each table found on database table() gets a specific table of the database

table class

name: string name of the table onFields( callaback ) execute a function for each field of the table onForeignKeys( callback ) execute a function for each foreign key of the table onPrimaryKeys( callback ) execute a function for each primary key of the table

field class

name: string name of the field type: string the type of the field size: number the size of the field allowNull: boolean if the field allows null values defaultValue: string the default value for this field primaryKey: boolean if a field is a primary key or not

Instance options

When you instantiate a new readdb class, it accepts four params. They are: database: string the database name user: string the database user password: string the password option: object and object with some configuration. The fourth param, options, acceppts this properties

var db = new readdb('database', 'user', 'pass', {
    host: 'localhost',
    dialect: 'mysql'|'mariadb'|'sqlite'|'postgres'|'mssql',
    directory: false, // prevents the program from writing to disk
    port: 'port',
    additional: {
        timestamps: false
        //...
    },
    tables: ['table1', 'table2', 'table3']
    //...
})

Adapters

Readdb works with mysql as default, but it can run with mariadb, sqlite, postgres and mssql as well. To do this, you need install it's respective npm package.