@empjourney/mysql-util
v0.0.4
Published
mysql2 dev friendly wrapper
Downloads
12
Readme
@empjourney/mysql
This library is a mysql2 wrapper with intuitive developer friendly methods
Usage
import mysqlUtil from '@empjourney/mysql-util';
Once imported, get the singleton instance
const dbInstance = await MySqlUtil.getInstance({
host: process.env.MYSQL_HOST,
user: process.env.MYSQL_USER,
password: process.env.MYSQL_PASSWORD,
database: process.env.MYSQL_DATABASE //optional
});
})
This gives you instance of MySqlUtil which has following methods:
| Method (all async) | Description | | :---------------------------------------------------- | :------------------------------------------ | | query (dbName:string) | runs query against DbPool | | createAndUseDatabase (dbName:string) | Creates database and switches to it | | useDatabase (dbName:string) | switches to it | | dropDatabase (dbName:string) | Drops the database | | createTable(tableName: string,columns: TableColumn) | Creates table with specified column details | | generateInsertStatements(tableName: string) | Generated Insert Queries for all rows | | describeTable(tableName: string) | Returns all columns with description |