diff --git a/docs/core.html b/docs/core.html index 70db96c..f74f1db 100644 --- a/docs/core.html +++ b/docs/core.html @@ -3727,6 +3727,20 @@

format_from +
+ +
+ +
+
from   table1
+
+
+
+ +
+ + {% endraw %} @@ -3782,6 +3796,20 @@

format_join +
+ +
+ +
+
    inner join table1
+
+
+
+ +
+ + {% endraw %} @@ -3842,6 +3870,20 @@

format_on +
+ +
+ +
+
        on a.asdf = b.asdf /* some comment */
+
+
+
+ +
+ + {% endraw %} @@ -3865,6 +3907,21 @@

format_on +
+ +
+ +
+
        on a.asdf = b.asdf and
+           a.qwer = b.qwer
+
+
+
+ +
+ + {% endraw %} @@ -3889,6 +3946,22 @@

format_on +
+ +
+ +
+
        on a.asdf = b.asdf and
+           a.qwer = b.qwer or
+           a.qwer2 = b.qwer2
+
+
+
+ +
+ + {% endraw %} @@ -3920,6 +3993,22 @@

format_on +
+ +
+ +
+
        on a.asdf = b.asdf and -- some comment
+           a.qwer = b.qwer or /* another comment */
+           a.qwer2 = b.qwer2
+
+
+
+ +
+ + {% endraw %} @@ -3979,6 +4068,22 @@

format_where +
+ +
+ +
+
WHERE  asdf = 1
+   and qwer = 1
+    or blabla = 'asdf'
+
+
+
+ +
+ + {% endraw %} @@ -4000,6 +4105,22 @@

format_where +
+ +
+ +
+
WHERE  asdf = 1 -- and some comment
+   and qwer = 1
+    or blabla = 'asdf'
+
+
+
+ +
+ + {% endraw %} @@ -4021,6 +4142,22 @@

format_where +
+ +
+ +
+
WHERE  asdf = 1 -- and some comment
+   and qwer = 1
+    or blabla = 'asdf'
+
+
+
+ +
+ + {% endraw %} @@ -4081,6 +4218,21 @@

format_statement_line +
+
+ +
+ +
+
select asdf,
+       qwer
+
+
+
+ +
+
+ {% endraw %} @@ -4101,6 +4253,20 @@

format_statement_line +
+
+ +
+ +
+
    left join table1 as abc
+
+
+
+ +
+
+ {% endraw %} @@ -4125,6 +4291,23 @@

format_statement_line +
+
+ +
+ +
+
where  asdf = 1
+   and qwer = 'things'
+   and blabla = 0
+    or stuff = -1
+
+
+
+ +
+
+ {% endraw %} @@ -4181,6 +4364,22 @@

format_statements +
+
+ +
+ +
+
select asdf,
+       qwer
+from   table1
+
+
+
+ +
+
+ {% endraw %} @@ -4287,6 +4486,23 @@

add_semicolon +
+ +
+ +
+
CREATE OR REPLACE TABLE my_table AS
+SELECT asdf,
+       qwer
+FROM   table1; /* something */
+
+
+
+ +
+ + {% endraw %} @@ -4317,6 +4533,23 @@

add_semicolon +
+ +
+ +
+
CREATE OR REPLACE TABLE my_table AS
+SELECT asdf,
+       qwer
+FROM   table1; -- some thing
+
+
+
+ +
+ + {% endraw %} @@ -4347,6 +4580,23 @@

add_semicolon +
+ +
+ +
+
CREATE OR REPLACE TABLE my_table AS
+SELECT asdf,
+       qwer
+FROM   table1;
+
+
+
+ +
+ + {% endraw %} @@ -4406,6 +4656,45 @@

format_simple_sql +
+
+ +
+ +
+
CREATE OR REPLACE TABLE mytable AS -- Mytable example
+/* multi line
+   comment */
+SELECT a.asdf,
+       -- some line comment
+       b.qwer, -- some comment here
+       /* and here is a line comment inside select */
+       substr(c.asdf, 1, 2) as substr_asdf,
+       /* some commenT
+          there */
+       case when a.asdf = 1 then 'b' /* here a case comment */
+            when b.qwer = 2 then 'c'
+            else 'd' end as new_field, -- Some comment
+       /* and here some inline comment */
+       b.asdf2
+FROM   table1 as a
+    LEFT JOIN table2 as b -- and here a comment
+        ON a.asdf = b.asdf /* joiN this way */
+    INNER JOIN table3 as c
+        ON a.asdf = c.asdf and
+           a.qwer = b.qwer
+WHERE  a.asdf = 1 -- comment this
+   and b.qwer = 2
+   and a.asdf <= 1 --comment that
+    or b.qwer >= 5
+GROUP BY a.asdf
+
+
+
+ +
+
+ {% endraw %} @@ -4440,6 +4729,24 @@

