npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@liangwp/simple-mysql

v1.0.4

Published

## Description

Readme

simple-mysql

Description

A thin wrapper around the official MySql8 XDevAPI connector, exposing some common use-cases with a simple promise-based api.

Features

  • Depends on @mysql/xdevapi v8.0.22
  • [x] Connection pooling
  • [x] Easy api to test for db connection
  • [x] SQL queries (using SQL statements instead of chainable api)
  • [ ] Transactions (WIP)
  • [ ] Collections (only supports chainable api)
  • [ ] Expose underlying mysqlx.client object

Additional features and notes

  • Init Promise:
    • Wait for database connection to be up before resolving (useful for running in docker, esp in dev)
  • Dropped connections:
    • If connection to DB drops, queries will fail and throw an error.
    • When connection to DB comes back, queries will be successful again without needing to re-initialize the client.

Usage

Installation

npm install --save @liangwp/simple-mysql

Connect to DB

const simpleMySQL = require('@liangwp/simple-mysql');

var connection_config = {
    user: 'test_user',
    password: 'test_pswd',
    host: 'mysql8-sample',
    port: 33060,
    schema: 'test_db'
};
var connection_options = {
    pooling: { enabled: true, maxIdleTime: 30000, maxSize: 25, queueTimeout: 10000 }
}

var mysql = simpleMySQL(connection_config, connection_options);

var retry_params = {
    retries: 10,
    factor: 2,
    minTimeout: 1000,
    randomise: true
};

# wait for connection
mysql.awaitDbInit(retry_params) # if retry_params not supplied, defaults to the above
.then(() => {
    // connection is ready
})

Test for Connection / Get Connection Params

mysql.inspect()
.then(data => {
    // do your stuff
    // data {
    //     pooling: true,
    //     auth: 'PLAIN',
    //     schema: 'test_db',
    //     ssl: true,
    //     user: 'test_user',
    //     host: 'mysql8-sample',
    //     port: 33060,
    //     dbUser: 'test_user',
    //     socket: undefined
    // }
});

Perform Simple Query

mysql.query('SELECT col1, col2 FROM some_table WHERE col3 = ?', [col3_binding])
.then(data => {
    // do your stuff
});

Close Connection to DB

mysql.close()
.then(() => {
    // connection closed
});

Transaction (WIP)

Promise.resolve()
.then(() => {
    return mysql.startTransaction()
})
.then(mysqlTrans => {
    return mysqlTrans.query('SELECT col1, col2 FROM some_table WHERE col3 = ?', [col3_binding])
    .then(data => {
        // do some stuff
        var col3_binding = 'abcde';
        return mysqlTrans.query('SELECT col1, col2 FROM other_table WHERE col3 = ?', [col3_binding]);
    })
    .then(data => {
        // do more stuff
    })
    .then(() => {
        return mysqlTrans.commit()
    })
    .catch(err => {
        return mysqlTrans.rollback()
    });
})
.catch(err => {
    // transaction failed to start
    // OR rollback failure
})
.then(() => {
    // transaction ok
    // OR rollback successful
});

Run example (in docker)

cd dev
docker-compose -f docker-compose-example.yml up --build

Run tests (in docker)

cd dev
docker-compose -f docker-compose-mocha.yml up --build

Changelog

| Date | Version | Description | | ---- | ------------------|---------------------------------------------------------------------------------------- | | 2021.04.04 | v1.0.3 | Comment out the console.log in awaitDbInit() from spamming into code that depends on this module. Should figure out a cleaner logging method later. | | 2021.01.14 | v1.0.2 | Fix silly typo, add github link. | | 2021.01.14 | v1.0.1 | Update example to work dev (git cloned), as well as for npm version. | | 2021.01.14 | v1.0.0 | Seems usable for most simple queries. Transactions support is still incomplete. |