
Product
Announcing Precomputed Reachability Analysis in Socket
Socket’s precomputed reachability slashes false positives by flagging up to 80% of vulnerabilities as irrelevant, with no setup and instant results.
mysql-bricks
Advanced tools
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.
Requires Node.js V6+ and ECMAScript 6 to run
$ npm install mysql-bricks
see sql-bricks documentation for common SELECT, INSERT, UPDATE and DELETE functionality. Below are examples of usage for the MySQL-specific functionality:
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
*/
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)
*/
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
*/
let query = sql.select().from('main.some_table').limit(100).offset(50).toString();
/*
SELECT * FROM main.some_table LIMIT 100 OFFSET 50
*/
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
*/
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!
FAQs
sql-bricks extension for MySQL
The npm package mysql-bricks receives a total of 909 weekly downloads. As such, mysql-bricks popularity was classified as not popular.
We found that mysql-bricks demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket’s precomputed reachability slashes false positives by flagging up to 80% of vulnerabilities as irrelevant, with no setup and instant results.
Product
Socket is launching experimental protection for Chrome extensions, scanning for malware and risky permissions to prevent silent supply chain attacks.
Product
Add secure dependency scanning to Claude Desktop with Socket MCP, a one-click extension that keeps your coding conversations safe from malicious packages.