format_simple_sql +
+
+ +
+ +
+
CREATE OR REPLACE TABLE first_table AS -- my first table
+SELECT car_id,
+       avg(price) as avg_price
+FROM   first_view
+GROUP BY car_id
+
+
+
+ +
+
+ {% endraw %} @@ -4575,6 +4882,32 @@

format_sql +
+ +
+ +
+
SELECT asdf,
+       cast(qwer as numeric), -- some comment
+       substr(qwer1, 3, 2) as substr_qwer /* some field */
+FROM   (SELECT asdf,
+               qwer /* some nice field */
+        FROM   table1
+        WHERE  asdf = 1) as a
+    LEFT JOIN (SELECT asdf,
+                      qwer2
+               FROM   table2
+               WHERE  qwer2 = 1) as b
+        ON a.asdf = b.asdf
+WHERE  qwer1 >= 0
+
+
+
+ +
+ + {% endraw %} @@ -4602,6 +4935,45 @@

format_sql +
+ +
+ +
+
CREATE OR REPLACE TABLE mytable AS -- Mytable example
+/* multi line
+   comment */
+SELECT a.asdf,
+       -- some line comment
+       b.qwer, -- some comment here
+       /* and here is a line comment inside select */
+       substr(c.asdf, 1, 2) as substr_asdf,
+       /* some commenT
+          there */
+       case when a.asdf = 1 then 'b' /* here a case comment */
+            when b.qwer = 2 then 'c'
+            else 'd' end as new_field, -- Some comment
+       /* and here some inline comment */
+       b.asdf2
+FROM   table1 as a
+    LEFT JOIN table2 as b -- and here a comment
+        ON a.asdf = b.asdf /* joiN this way */
+    INNER JOIN table3 as c
+        ON a.asdf = c.asdf and
+           a.qwer = b.qwer
+WHERE  a.asdf = 1 -- comment this
+   and b.qwer = 2
+   and a.asdf <= 1 --comment that
+    or b.qwer >= 5
+GROUP BY a.asdf
+
+
+
+ +
+ + {% endraw %} @@ -4682,6 +5054,32 @@

Nested subqueries +
+ +
+ +
+
SELECT asdf,
+       qwer
+FROM   (SELECT a.asdf,
+               lead(a.substr_qwer) OVER (PARTITION BY a.asdf,
+                                                      asdf2
+                                         ORDER BY qwer) as lead_qwerty
+        FROM   (SELECT asdf,
+                       substr(qwer, 3, 2) as substr_qwer
+                FROM   table2) as a
+            INNER JOIN (SELECT asdf,
+                               qwer
+                        FROM   table3) as b
+                ON a.qwer = b.qwer)
+
+
+
+ +
+ + {% endraw %} @@ -4718,6 +5116,24 @@

With SELECT DISTINCT +
+ +
+ +
+
SELECT asdf,
+       qwer
+FROM   (SELECT DISTINCT asdf,
+                        qwer
+        FROM   table1)
+
+
+
+ +
+ + {% endraw %} @@ -4798,6 +5214,29 @@

More convoluted nested subquery +
+
+ +
+ +
+
SELECT asdf
+FROM   (SELECT asdf,
+               qwer /* some comment */
+        FROM   (SELECT a.asdf,
+                       b.qwer --some comment
+                FROM   (SELECT asdf
+                        FROM   table1) as a
+                    RIGHT JOIN (SELECT qwer
+                                FROM   table2) as b
+                        ON a.asdf = b.asdf))
+
+
+
+ +
+
+ {% endraw %} @@ -4836,6 +5275,28 @@

More convoluted nested subquery +
+
+ +
+ +
+
SELECT asdf,
+       qwer
+FROM   table1
+UNION
+SELECT qwer,
+       asdf,
+       asdf2
+FROM   table3
+WHERE  asdf2 >= 2
+
+
+
+ +
+
+ {% endraw %} @@ -4876,6 +5337,25 @@

