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

mysql-db-pool-connection-class

v1.0.6

Published

## What is "mysql-db-pool-connection-class"?

Readme

mysql-db-pool-connection-class

What is "mysql-db-pool-connection-class"?

Class used when trying to handle MySQL PoolConnection nicely with node.js express etc.

Installation

npm package

npm i mysql-db-pool-connection-class

And

import { MySqlPoolConnection } from 'mysql-db-pool-connection-class';

Usage

API Documentation created By typedoc: Check github pages

How to class

import { SqlQueryFactory } from 'sql-query-builder-like-firestore';
import { IMySqlPoolConnection, MySqlPoolConnection } from 'mysql-db-pool-connection-class';

const mysqlPoolConfig = {
  connectionLimit: << mysql connection >>,
  host: << mysql host >>,
  user: << mysql user >>,
  password: '<< mysql password >>,
  database: << mysql database >>,
}

export class TestClass {
  private readonly connection: IMySqlPoolConnection;
  constructor(connection: IMySqlPoolConnection) {
    this.connection = connection;
  }

  // SELECT Query use executeReadOnly
  async get18YearsUsers() {
    return await this.connection.executeReadOnly('SELECT * from where age = 18;');
  }

  // INSERT, UPDATE, DELETE use executeWithTransaction & execute
  async editUserName(userId: number, username: string) {
    return await this.connection.executeWithTransaction(async (connection) => {
      await this.connection.execute(
        connection,
        SqlQueryFactory.update('projects')
          .column({ columnName: 'name', value: projectName })
          .where('id', '=', projectId).query,
      );
      await this.connection
          .execute(
            connection,
            SqlQueryFactory.insert('user').column({
              columnName: 'name',
              value: username,
            }).query,
          )
      const projects = await this.connection
        .execute(connection, SqlQueryFactory.select('projects').where('id', '=', projectId).query)
        .then(toProjects);
      return projects[0];
    });
  }
}

// DI injection
const test = new TestClass(new new TestClass(new MySqlPoolConnection(mysqlPoolConfig));

const users = test.get18YearsUsers();
console.log(users);
// [
//   {
//    id: 1,
//     username: 'risa',
//     age: 18,
//     createe_at: 2020-01-25T00:00:00.000Z,
//     updated_at: 2020-01-25T00:00:00.000Z,
//   },
//   {
//    id: 2,
//     username: 'masumi',
//     age: 18,
//     created_at: 2020-01-25T00:00:00.000Z,
//     updated_at: 2020-01-25T00:00:00.000Z,
//   },
//   {
//    id: 3,
//     username: 'yuka',
//     age: 18,
//     created_at: 2020-01-25T00:00:00.000Z,
//     updated_at: 2020-01-25T00:00:00.000Z,
//   },
//   ...
// ]

const modifiedUser = test.editUserName(3, 'yuuka');
console.log(modifiedUser);
// [
//   {
//    id: 3,
//     username: 'yuuka',
//     age: 18,
//     created_at: 2020-01-25T00:00:00.000Z,
//     updated_at: 2020-01-25T12:00:00.000Z,
//   },
//   ...
// ]

How to converter

import { SqlQueryFactory } from 'sql-query-builder-like-firestore';
import { toRowDataPacket, TMapDBColumnToPropertyConfig } from 'mysql-db-pool-connection-class';
import { format } from 'date-fns';
import * as R from 'ramda';

const DATE_FORMAT = 'yyyy/MM/dd';
const toDateString = R.partialRight(format, [DATE_FORMAT, undefined]);
type TUser = {
  id: number;
  name: string;
  age: number;
  createdAt: string;
  updatedAt: string;
}

// map DB column name to Javascript interface property definition.
const USER_MAPPING_CONFIG: TMapDBColumnToPropertyConfig<TUser> = [
  {
    // db column name
    dbColumnName: 'id',
    // TUser property name
    propertyName: 'id',
  },
  {
    dbColumnName: 'name',
    propertyName: 'name',
  },
  {
    dbColumnName: 'age',
    propertyName: 'age',
  },
  {
    dbColumnName: 'created_at',
    propertyName: 'createdAt',
    // DB data convert function
    to: toDateString,
  },
  {
    dbColumnName: 'updated_at',
    propertyName: 'updatedAt',
    to: toDateString,
  },
];

// create converter function.
// return (data: any) => TUser[]
const toUsers = toRowDataPacket(USER_MAPPING_CONFIG);

export class TestClass {
  ...
  async get18YearsUsers() {
    return await this.connection.executeReadOnly('SELECT * from where age = 18;')
      // set converter
      .then(toUsers);
  }

  async addUser(username: string, age: number) {
    return await this.connection.executeWithTransaction(async (connection) => {
      const id = await this.connection
          .execute(
            connection,
            `INSERT INTO users (username, age) VALUES (/'${username}/', age);',
          )
          // return auto increment id
          .then(toInsertId);
    });
    return id;
  }
}

const test = new TestClass(new new TestClass(new MySqlPoolConnection(mysqlPoolConfig));
const users = test.get18YearsUsers();
console.log(users);
// [
//   {
//    id: 1,
//     username: 'risa',
//     age: 18,
//     createdAt: '2020/01/25',
//     updatedAt: '2020/01/25',
//   },
//  ...
// ]
const createdId = test.addUser('yuuki', 19);
console.log(createdId);
// 4