run-my-sql-file

1.0.0 • Public • Published

Run My SQL File

Run My SQL File is a NPM package that can run .sql script files.

For now it only supports mysql.

Installation

You can install it using NPM

npm install run-my-sql-file

Usage

First you need to pass the connection options, it supports all the mysql's createConnection options (host, password, user, etc).

Example:

const Runner = require("run-my-sql-file");
 
//SETTING THE OPTIONS
Runner.connectionOptions({
   host:"localhost",
   user:"root",
   password:"kept_u_w8ing_huh?"
});
 

And then when all the options are set, you can execute the runFile function.

Example:

const file1_path = __dirname + "/scripts/script1.sql";
 
const file2_path = "../script2.sql";
 
const file3_path = "./script3.sql";
 
//IT WILL RUN THE FILE 3
Runner.runFile(file3_path, (err)=>{
   if(err){
      console.log(err);
   } else {
      console.log("Script sucessfully executed!");
   }
});

Full example:

const Runner = require("run-my-sql-file");
 
//SETTING THE OPTIONS
Runner.connectionOptions({
   host:"localhost",
   user:"root",
   password:"kept_u_w8ing_huh?"
});
 
const file1_path = __dirname + "/scripts/script1.sql";
 
const file2_path = "../script2.sql";
 
const file3_path = "./script3.sql";
 
//IT WILL RUN THE FILE 3
Runner.runFile(file3_path, (err)=>{
   if(err){
      console.log(err);
   } else {
      console.log("Script sucessfully executed!");
   }
});

Source code

The source code is avaliable in github

License

Eiffel Forum License, version 2

Package Sidebar

Install

npm i run-my-sql-file

Weekly Downloads

169

Version

1.0.0

License

Eiffel Forum License, version 2

Unpacked Size

5.04 kB

Total Files

4

Last publish

Collaborators

  • vinicius.m