mysql-json-formatter
v1.2.1
Published
This package is used to edit MySQL queries containing 'JOIN' in JSON format
Downloads
30
Readme
mysql-json-formatter
This package is used to edit MySQL queries containing 'JOIN' in JSON format
Declaretions
.env
DB_NAME = 'dbname'
FSQL_HOST = 'host_ip'
FSQL_USER = 'username' //! I recommend that you type the root user
FSQL_PASSWORD = 'password'
db.js
const mysql = require('mysql');
require('dotenv').config();
const conn = mysql.createConnection({
host:process.env.FSQL_HOST,
user:process.env.FSQL_USER,
password:process.env.FSQL_PASSWORD,
database:process.env.DB_NAME
})
conn.connect(()=>{
console.log('Connected to MySQL');
})
module.exports = conn;
Usage / Examples
const fquery = require('mysql-json-formatter');
const db = require('./db');
async function mysqlJsonFormat() {
await fquery(`
SELECT * FROM stocks
LEFT JOIN patterns pt ON pt.id = stocks.pattern_id
LEFT JOIN machines mc ON mc.id = stocks.machine_id
`,db);
}
await fquery(`
SELECT * FROM stocks
LEFT JOIN patterns pt ON pt.id = stocks.pattern_id
LEFT JOIN machines mc ON mc.id = stocks.machine_id
WHERE id = ?
`,db,['2']);