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 🙏

© 2025 – Pkg Stats / Ryan Hefner

mysql-qb

v0.9.0

Published

MySQL query builder

Readme

MySQL Query builder

Build Status npm version codecov

Designed to make SQL-queries easier to use. With this builder you don't have to write raw-queries. In this version you can build simple SQL-queries: SELECT (with joins), CREATE, UPDATE, DELETE.

I'm using this builder for my projects so it updates few times a week. It is not stable for now and very young. v1.0 release is planned for September 1st.

Contents

Changelog

Unreleased (roadmap)

  • INSERT ... SELECT
  • 0.7.3 - Added UNION, LIMIT by default is empty array, Fixed tests
  • 0.7.2 - Fixes and new features in where. Updated MySQL adapter
  • Details

Usage example

More detailed usage:

As builder

var conn = require('mysql');
conn.connect();

var qb = require('mysql-qb');

var SQL = qb.select('id, name')
            .from('my_table')
            .where('id', 5)
            .build();
conn.query(SQL, function(error, rows){
  // ... Data processing
});

As builder and executor

Passing db config

You can pass config in nodejs mysql format: More info on mysql package page. Query builder will create new connection and execute query.

var config = {
  host: '127.0.0.1',
  user: 'root',
  password: 'mySecurePassword123',
  database: 'MyDB'
};

var QueryBuilder = require('mysql-qb');
var mqb = new QueryBuilder(config);

// Query builder unlike the mysql module returns Promise. Not a callback
var query = mqb.select('id, name')
            .from('my_table')
            .where('id', 5)
            .exec();

query.then( result => {
  console.log('DB result: ', result);
}).catch(error => {
  console.log('DB error: ', error);
})

Passing db connection

You can pass to constructor mysql module connection object instead of config. If connection state == 'disconnected' builder will try to get config from connection object and reconnect automatically.

var config = {
  host: '127.0.0.1',
  user: 'root',
  password: 'mySecurePassword123',
  database: 'MyDB'
};
var mysql = require('mysql');
var connection = mysql.createConnection(config);
connection.connect();

var QueryBuilder = require('mysql-qb');
var mqb = new QueryBuilder(connection); // Passing connection.

// Query builder unlike the mysql module returns Promise. Not a callback
var query = mqb.select('id, name')
            .from('my_table')
            .where('id', 5)
            .exec();

query.then( result => {
  console.log('DB result: ', result);
}).catch(error => {
  console.log('DB error: ', error);
})

Commands

Order of method calls in pipeline doesn't matter. They all return this so you can use them UNTIL build() method is called. After that query is immutable.

Method build() returns a string and pushes last query in queries array, so you can always get it by lastQuery() call.

All methods are described in the Methods API docs.

Installation

npm install --save mysql-qb

Tests

To run tests — where they are belong (tests/unit folder).