Socket
Socket
Sign inDemoInstall

pg-minify

Package Overview
Dependencies
0
Maintainers
1
Versions
53
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    pg-minify

Minifies PostgreSQL scripts.


Version published
Weekly downloads
359K
decreased by-2.42%
Maintainers
1
Install size
13.7 kB
Created
Weekly downloads
 

Readme

Source

pg-minify

Build Status Node Version

Minifies PostgreSQL scripts, reducing the IO usage.

Features:

  • Removes /*multi-line*/ (including nested) and --single-line comments
  • Preserves special/copyright multi-line comments that start with /*!
  • Concatenates multi-line strings into a single line with \n
  • Fixes multi-line text, prefixing it with E where needed
  • Removes redundant line gaps: line breaks, tabs and spaces
  • Provides basic parsing and error detection for invalid SQL
  • Flattens the resulting script into a single line
  • Optionally, compresses SQL for minimum space

Installing

$ npm install pg-minify

Usage

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.

Error Handling

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.
}

API

minify(sql, [options]) ⇒ String

Minifies SQL into a single line, according to the options.

options.compress ⇒ Boolean

Compresses / uglifies the SQL to its bare minimum, by removing all unnecessary spaces.

  • false (default) - keeps minimum spaces, for easier read
  • true - removes all unnecessary spaces

See also: SQL Compression.

options.removeAll ⇒ Boolean

Removes everything, i.e. special/copyright multi-line comments that start with /*! will be removed as well.

Testing

First, clone the repository and install DEV dependencies.

$ npm test

Testing with coverage:

$ npm run coverage

License

Copyright © 2020 Vitaly Tomilov; Released under the MIT license.

Keywords

FAQs

Last updated on 06 Apr 2024

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc