Node's Pastoral Musicians

    mysql-database

    1.2.8 • Public • Published

    MySQL Database


    Table of 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

    Documentation

    View Documentation

    Events

    • connected (connection)
    // Import Libary
    const MySQL = require('mysql-database');
    const database = new MySQL();
    
    // Create Your Own Connection
    run();
    async function run(){
    	let db = await database.connect({ 
    		host: 'localhost',
    		port: '3306', // the default is 3306
    		user: 'root',
    		password: '',
    		database: 'my_database'
    	});
    
    	// database connected event
    	db.on('connected', function (connection) {
    		console.log('Database Connected');
    	})
    }

    Methods

    • set (table, key, value)
    await db.set('my_table', 'foo', 'bar');
    // -> Stores 'bar' in 'foo' key name in the table 'my_table'
    • get (table, key)
    await db.get('my_table', 'foo');
    // -> Gets foo key name value (which is bar) in the table 'my_table'
    • base_set (table, key, value)
    await db.base_set('my_table', 'foo', 'bar');
    // -> Stores 'bar' in 'foo' key name in the table 'my_table' but base encrypted
    • base_get (table, key)
    await db.base_get('my_table', 'foo');
    // -> Gets foo key name value (which is bar) in the table 'my_table' for encrypted rows using base_set method
    • push (table, array, value)
    await db.push('my_table', 'fruits', 'banana');
    // -> pushs 'banana' to 'fruits' array in 'my_table' table
    • pull (table, array, value)
    await db.pull("my_table", "fruits", "banana");
    // -> pulls FIRST 'banana' from 'fruits' in 'my_table'
    await db.pull("my_table", "fruits", "banana", "all");
    // -> pulls ALL 'banana' from 'fruits' in 'my_table'
    • includes (table, array, value)
    await db.includes("my_table", "fruits", "banana");
    // -> Checks if the array includes provided value
    • add (table, key, number)
    await db.add("my_table", "price", 10);
    // -> add 10 to price in 'my_table' table
    • sub (table, key, number)
    await db.sub("my_table", "price", 5);
    // -> subtracts 5 from price - the remaining is 5 from price in 'my_table' table
    • all (table)
    await db.all("my_table");
    // -> retutn all the data in 'my_table' table
    • delete (table, key)
    await db.delete("my_table", "foo");
    // -> delete foo key in 'my_table' table
    • tables ()
    await db.tables();
    // -> return array of all tables existed in the database
    • rename (table, new_table_name)
    await db.rename("my_table", "new_name");
    // -> renames table name
    • stats (table)
    await db.stats("my_table");
    // -> return table info
    • query (query)
    await db.query("DROP TABLE my_table;")
    // -> executes a SQL query
    • auto_increment (table, number)
    await db.auto_increment("my_table", 5);
    // -> sets 'my_table' table auto increment to 5
    • create (table)
    await db.create("table_name");
    // -> Create empty table with "table_name" name without inserting any data to it
    • drop (table)
    await db.drop("table_name");
    // -> deletes the table 'table_name'
    • clear (table)
    await db.clear("table_name");
    // -> clears all 'table_name' table rows & data
    • variables (variables_object)
    await db.variables({ 
    	max_connections: 100000,
    	max_connect_errors: 100000,
    	wait_timeout: 60
    });
    // -> modifies any global variable
    • ping ()
    await db.ping();
    // -> gets database ping (in ms)
    • process ()
    await db.process();
    // -> returns the processes/connections list
    • end ()
    await db.end();
    // -> closes the connection

    Contributing

    © mysql-database, 2021 - 2022 | TARIQ (contact@itariq.dev)

    Install

    npm i mysql-database

    DownloadsWeekly Downloads

    81

    Version

    1.2.8

    License

    MIT

    Unpacked Size

    29 kB

    Total Files

    32

    Last publish

    Collaborators

    • tariqdev