Db Model helper is a helper to get model and other information from an existent database.
For now, the only database supported is Mysql
npm i @devmojos/db-model-helper --save
import DbHelpers from '@devmojos/db-model-helper';
import { IDBHelper, IDBAttribute } from '@devmojos/db-model-helper/common/types';
const mysqlHelper : IDBHelper = DbHelpers.mysql({
host: "localhost",
user: "username",
password: "password",
database: "database_name",
port: 3306
});
const displayInfo = async (db: IDBHelper) => {
//create a pool to the database
mysqlHelper.createPool();
//
// Run how many queries you want
//
//Tables
const tables : string[] = await db.model.getTables();
console.log("Tables: ", tables )
//Columns
const columns = await db.model.getColumns("some_table");
console.log("Columns: ", columns);
//
//Close database connection when you don't need it anymore
//
db.close();
};
displayInfo(mysqlHelper);
npm install
npm run build
npm test
#You need to create your own index.development.ts first
npm run local