-
Notifications
You must be signed in to change notification settings - Fork 2
Home
Vitaly Tomilov edited this page Jan 31, 2016
·
19 revisions
This library can correctly minify and compress a PostgreSQL script of any size or complexity, including text blocks with line breaks and tabs in them, as shown in the examples below.
UPDATE test
SET values = 'one
two
three';
are concatenated with \n
, injecting E
in front, if it is not there:
UPDATE test SET values = E'one\ntwo\nthree';
Also, the first string is trimmed on the right (removing tabs and spaces), the last one is trimmed on the left, and all strings in between are trimmed on both sides.
SELECT ' first second third '
are replaced with \t
, injecting E
in front, if it is not there:
SELECT E'\tfirst\tsecond\tthird\t'
With the help of this library you can focus on implementing and documenting your queries as external files:
/*
Test query that inserts a whole text document.
*/
INSERT INTO documents (id, content)
VALUES (${id}, -- inserting a whole text document here:
'
Text starts with a line break,
with a tab inside text: ,
ending with another line break.
');
that will be minified into a single-line query:
INSERT INTO documents (id, content) VALUES (${id}, E'\nText starts with a line break,
\nwith a tab inside text:\t,\nending with another line break.\n');
or even shorter, with option compress set:
INSERT INTO documents(id,content)VALUES(${id},E'\nText starts with a line break,
\nwith a tab inside text:\t,\nending with another line break.\n');