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

db-metadata-cg-lib

v1.0.16

Published

Library to get metadata of a database connection like oracle,mariadb,postgres.

Downloads

71

Readme

N|Solid

db-metadata-cg-lib

1. Introduction

The objective of this code is to query the metadata of databases from drivers such as Oracle, Postgres and MariaDB. Three types of calls can be made: schemes, tables and columns. This is for the purpose of knowing the table structure of databases and knowing how to make queries, inserts, updates and deletes.

This library is useful to be added to any nodejs project.

Within "db-metadata-cg-lib" there is one additional library is used: sequelize: This library is used to create a connection with the databases and perform the queries to get de metadata and return the final result that is managed as JSON objects.

The next is an example, we are going to get all the schemas from an Oracle database and we are going to send all the required parameters like the next example:

{
        "dialect": "oracle",
        "database": "ORCL",
        "host":"oracle.training.cgdemos.com",
        "user": "TEST_USER",
        "password": "admin",
        "type":"schemas",
        "filter":""  
    }

This is the result:

[
    {
        "OWNER": "SYS"
    },
    {
        "OWNER": "SYSTEM"
    },
    {
        "OWNER": "DBSNMP"
    },
    {
        "OWNER": "APPQOSSYS"
    },
    {
        "OWNER": "TEST_USER"
    },
    {
        "OWNER": "DBSFWUSER"
    },
    {
        "OWNER": "REMOTE_SCHEDULER_AGENT"
    },
    {
        "OWNER": "PUBLIC"
    },
    {
        "OWNER": "CTXSYS"
    },
    {
        "OWNER": "AUDSYS"
    },
    {
        "OWNER": "OJVMSYS"
    },
    {
        "OWNER": "SI_INFORMTN_SCHEMA"
    },
    {
        "OWNER": "DVF"
    },
    {
        "OWNER": "DVSYS"
    },
    {
        "OWNER": "GSMADMIN_INTERNAL"
    },
    {
        "OWNER": "ORDPLUGINS"
    },
    {
        "OWNER": "MDSYS"
    },
    {
        "OWNER": "ORDDATA"
    },
    {
        "OWNER": "OLAPSYS"
    },
    {
        "OWNER": "LBACSYS"
    },
    {
        "OWNER": "OUTLN"
    },
    {
        "OWNER": "ORACLE_OCM"
    },
    {
        "OWNER": "HRAPPS"
    },
    {
        "OWNER": "XDB"
    },
    {
        "OWNER": "WMSYS"
    },
    {
        "OWNER": "ORDSYS"
    }
]

2. Methods explanation

_2.1. metadataProcess

The library can be installed from npm page with the next sentences:

npm install db-metadata-cg-lib, npm i db-metadata-cg-lib or yarn install db-metadata-cg-lib

This method is used to perform all the operations that the library can do for the different database managers that are Oracle, Postgres and MariaDB, sending the required parameters.

3. Argument and result explanation

  • Arguments: The only and main method needs a list of parameters, then all the parameters are listed with their description:

    • dialect. - parameter to know which database manager is going to be consulted.
    • database. - the name of the database
    • host. - numeric or alphanumeric address to connect to the database.
    • user. - the username to connect to the database.
    • password. - the password to connect to the database.
    • type. - parameter that defines what type of query will be made to the database, there are three types:
      • schemas: this type will return all the schemas that exist in the database connection.
      • tables: this type will return all the tables that exist in the schema that is sent in the "filter" parameter.
      • columns: this type will return all the columns of the tables and their data type that are sent in the "filter" parameter, the name of the table(s) must be sent separated by a comma.
    • filter. - this parameter is used to filter the metadata when the “type” parameter is “tables” or “columns”, with type “schema” it has no effect, to send more than one table we have to separate by coma.
  • Result: The final result varies depending on the process, if it is "schemas" it will return a JSON as a result with the schemas of the database, if it is an "tables" it will return a JSON with all the tables of the schema selected, and the last one "columns" it will return a JSON with the columns of the tables that we send in the filter parameter.

3. Examples

Example 1: We are going to get all the schemas from an Oracle database and we are going to send all the required parameters like the next example:

{
        "dialect": "oracle",
        "database": "ORCL",
        "host":"oracle.training.cgdemos.com",
        "user": "TEST_USER",
        "password": "admin",
        "type":"schemas",
        "filter":""  
    }

And this is the result of that:

[
    {
        "OWNER": "SYS"
    },
    {
        "OWNER": "SYSTEM"
    },
    {
        "OWNER": "DBSNMP"
    },
    {
        "OWNER": "APPQOSSYS"
    },
    {
        "OWNER": "TEST_USER"
    },
    {
        "OWNER": "DBSFWUSER"
    },
    {
        "OWNER": "REMOTE_SCHEDULER_AGENT"
    },
    {
        "OWNER": "PUBLIC"
    },
    {
        "OWNER": "CTXSYS"
    },
    {
        "OWNER": "AUDSYS"
    },
    {
        "OWNER": "OJVMSYS"
    },
    {
        "OWNER": "SI_INFORMTN_SCHEMA"
    },
    {
        "OWNER": "DVF"
    },
    {
        "OWNER": "DVSYS"
    },
    {
        "OWNER": "GSMADMIN_INTERNAL"
    },
    {
        "OWNER": "ORDPLUGINS"
    },
    {
        "OWNER": "MDSYS"
    },
    {
        "OWNER": "ORDDATA"
    },
    {
        "OWNER": "OLAPSYS"
    },
    {
        "OWNER": "LBACSYS"
    },
    {
        "OWNER": "OUTLN"
    },
    {
        "OWNER": "ORACLE_OCM"
    },
    {
        "OWNER": "HRAPPS"
    },
    {
        "OWNER": "XDB"
    },
    {
        "OWNER": "WMSYS"
    },
    {
        "OWNER": "ORDSYS"
    }
]

