Manages pool of MySQL connections.
Import the module
require('@aliceo2/web-ui').MySQL
Create an instance
MySQL({host: HOST, user: USER, database: DATABASE, password: PASSWORD, port: PORT});
Where:
HOST
- database hostnameUSER
- database usernamePASSWORD
] - database passwordDATABASE
- database namePORT
] - database port numberquery
Use ?
characters as placeholders for values you would like to have escaped and pass array of values as second parameter to query
method:
mySql.query('SELECT * FROM Layouts WHERE id = ?', [1])
The following values are available as result of INSERT, UPDATE or DELETE
affectedRows
- affected rows from an INSERT or DELETEchangedRows
- changed rows from an INSERTinsertId
- id of INSERTed rowMore details available in here: https://github.com/mysqljs/mysql#table-of-contents
const {MySQL} = require('@aliceo2/web-ui');
const mySql = new MySQL({host: 'localhost', user: 'root', database: 'test'});
// Insert data
mySql.query('INSERT INTO layout (name, owner_id, owner_name, tabs) value (?,?,?,?)', [1, 2, 3, 4])
.then(result => console.log(result))
.catch(err => console.error(err));