forked from darold/pgFormatter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME
122 lines (86 loc) · 4.42 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
ABSTRACT
pgFormatter - PostgreSQL SQL syntax beautifier
DESCRIPTION
This SQL formatter/beautifier supports keywords from SQL-92, SQL-99,
SQL-2003, SQL-2008, SQL-2011 and PostgreSQL specifics keywords. May
works with any other databases too.
pgFormatter can work as a console program or as a CGI. It will
automatically detect his environment and output as text or as HTML
following the context.
Keywords highlighting will only be available in CGI context.
Terminal/console execution
Usage: pg_format [options] file.sql [...]
PostgreSQL SQL queries and PL/PGSQL code beautifier.
Arguments:
file.sql can be a file or use - to send a query using stdin. Use a single
dot in a line to terminate the stdin input or EOF.
Returning the SQL formatted to stdout or into a file specified with the
-o | --output option.
Options:
-a | --anonymize : obscure all literals in queries, useful to hide
confidential data before formatting.
-d | --debug : enable debug mode. Disabled by default.
-f | --function-case N: Change the case of the reserved keyword. Default is
unchanged: 0. Values: 0=>unchanged, 1=>lowercase,
2=>uppercase, 3=>capitalize.
-h | --help : show this message and exit.
-m | --maxlength SIZE : maximum length of a query, it will be cut above
the given size. Default: no truncate.
-n | --nocomment : remove any comment from SQL code.
-o | --output file : define the filename for the output. Default: stdout.
-s | --spaces size : change space indent, default 4 spaces.
-u | --keyword-case N : Change the case of the reserved keyword. Default is
uppercase: 2. Values: 0=>unchanged, 1=>lowercase,
2=>uppercase, 3=>capitalize.
-v | --version : show pg_format version and exit.
Examples:
cat samples/ex1.sql | /usr/local/bin/pg_format -
/usr/local/bin/pg_format -n samples/ex1.sql
/usr/local/bin/pg_format -f 2 -n samples/ex1.sql -o result.sql
CGI context
Install pg_format into your cgi-bin folder, grant execution on it as a
CGI script (maybe you should add the .cgi extension) and get it from
your favorite browser.
You have a live example without limitation than ten thousand characters
in your SQL query here:
http://sqlformat.darold.net/
pg_format will automatically detected that it is running in a CGI
environment and will output all html code needed to run an online code
formatter site. There's nothing more to do.
INSTALLATION
Download the tarball from github and unpack the archive as follow:
tar xzf pgFormatter-x.x.tar.gz
cd pgFormatter-x.x/
perl Makefile.PL
make && sudo make install
This will copy the Perl script pg_format in /usr/local/bin/pg_format
directory by default and the man page into
/usr/local/share/man/man1/pg_format.1. Those are the default
installation directory for 'site' install.
If you want to install all under /usr/ location, use INSTALLDIRS='perl'
as argument of Makefile.PL. The script will be installed into
/usr/bin/pg_format and the manpage into /usr/share/man/man1/pg_format.1.
For example, to install everything just like Debian does, proceed as
follow:
perl Makefile.PL INSTALLDIRS=vendor
By default INSTALLDIRS is set to site.
HINTS
With pgFormat, you can just add the following line to your ~/.vimrc
file:
au FileType sql setl formatprg=/usr/local/bin/pg_format\ -
This lets your gq commands use pgFormat automagically. For example if
you are on the first line, typing:
ESC+gq+G
will format the entire file.
ESC+gq+2j
will format the next two line.
Thanks to David Fetter for the hint.
AUTHORS
pgFormatter is an original work from Gilles Darold
COPYRIGHT
Copyright 2012-2015 Gilles Darold. All rights reserved.
LICENSE
pgFormatter is free software distributed under the PostgreSQL Licence.
A modified version of the SQL::Beautify Perl Module is embedded in
pgFormatter with copyright (C) 2009 by Jonas Kramer and is published
under the terms of the Artistic License 2.0.