Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
pg-minify is an npm package designed to minify SQL queries. It removes unnecessary whitespace, comments, and other non-essential elements from SQL code, making it more compact and potentially improving performance when sending queries to a PostgreSQL database.
Minify SQL Queries
This feature allows you to minify a given SQL query by removing unnecessary whitespace and comments. The example demonstrates how to use pg-minify to minify a simple SQL query.
const pgMinify = require('pg-minify');
const sql = 'SELECT * FROM users WHERE id = $1; -- Get user by ID';
const minifiedSQL = pgMinify(sql);
console.log(minifiedSQL); // Outputs: 'SELECT * FROM users WHERE id=$1;'
Error Handling
pg-minify provides error handling capabilities to catch and handle any issues that arise during the minification process. The example shows how to wrap the minification process in a try-catch block to handle potential errors.
const pgMinify = require('pg-minify');
try {
const sql = 'SELECT * FROM users WHERE id = $1; -- Get user by ID';
const minifiedSQL = pgMinify(sql);
console.log(minifiedSQL);
} catch (error) {
console.error('Error minifying SQL:', error);
}
sql-minify is another npm package that offers similar functionality to pg-minify. It focuses on reducing the size of SQL queries by removing unnecessary whitespace and comments. However, it may not be as optimized for PostgreSQL-specific syntax as pg-minify.
sql-formatter is a package that primarily focuses on formatting SQL queries to improve readability. While it can also minify SQL by removing unnecessary elements, its main purpose is to beautify SQL code, making it somewhat different from pg-minify, which focuses solely on minification.
Minifies PostgreSQL scripts, reducing the IO usage.
Features:
/*multi-line*/
(including nested) and --single-line
comments/*!
\n
E
where needed$ npm install pg-minify
const minify = require('pg-minify');
const sql = 'SELECT 1; -- comments';
minify(sql); //=> SELECT 1;
with compression (removes all unnecessary spaces):
const sql = 'SELECT * FROM "table" WHERE col = 123; -- comments';
minify(sql, {compress: true});
//=> SELECT*FROM"table"WHERE col=123;
The library's distribution includes TypeScript declarations.
SQLParsingError is thrown on failed SQL parsing:
try {
minify('SELECT \'1');
} catch (error) {
// error is minify.SQLParsingError instance
// error.message:
// Error parsing SQL at {line:1,col:8}: Unclosed text block.
}
Minifies SQL into a single line, according to the options
.
Compresses / uglifies the SQL to its bare minimum, by removing all unnecessary spaces.
false (default)
- keeps minimum spaces, for easier readtrue
- removes all unnecessary spacesSee also: SQL Compression.
Removes everything, i.e. special/copyright multi-line comments that start with /*!
will be removed as well.
Double-dollar $$
string escaping, which avoids escaping single quotes is not supported.
See issue #12.
Copyright © 2020 Vitaly Tomilov; Released under the MIT license.
FAQs
Minifies PostgreSQL scripts.
The npm package pg-minify receives a total of 299,151 weekly downloads. As such, pg-minify popularity was classified as popular.
We found that pg-minify demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers 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.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.