1.1.1 • Published 4 months ago
@uwineza/mysql.connect v1.1.1
MYSQL DATABASE CONNECTION
Simple Mysql Database Server (MDS) providing comprehensive error message for both development and production as you mention in the .env file
Environment configuration
IS_PRODUCTION = 1 # 0 - Development server | 1 - Production server
DB_HOST = localhost
DB_HOST_USER = root
DB_HOST_PWD =
DB_NAME = test
DB_POOL_MAX_CONNECTIONS = 10
Usage
@uwineza/mysql.connect is a promise version of connection, therefore to be working with this MySQL connector you should follow the promise rule of javascript. Here is the functional sample code
const express = require('express');
const { pool, mysqlMessage } = require('@uwineza/mysql.connect');
const router = express.Router();
router.get('/users', async (req, res) => {
try {
const [users] = await pool.query("SELECT * FROM users");
return res.json({ users });
} catch (err) {
return mysqlMessage(err, res)
}
});