1.6.4 • Published 18 days ago

pg-minify v1.6.4

Weekly downloads
183,052
License
MIT
Repository
github
Last release
18 days ago

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.

1.6.4

18 days ago

1.6.3

1 year ago

1.6.2

3 years ago

1.6.1

4 years ago

1.6.0

4 years ago

1.5.2

4 years ago

1.5.1

5 years ago

1.5.0

5 years ago

1.4.1

5 years ago

1.4.0

5 years ago

1.3.0

5 years ago

1.2.6

5 years ago

1.2.5

5 years ago

1.2.4

5 years ago

1.2.3

5 years ago

1.2.2

5 years ago

1.2.1

5 years ago

1.2.0

5 years ago

1.1.0

5 years ago

1.0.0

5 years ago

0.5.5

6 years ago

0.5.4

6 years ago

0.5.3

7 years ago

0.5.2

7 years ago

0.5.1

7 years ago

0.5.0

7 years ago

0.4.5

7 years ago

0.4.4

7 years ago

0.4.3

7 years ago

0.4.2

7 years ago

0.4.1

7 years ago

0.4.0

7 years ago

0.3.5

7 years ago

0.3.4

7 years ago

0.3.3

8 years ago

0.3.2

8 years ago

0.3.1

8 years ago

0.3.0

8 years ago

0.2.5

8 years ago

0.2.4

8 years ago

0.2.2

8 years ago

0.2.1

8 years ago

0.2.0

8 years ago

0.1.5

8 years ago

0.1.4

8 years ago

0.1.3

8 years ago

0.1.2

8 years ago

0.1.1

8 years ago

0.1.0

8 years ago

0.0.5

8 years ago

0.0.4

8 years ago

0.0.3

8 years ago

0.0.2

8 years ago

0.0.1

8 years ago