@lazy-toolbox/mysql
TypeScript icon, indicating that this package has built-in type declarations

0.0.0 • Public • Published

Lazy Toolbox - MySQL

A NodeJS toolbox made for a lazy development when dealing with MySQL.

Lazy Toolbox

Made to tame MySQL like it should haved behaved natively.

Index

Installation (NPM)

The installation is pretty straight forward:

npm i @lazy-toolbox/mysql

v0.0.0 - Initial commit

Documentation

This part explain all tools with examples if it's needed.

MySql

LazySQL

interface MySQLConnect {
    getConnection(): mysql.Connection;
    query(sql: string | mysql.QueryOptions): Promise<unknown>;
    close(): Promise<void>;
    beginTransaction(): Promise<void>;
    commit(): Promise<unknown>;
    rollback(): Promise<void>;
}
class LazySQL {
    static createConnection(config: string | mysql.ConnectionConfig): MySQLConnect;
}

An interface to communicate with a MySQL database in asynchronous.

Example:

const { LazySQL } = require('@lazy-toolbox/mysql');
const login = () => {
    const dbLink = LazySQL.createConnection({
        host: 'localhost',
        port: 6060,
        username: 'root'
    });
    /*
    The query gives a result written like:
    [ // All selected datas
        { solution: 2 } // column 0
    ]
    */
    const result = await dbLink.query('SELECT 1 + 1 AS solution');
    /*
    The query result contain the following properties: error, results, fields.
    */
    console.log(result.results[0].solution);
    dbLink.close();
}

Package Sidebar

Install

npm i @lazy-toolbox/mysql

Weekly Downloads

1

Version

0.0.0

License

MIT

Unpacked Size

7.44 kB

Total Files

9

Last publish

Collaborators

  • friquet-luca