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 🙏

© 2024 – Pkg Stats / Ryan Hefner

mysqlb

v1.0.1

Published

The library includes a set of simple methods for quickly constructing queries to the database

Downloads

2

Readme

mysqlb

Environments

  • node.js (>=8)

Usage

The simple mysql query builder. The library includes a set of simple methods for quickly constructing queries to the database. Syntax is similar to laravel query builder.

Get started

Create connection and new query builder instance

  const Builder = require('mysqlb')
  // create new Builder instance
  const builder = new Builder({
    host: 'localhost',
    port: '3306',
    user: 'root',
    password: 'root',
    database: 'test'
  })

The connection will be established automatically before first query execution. To force closing connection, use:

  builder.closeConnection(function (err) {
    // connection is closed
  })

Insert syntax

  const users = builder.use('users')
  users.create({
    name: 'John',
    email: '[email protected]'
  },
  false, // update on duplicate keys
  function (err, data) {
    // item is created
  })

Update syntax

  const users = builder.use('users')
  users.where('id', '=', 4)
  users.update({
    name: 'Johny',
    email: '[email protected]'
  },
  function (err, data) {
    // item is updated
  })

Delete syntax

  const users = builder.use('users')
  users.where('id', '=', 4)
  users.delete(function (err, data) {
    // item is deleted
  })

Where conditions

  const users = builder.use('users')
  // WHERE id
  users.where('id', '=', 4)
  // WHERE id IN
  users.whereIn('id', [1, 3, 5, 9])
  // WHERE name LIKE
  users.like('name', '%ohn%')
  // raw WHERE
  user.whereRaw('id=?', [4])

Join tables

  const users = builder.use('users')
  // LEFT JOIN
  users.leftJoin('professions', 'profession_id', 'id')
  // RIGHT JOIN
  users.rightJoin('professions', 'profession_id', 'id')
  // INNER JOIN
  users.innerJoin('professions', 'profession_id', 'id')

Select custom fields

  const users = builder.use('users')
  // LEFT JOIN
  users.leftJoin('professions', 'profession_id', 'id')
  users.only(['users.*', 'professions.name as profession_name'])

Get count

  const users = builder.use('users')
  users.getCount(function (err, count) {
    // count
  })

Get first element

  const users = builder.use('users')
  users.getFirst(function (err, item) {
    // first item
  })

Find item by id

  const users = builder.use('users')
  users.find(4, function (err, item) {
    // item
  })

Get items

  const users = builder.use('users')
  users.get(function (err, items) {
    // items
  })

Order

  const users = builder.use('users')
  users.orderBy('id', 'desc')

Limit, offset

  const users = builder.use('users')
  users.limit(9).offset(2)

Paginator

  const users = builder.use('users')
  users.getPaginated(
    9, // items per page
    1, // page number
    function (err, paginator) {
      paginator.getItems() // get data from db
      paginator.getCountInPage() // count items per page
      paginator.getTotalPages() // count of pages
      paginator.getLastPage() // last page number
      paginator.getFirstPage() // first page number
      paginator.getPrevPage() // previous page number
      paginator.getNextPage() // next page number
      paginator.getCurrentPage() // current page number
    }
  )

Async methods

You can call all available methods as asycn. Just add 'async' to the end of your methods name.

Example:

  const users = builder.use('users')
  users.get(function (err, items) {
    // items
  })

Async example:

  const users = builder.use('users')
  const items = users.getAsync()