Skip to main content

Getting Started

Get started with the most powerful database for your project that can handle billion of users


Logo


NPM version NPM downloads

MySQL Database

Table Of Getting Started Contents

About

  • Easily modify your MySQL database data with easy functions
  • Useful for websites & large projects where it makes managing data easier & faster
  • Supports the Promise-API, you will be able to use .then, .catch, await, etc...
  • & more...

Installation

npm i mysql-database

Example Usage

const MySQL = require('mysql-database');
const database = new MySQL();

run()
async function run() {
let db = await database.connect({ // creates a database connection
host: 'localhost',
port: '3306', // the default is 3306
user: 'root',
password: '',
database: 'my_database',
charset: 'utf8mb4'
});

db.on('connected', async connection => { // database connected event
console.log('Database Connected');
});

db.on('dataModification', async event => { // data changes & modifications event
console.log(event);
/*
{
oldData: 'bar',
newData: 'bar2',
type: 'UPDATE',
table: 'test_table',
modifiedAt: 1653815607288
}
*/
});

db.on('tableCreate', async table => {
console.log(`Table ${table} Created`);
});

db.on('tableDelete', async table => {
console.log(`Table ${table} Deleted`);
});

db.on('tableClear', async table => {
console.log(`Table ${table} Data Cleared`);
});

db.on('tableRename', async (oldName, newName) => {
console.log(`Table renamed from ${oldName} to ${newName}`);
});

await db.set("my_table", "foo", "bar");
// -> Stores 'bar' in 'foo' key name in the table 'my_table'

let data = await db.get("my_table", "foo");
console.log(data); // bar
// -> Gets foo key name value (which is bar) in the table 'my_table'

await db.delete("my_table", "foo");
// -> delete foo key in 'my_table' table
}