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

@hoangnguyennn/mysql-builder

v0.0.1

Published

Support building MySQL statements

Readme

MySQL Builder

Support building MySQL statements

Table of contents

Example Usage

const Post = new Model('posts')
Post.all() //  select * from `posts`
Post.where('id', 1).exec() // select * from `posts` where `id` = 1

API

Model

Model.prototype.all()

Return a query that retrieves all the records in the table

Return type: string

Post.all()
// select * from `posts`

Model.prototype.get()

Same as all() method

Return type: string

Post.get()
// select * from `posts`

Model.prototype.first()

Return a query that retrieves the first record in the table.

Return type: string

Post.first()
// select * from `posts` limit 1

Model.prototype.limit(value)

Specifies the maximum number of records the query will return.

Parameters:

  • value (number): The number of records will return

Return type: Query

const query = Post.limit(10)

query.exec()
// select * from `posts` limit 10

Model.prototype.offset(value)

Specifies the number of records the query will skip.

Parameters:

  • value (number): The number of records will skip

Return type: Query

const query = Post.limit(10).offset(20)

query.exec()
// select * from `posts` limit 10 offset 20

Model.prototype.orderBy(key, [direction])

Sort query result in ascending or descending order

Parameters:

  • key (string): The specified column name to sort
  • direction (Direction, optional): Sort direction (asc or desc). Default is asc

Return type: Query

const query = Post.orderBy('title', 'desc')

query.exec()
// select * from `posts` order by `title` desc

Model.prototype.select(...keys)

Specifies which column is selected

Parameters:

  • ...keys (string[]): The list of columns to select

Return type: Query

const query = Post.select('id', 'title')

query.exec()
// select `id`, `title` from `posts`

Model.prototype.select(keys)

Specifies which column is selected

Parameters:

  • keys (string[]): The list of columns to select

Return type: Query

const query = Post.select(['id', 'title'])

query.exec()
// select `id`, `title` from `posts`

Model.prototype.select(key)

Specifies which column is selected

Parameters:

  • key (string): The column to select

Return type: Query

const query = Post.select(['title'])

query.exec()
// select `title` from `posts`

Model.prototype.where(key, operator, value)

Add condition to filter records

Parameters

Depending on the operator, the value takes a different type. As follows:

Return type: Query

/*** EXAMPLE 1 ***/
const query = Post.where('title', '=', 'test')

query.exec()
// select * from `posts` where `title` = 'test'

/*** EXAMPLE 2 ***/
const query = Post.where('title', 'in', ['test', 'test2'])

query.exec()
// select * from `posts` where `title` in ('test', 'test2')

/*** EXAMPLE 3 ***/
const query = Post.where('views', 'between', [100, 200])

query.exec()
// select * from `posts` where `views` between 100 and 200

Model.prototype.where(key, value)

Add condition to filter records. The operator is =

Parameters

  • key (string): The column to use for filtering
  • value (AlphaNumeric): The value to use for filtering

Return type: Query

Model.prototype.where(fn)

Sometimes you want to group several where clauses with parentheses, passing a parameter is a method, it will do it

const query = Post.where('id', 1).where((q) => {
  q.where('title', 'test').orWhere('title', 'test2')
})

query.exec()
// select * from `posts` where `id` = 1 and (`title` = 'test' or `title` = 'test2')

Model.prototype.whereIn(key, values)

Add condition to filter records. The operator is in

Parameters

  • key (string): The column to use for filtering
  • value (AlphaNumeric[]): The value to use for filtering

Return type: Query

Model.prototype.whereNotIn(key, values)

Add condition to filter records. The operator is not in

Parameters

  • key (string): The column to use for filtering
  • value (AlphaNumeric[]): The value to use for filtering

Return type: Query

Query

Query.prototype.exec()

Query.prototype.get()

Query.prototype.first()

Query.prototype.limit(value)

Query.prototype.offset(value)

Query.prototype.orderBy(key, direction = 'asc')

Query.prototype.orWhere(fn)

Query.prototype.orWhere(key, operator, value)

Query.prototype.orWhere(key, value)

Query.prototype.select(...keys)

Query.prototype.select(keys)

Query.prototype.select(key)

Query.prototype.where(fn)

Query.prototype.where(key, operator, value)

Query.prototype.where(key, value)

Query.prototype.whereIn(key, values)

Query.prototype.whereNotIn(key, values)

Interfaces

Direction

asc | desc

AlphaNumeric

string | number

Operator

InOperator | RangeOperator | ComparisonOperator | LikeOperator

InOperator

in | not in

RangeOperator

between | not between

ComparisonOperator

= | != | < | <= | > | >=

LikeOperator

like | not like