Now we take one schema for the next call, we are going to use the schema to filter the tables by that schema, this is the payload:

    {
        "dialect": "oracle",
        "database": "ORCL",
        "host":"oracle.training.cgdemos.com",
        "user": "TEST_USER",
        "password": "admin",
        "type":"tables",
        "filter":"TEST_USER"  
    }

And this is the result:

[
    {
        "TABLE_NAME": "ALL_ORDERS"
    },
    {
        "TABLE_NAME": "ERPDATA"
    },
    {
        "TABLE_NAME": "IL_ITEMS"
    },
    {
        "TABLE_NAME": "IL_ORDERS"
    },
    {
        "TABLE_NAME": "MEX_ITEMS"
    },
    {
        "TABLE_NAME": "MEX_ORDERS"
    },
    {
        "TABLE_NAME": "PERSONA"
    },
    {
        "TABLE_NAME": "PERSONA_NAME"
    },
    {
        "TABLE_NAME": "SLC_HRINF_OUTBOUND_STG"
    },
    {
        "TABLE_NAME": "WI_ITEMS"
    },
    {
        "TABLE_NAME": "WI_ORDERS"
    }
]

Now the last call is to get the columns, so we are going to send a table or tables into the filter parameters like the next example:

    {
        "dialect": "oracle",
        "database": "ORCL",
        "host":"oracle.training.cgdemos.com",
        "user": "TEST_USER",
        "password": "admin",
        "type":"columns",
        "filter":"IL_ORDERS,MEX_ITEMS"  
    }

The result is this:

[
    {
        "TABLE_NAME": "IL_ORDERS",
        "COLUMN_NAME": "ID",
        "DATA_TYPE": "VARCHAR2",
        "DATA_LENGTH": 50
    },
    {
        "TABLE_NAME": "IL_ORDERS",
        "COLUMN_NAME": "ORDER_EXPECTED_DATE",
        "DATA_TYPE": "VARCHAR2",
        "DATA_LENGTH": 50
    },
    {
        "TABLE_NAME": "IL_ORDERS",
        "COLUMN_NAME": "COMPANY",
        "DATA_TYPE": "VARCHAR2",
        "DATA_LENGTH": 50
    },
    {
        "TABLE_NAME": "IL_ORDERS",
        "COLUMN_NAME": "CUSTOMER_NAME",
        "DATA_TYPE": "VARCHAR2",
        "DATA_LENGTH": 100
    },
    {
        "TABLE_NAME": "IL_ORDERS",
        "COLUMN_NAME": "CUSTOMER_EMAIL",
        "DATA_TYPE": "VARCHAR2",
        "DATA_LENGTH": 50
    },
    {
        "TABLE_NAME": "IL_ORDERS",
        "COLUMN_NAME": "CUSTOMER_ADDRESS",
        "DATA_TYPE": "VARCHAR2",
        "DATA_LENGTH": 200
    },
    {
        "TABLE_NAME": "IL_ORDERS",
        "COLUMN_NAME": "WHS_LOCATION",
        "DATA_TYPE": "VARCHAR2",
        "DATA_LENGTH": 20
    },
    {
        "TABLE_NAME": "IL_ORDERS",
        "COLUMN_NAME": "ORDER_TOTAL",
        "DATA_TYPE": "VARCHAR2",
        "DATA_LENGTH": 20
    },
    {
        "TABLE_NAME": "IL_ORDERS",
        "COLUMN_NAME": "ORDER_DAYS_DURATION",
        "DATA_TYPE": "VARCHAR2",
        "DATA_LENGTH": 20
    },
    {
        "TABLE_NAME": "MEX_ITEMS",
        "COLUMN_NAME": "LINE_ID",
        "DATA_TYPE": "VARCHAR2",
        "DATA_LENGTH": 50
    },
    {
        "TABLE_NAME": "MEX_ITEMS",
        "COLUMN_NAME": "ITEM_SKU",
        "DATA_TYPE": "VARCHAR2",
        "DATA_LENGTH": 20
    },
    {
        "TABLE_NAME": "MEX_ITEMS",
        "COLUMN_NAME": "NAME",
        "DATA_TYPE": "VARCHAR2",
        "DATA_LENGTH": 150
    },
    {
        "TABLE_NAME": "MEX_ITEMS",
        "COLUMN_NAME": "QUANTITY",
        "DATA_TYPE": "NUMBER",
        "DATA_LENGTH": 22
    },
    {
        "TABLE_NAME": "MEX_ITEMS",
        "COLUMN_NAME": "PRICE",
        "DATA_TYPE": "FLOAT",
        "DATA_LENGTH": 22
    },
    {
        "TABLE_NAME": "MEX_ITEMS",
        "COLUMN_NAME": "EFFECTIVE_DATE",
        "DATA_TYPE": "VARCHAR2",
        "DATA_LENGTH": 20
    },
    {
        "TABLE_NAME": "MEX_ITEMS",
        "COLUMN_NAME": "PARENT_ORDER",
        "DATA_TYPE": "VARCHAR2",
        "DATA_LENGTH": 50
    }
]