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

@queenzeinaproductions/mysql-bricks

v1.1.3

Published

sql-bricks extension for MySQL

Downloads

132

Readme

mysql-bricks

sql-bricks extension for MySQL

mysql-bricks is an extension to the awesome sql-bricks library, that helps generate SQL statements for MySQL DB. It adds MySQL specific functions and formatting on top of the sql-bricks functionality.

Installation

Requires Node.js V6+ and ECMAScript 6 to run

$ npm install mysql-bricks

Usage

see sql-bricks documentation for common SELECT, INSERT, UPDATE and DELETE functionality. Below are examples of usage for the MySQL-specific functionality:

INSERT ... ON DUPLICATE KEY UPDATE ...

let values = [[123, 'Daniel', 41, 92], [456, 'David', 34, 87], [789, 'Rachel', 22, 98]];  
let query = sql.insert('main.some_table', 'id', 'name', 'age', 'grade')
                .values(values)
                .onDuplicateKeyUpdate(['grade'])
                .toString();
/*                
INSERT INTO main.some_table (id, name, age, grade)
VALUES (123, \'Daniel\', 41, 92),  (456, \'David\', 34, 87), (789, \'Rachel\', 22, 98)
ON DUPLICATE KEY UPDATE grade = VALUES(grade)
*/

ON DUPLICATE KEY UPDATE clause can also contain a column-value pair, where the value is a free text sql.
Note that free-text sql will not be automatically quoted if it contains reserved words.

let values = [[123, 'Daniel', 41, 92, 0], [456, 'David', 34, 87, 0], [789, 'Rachel', 22, 98, 0]];  
let query = sql.insert('main.some_table', 'id', 'name', 'age', 'grade', 'counter')
                .values(values)
                .onDuplicateKeyUpdate(['age', 'grade', { counter: 'counter + 1' }])
                .toString();
/*                
INSERT INTO main.some_table (id, name, age, grade, counter)
VALUES (123, \'Daniel\', 41, 92, 0),  (456, \'David\', 34, 87, 0), (789, \'Rachel\', 22, 98, 0)
ON DUPLICATE KEY UPDATE age = VALUES(age), grade = VALUES(grade), counter = counter + 1
*/

INSERT IGNORE ...

let values = [[123, 'Daniel', 41, 92], [456, 'David', 34, 87], [789, 'Rachel', 22, 98]];  
let query = sql.insert('main.some_table', 'id', 'name', 'age', 'grade')
                .ignore()
                .values(values)
                .toString();
/*                
INSERT IGNORE INTO main.some_table (id, name, age, grade)
VALUES (123, \'Daniel\', 41, 92),  (456, \'David\', 34, 87), (789, \'Rachel\', 22, 98)
*/

LIMIT (SELECT / UPDATE / DELETE)

let query = sql.select().from('main.some_table').limit(100).toString();
/*                
SELECT * FROM main.some_table LIMIT 100
*/

MySQL supports optional 'limit' clause in UPDATE and DELETE queries:

let query = sql.delete('main.some_table').limit(100).toString();
/*                
DELETE FROM main.some_table LIMIT 100
*/

OFFSET

let query = sql.select().from('main.some_table').limit(100).offset(50).toString();
/*                
SELECT * FROM main.some_table LIMIT 100 OFFSET 50
*/

ORDER BY (UPDATE / DELETE)

MySQL supports optional 'order by' clause in UPDATE and DELETE queries:

let query = sql.update('main.some_table', { grade: 90})
                .where(sql.gt('grade', 90))
                .orderBy('age desc')
                .limit(100)
                .toString();
/*                
UPDATE main.some_table SET grade = 90 WHERE grade > 90 ORDER BY age desc LIMIT 100
*/

REGEXP (WHERE)

let query = sql.select().from('main.some_table').where(regexp('name', '^D')).limit(100).offset(50).toString();
/*                
SELECT * FROM main.some_table WHERE name REGEXP '^D' LIMIT 100 OFFSET 50
*/

Contribute

Supported MySQL specific functions are the most common ones as used by me, but if you find something missing - feel free to open an issue, or better yet - a pull request!