Importing SQL string used in MySQL from external SQL files.
npm install @garafu/mysql-fileloadermysql-fileloader
====
This module load MySQL SQL string from sql files.
Recursively reads SQL files that exist under the specified folder.
npm install @garafu/mysql-fileloader
`
or
`
yarn add @garafu/mysql-fileloader
`
Usage
When read the required SQL string from specified file each time.
`
const path = require("path");
const root = path.join(__dirname, "./sql");
const { sql } = require("@garafu/mysql-fileloader")({ root });
(async () => {
console.log(await sql("SELECT_USER_BY_ID")); // <-- "SELECT * FROM user WHERE id=?"
})();
`
When reading synchronously all SQL files from under specified folder.
`
const path = require("path");
const SQL = require("mysql-file").loadSync(path.join(__dirname, "./sql"));
console.log(SQL["SELECT_USER_BY_ID"]); // <-- "SELECT * FROM user WHERE id=?"
`
Documents
* function
* function init([options]): void
* function sql(name): Promise
* function loadSync(root [, options]): SQL
* function loadAsync(root [, options]): SQL
$3
_function init([options]): void_
Initialize SqlFileLoader.
arguments
* options
* root {string} Root directory path of loading SQL files.
returns
This module object.
_function sql(name): Promise_
Load SQL string from specified file asyncnously.
arguments
* name {string} SQL file name.
returns
Promise SQL string
_function loadSync(root, options): SQL_
Load sql string syncronously from sql files under the specified folder.
arguments
* root {string} Start directory for searching sql files.
* options {object} See options section.
returns
_function loadAsync(root, options): SQL_
Load sql string asyncronously from sql files under the specified folder.
arguments
* root {string} Start directory for searching sql files.
* options {object} See options section.
returns
$3
* _recursive {boolean}_ : Whether you want to recoursive search or not.
$3
_SQL`_