The custom handler for mysql2 module.
npm install @edu-tosel/mysql2-handler
export DB_HOST='localhost'
export DB_USER='root'
export DB_PASSWORD='password'
export DB_NAME='database'
export DB_PORT='3306'
export DATE_STRINGS='DATE' # or 'DATETIME' or 'TIMESTAMP'
# ...export DATE_STRINGS='DATETIME'
export CONNECTION_LIMIT='10'
export CASTED_BOOLEAN='true' # or 'false'
- DB_HOST: None
- DB_USER: None
- DB_PASSWORD: None
- DB_NAME: None
- DB_PORT: 3306
- DATE_STRINGS: 'DATE'
- CONNECTION_LIMIT: 5
- TIMEZONE: 'UTC'
- CASTED_BOOLEAN: false
const mysqlHandler = require("@edu-tosel/mysql2-handler");
function select1() {
return mysqlHandler.handler(async (connection) => {
const [rows, fields] = await connection.execute("SELECT 1 AS `one`");
return rows; // [{one: 1}]
});
}
select1().then(console.log).catch(console.error); // stdout: [{one: 1}]