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

mysql-simple-query

v1.0.25

Published

Simple query wrapper for mysql-promise to make querying, inserting, updating, and deleting easier for developers.

Downloads

51

Readme

MySQL Simple Query

Build Status

Simple mysql query builder to make querying, inserting, updating, and deleting easier for developers. This library can be used with any mysql library.


This library takes the annoyance out of writing raw MySQL queries in Javascript. The queries are easy to read in your code and easy to build complex queries.

Install

npm install --save mysql-simple-query

List of features

Configuring

All calls need to be have a reference to the mysql-simple-query class.

const mysqlQuery = require("mysql-simple-query");

const db = new mysqlQuery();

Querying

Query with basic select from and where

db.select('id, name');
db.from('users');
db.where('name', 'foo');

const results = db.query();

results.then(function(result) {
   console.log(result);
});

If Select * is needed you can leave off the db.select and it will be defaulted.

Query with select, from, join, and where

db.select('id, name');
db.join('table', 'abc = def');
db.from('users');
db.where('name', 'foo');

const results = db.query();

results.then(function(result) {
   console.log(result);
});

The above example will produce an INNER JOIN. There can be multiple db.join and db.where to chain them together.

db.select('id, name');
db.join('table', 'abc = def');
db.join('table2', 'abc = def');
db.from('users');
db.where('id', '123');
db.where('name', 'foo');

const results = db.query();

results.then(function(result) {
   console.log(result);
});

Other querying parameters

db.groupBy('item');
db.orderBy('item', 'ACS');
db.limit(1);

Inserting

/**
 * @param {string} table    Name of the database table to insert into
 * @param {object} data     data to insert into the database
 * @returns {promise}
 */
const results = db.insert('users_table', {
    'name': 'foo bar',
    'department': 'engineering',
    'datetime': '2019-08-27 03:11:06'
});

results.then(function(result) {
   console.log(result);
});

Updating

/**
 * @param {string} table    Name of the database table to update
 * @param {object} data     data to update into the database
 * @returns {promise}
 */
const results = db.update('users_table', {
    'name': 'foo bar',
    'department': 'engineering',
    'datetime': '2019-08-27 03:11:06'
});

results.then(function(result) {
   console.log(result);
});

Deleting

db.where('name', 'foo');
db.delete('users');

Raw Query

If you need to pass in your own custom query into mysql-promise you can do so by calling the following.

const results = db.queryRaw('SELECT * FROM TABLE...');

Component Definitions

db.select()

/**
 * @param {string} select string    Comma seperated list
 * @returns {promise}
 */
db.select('id','name','department');

db.from()

/**
 * @param {string} table_name
 * @returns {promise}
 */
db.from('users');

db.where()

These calls can be chained together to form multiple where statements.

/**
 * @param {string} key
 * @param {string} value
 * @returns {promise}
 */
db.where('name','foo');
db.where('deparment','engineering');

db.join()

This will produce an INNER JOIN. These calls can be chained together to form multiple join statements.

/**
 * @param {string} key
 * @param {string} value
 * @returns {promise}
 */
db.join('table', 'item = item2');

db.groupBy()

/**
 * @param {string} key
 * @returns {promise}
 */
db.groupBy('key');

db.orderBy()

/**
 * @param {string} key
 * @param {ENUM} order ASC or DESC
 * @returns {promise}
 */
db.orderBy('key', 'ASC');

db.limit()

/**
 * @param {int} number to limit by
 * @returns {promise}
 */
db.limit(1);

License

This project is licensed under the MIT License