More convoluted nested subquery +
+
+ +
+ +
+
CREATE OR REPLACE TABLE asdf AS
+SELECT asdf,
+       qwer OVER (PARTITION BY asdf,
+                               qwer
+                  ORDER BY qwerty)
+FROM   table1
+
+
+
+ +
+
+ {% endraw %} @@ -4921,6 +5401,28 @@

More convoluted nested subquery +
+
+ +
+ +
+
CREATE OR REPLACE TABLE asdf AS
+SELECT asdf,
+       case when asdf in (123412341234, 12341234123412, 123412341234, 512351235132, 123412341,
+                          1234) then 1
+            else 0 end as qwerty,
+       qwer OVER (PARTITION BY asdf,
+                               qwer
+                  ORDER BY qwerty)
+FROM   table1
+
+
+
+ +
+
+ {% endraw %} diff --git a/docs/format_file.html b/docs/format_file.html index e4ddc99..1f5db1f 100644 --- a/docs/format_file.html +++ b/docs/format_file.html @@ -164,7 +164,7 @@

Main function to for
-

format_sql_commands[source]

format_sql_commands(s, max_len=82)

+

format_sql_commands[source]

format_sql_commands(s, max_len=82)

Format SQL commands in s. If SELECT line is longer than max_len then reformat line

@@ -820,7 +820,7 @@

Function to format 1 SQL file -

format_sql_file[source]

format_sql_file(f, max_len=82)

+

format_sql_file[source]

format_sql_file(f, max_len=82)

Format file f with SQL commands and overwrite the file. If SELECT line is longer than 82 characters then reformat line

@@ -1135,7 +1135,7 @@

Function to format many SQL files -

format_sql_files[source]

format_sql_files(files, recursive=False, max_len=82)

+

format_sql_files[source]

format_sql_files(files, recursive=False, max_len=82)

Format SQL files

@@ -1279,7 +1279,7 @@

format_sql_files -

format_sql_files_cli[source]

format_sql_files_cli()

+

format_sql_files_cli[source]

format_sql_files_cli()

Format SQL files

diff --git a/nbs/01_format_file.ipynb b/nbs/01_format_file.ipynb index 3e3f1d5..50ebac6 100644 --- a/nbs/01_format_file.ipynb +++ b/nbs/01_format_file.ipynb @@ -33,6 +33,7 @@ "import tempfile\n", "import argparse\n", "from glob import glob\n", + "import sql_formatter\n", "from sql_formatter.core import *\n", "from sql_formatter.utils import *\n", "from sql_formatter.validation import *" @@ -1175,6 +1176,12 @@ " type=int,\n", " default=82\n", " )\n", + " parser.add_argument(\n", + " \"-v\",\n", + " \"--version\",\n", + " action=\"version\",\n", + " version=f\"sql_formatter version {sql_formatter.__version__}\"\n", + " )\n", " args = parser.parse_args()\n", " format_sql_files(files=args.files, recursive=args.recursive, max_len=args.max_line_length)" ] diff --git a/settings.ini b/settings.ini index 947e531..ba62ab4 100644 --- a/settings.ini +++ b/settings.ini @@ -8,7 +8,7 @@ author = Pablo Rodriguez Mira author_email = rodriguez.mira.pablo@gmail.com copyright = Pablo Rodriguez Mira branch = master -version = 0.6.2 +version = 0.6.1 min_python = 3.6 audience = Developers language = English diff --git a/sql_formatter/__init__.py b/sql_formatter/__init__.py index 22049ab..43c4ab0 100644 --- a/sql_formatter/__init__.py +++ b/sql_formatter/__init__.py @@ -1 +1 @@ -__version__ = "0.6.2" +__version__ = "0.6.1" diff --git a/sql_formatter/format_file.py b/sql_formatter/format_file.py index 15ec678..f4bbcde 100644 --- a/sql_formatter/format_file.py +++ b/sql_formatter/format_file.py @@ -8,6 +8,7 @@ import tempfile import argparse from glob import glob +import sql_formatter from .core import * from .utils import * from .validation import * @@ -193,5 +194,11 @@ def format_sql_files_cli(): type=int, default=82 ) + parser.add_argument( + "-v", + "--version", + action="version", + version=f"sql_formatter version {sql_formatter.__version__}" + ) args = parser.parse_args() format_sql_files(files=args.files, recursive=args.recursive, max_len=args.max_line_length) \ No newline at end of file