0.18.0 • Published 6 months ago

mysql-oh-wait v0.18.0

Weekly downloads
1
License
MIT
Repository
github
Last release
6 months ago

Mysql Oh Wait! (Mysql await)

code coverage version downloads license

Uses the great node mysqljs/mysql package and wraps around it to facilitate getting results as a return from MysqlReq.query(). Instead of needing to use callbacks, this package uses Promises and the async / await syntax which is much easier. On top of that the advantage (if you need this feature of course) is that you don't need to worry about connections not being closed or open at the moment of querying.

Installation

To install this npm package do

npm i mysql-oh-wait

Usage

MysqlReq

Then from your javascript files import either MysqlReq or MysqlDump with

//var MysqlReq = require('mysql-oh-wait').MysqlReq;
import { MysqlReq } from 'mysql-oh-wait';

Then you can directly query your database:

//import 'dotenv/config'; // this will get connection settings from .env file

import { MysqlReq, MysqlDump } from 'mysql-oh-wait';

const res = await MysqlReq.query({sql: 'SELECT * FROM MyTable WHERE ?', values: {myCol: 'myValue'}});
console.log(res); // [ { myCol: 'myValue', ...otherColumns }, { myCol: 'myValue', ...otherColumns2 }, ...otherRows ]

This is assuming you have set the connection details in environment variables like:

process.env.DB_HOST = 'myhost'
process.env.DB_USER = 'myuser'
process.env.DB_PASSWORD = 'mypwd'
process.env.DB_NAME = 'mydbname'
process.env.MULTIPLE_STATEMENTS = 1

Or you can store these in a .env file. In which case the import 'dotenv/config'; statement will load them for you. (You need to npm i -P dotenv for this to work.

MysqlDump

If you want to create the database tables from an sql file you can use MysqlDump

//var MysqlDump = require('mysql-oh-wait').MysqlDump;
import { MysqlDump } from 'mysql-oh-wait';

Then if you have an MysqlDump file somewhere you can simply do:

import { MysqlDump } from 'mysql-oh-wait';
await MysqlDump.executeSqlFile(`${__dirname}/mysqldump.sql`);

This should have loaded all your tables in the database. Again, assuming you have database connection config in process.env.DB_... properties.

0.18.0

6 months ago

0.17.0

10 months ago

0.16.3

10 months ago

0.15.1

1 year ago

0.16.0

1 year ago

0.16.1

1 year ago

0.16.2

1 year ago

0.15.0

4 years ago

0.14.0

4 years ago

0.13.0

4 years ago

0.12.0

4 years ago

0.11.13

4 years ago

0.11.11

4 years ago

0.11.12

4 years ago

0.11.8

4 years ago

0.11.9

4 years ago

0.11.5

4 years ago

0.11.6

4 years ago

0.11.7

4 years ago

0.11.10

4 years ago

0.11.4

4 years ago

0.11.0

4 years ago

0.11.1

4 years ago

0.11.2

4 years ago

0.11.3

4 years ago

0.10.1

4 years ago

0.10.0

4 years ago

0.9.5

5 years ago

0.9.4

5 years ago

0.9.3

5 years ago

0.9.2

5 years ago

0.9.1

5 years ago

0.9.0

5 years ago

0.8.1

5 years ago

0.8.0

5 years ago

0.7.0

5 years ago

0.6.1

5 years ago

0.6.0

5 years ago

0.5.4

5 years ago

0.5.3

5 years ago

0.5.2

5 years ago

0.5.1

5 years ago

0.5.0

5 years ago

0.4.0

5 years ago

0.3.0

5 years ago

0.2.0

5 years ago

0.1.8

5 years ago

0.1.7

5 years ago

0.1.5

5 years ago

0.1.4

5 years ago

0.1.3

5 years ago

0.1.1

5 years ago