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

mockingbird-sql

v0.4.0

Published

SQL statement builder

Downloads

22

Readme

mockingbird-sql

SQL statement builder

NAME

mockingbird-sql - A simple SQL statement builder

SYNOPSIS

const sql = require('mockingbird-sql');

let s = sql.select().columns([
  'ColA',
  'ColB',
  'ColC',
]).from('tableA')
  .leftOuterJoin('tableB', 'tableA.ColB = tableB.ColB', 'aliasB')
  .where(
    sql.and(
      'tableA.ColA like \'%value%\'',
      sql.lt('aliasb.ColX', 27)
    )
  ).orderBy('ColA');

let query = sql.mysql.MySql.toSql(s);

// query.sql    => SQL statement
// query.values => list of arguments

DESCRIPTION

This module exports several kinds of functions useful for building complex SQL queries programmatically.

The major class are constructors for SQL statement objects. Another is functions for building SQL expressions. The third is classes for converting the statement objects into SQL suitable for passing to database drivers in order to execute the query.

SQL Statement Objects

Currently, two statements are supported: SELECT and UNION. Others can be added as necessary.

SELECT

Constructor: module.select(): SELECT statement object

Methods:

All methods return the this object, to allow chaining.

  • s.columns( columns )

  • s.distinct( bool )

  • s.from( table, alias )

  • s.join( table, on, _alias )

  • s.where( expression )

    • s.whereAnd( expression )

    • s.whereOr( expression )

  • s.groupBy( column )

  • s.orderBy( column, direction )

  • s.limit( rows )

  • s.offset( _rows )

  • s.window( offset, limit )

UNION

Constructor: module.union(): UNION statement object

Methods:

  • u.add( statements )

  • u.orderBy( column, direction )

  • u.limit( rows )

  • u.offset( _rows )

  • u.window( offset, limit )

Expressions

Logical operators

  • module.and( expression, expression )

  • module.or( expression, expression )

  • module.not( expression, expression )

Unary operators

  • module.isNull( expression )

  • module.isNotNull( expression )

Binary operators

  • module.op( column, value )

Operators are:

  • eq
  • neq
  • gt
  • lt
  • gteq
  • lteq
  • like
  • in

Trinary Operators

  • module.between( column, left-value, right-value )

  • module.notBetween( column, left-value, right-value )

Case operator

  • module.case( expression )

The Case object has a number of methods:

  • c.when( expression, result = null )

    If result is null, use the then method below to specifiy the result of the branch.

  • c.then( result )

  • c.else( result )

Conversion

This module is intended to support any (semi-) standardized SQL. Currently, it supports MySQL. The currently supported options are:

MySQL

Conversion of a generated statement to MySQL is handled by the mysql.MySQL object. Methods on this object are:

  • mysql.MySQL.toSql( statement )

    This method returns an object containing two keys:

    • sql: A string representation of the SQL query, with placeholders for parameters.
    • values: A list of arguments for the query.

Oracle

Conversion to Oracle SQL is handled by oracle.Oracle object. The methods are the same as MySQL above.