You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+69-19Lines changed: 69 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,8 +1,18 @@
1
1
# readsql
2
2
3
-
Convert SQL to most human readable format
3
+
Convert SQL to most human readable format. For the time being it upper cases SQL keywords, it might prettify of even suggest improvements of SQL code in the future. It converts SQL code and even SQL-strings in programming languages (only Python at the moment).
4
4
5
-
It can convert SQL code and even SQL strings in other languages (only Python at the moment)
5
+
So if we write
6
+
7
+
```sql
8
+
select sushi, avg(price) from tokyo where ocean ='pacific'group by sushi
9
+
```
10
+
11
+
readsql will help us read it as
12
+
13
+
```sql
14
+
SELECT sushi, AVG(price) FROM tokyo WHERE ocean ='pacific'GROUP BY sushi
15
+
```
6
16
7
17
# Installation
8
18
@@ -12,34 +22,73 @@ It can convert SQL code and even SQL strings in other languages (only Python at
12
22
13
23
1. Format SQL code provided in command line
14
24
-`readsql <SQL_STRING> -s`
15
-
2. Format an SQL file
16
-
-`readsql <FILE_PATH>`
25
+
2. Format an SQL file or folder
26
+
- as in a folder, it will look for files ending with .sql or .py
27
+
-`readsql <FILE_OR_FOLDER_PATH>`
28
+
29
+
It supports multiple strings and files or folders as well
30
+
31
+
1.
32
+
```bash
33
+
readsql <SQL_STRING1><SQL_STRING2> -s
34
+
```
17
35
36
+
2. In Python files it looks for `query` strings and formats them
1.`readsql 'select sushi from tokyo' -s` command returns
49
+
-`SELECT sushi FROM tokyo`
50
+
51
+
2. a. `readsql sql_example.sql` command, while `sql_example.sql` is a SQL file with code as below,
52
+
```sql
53
+
selectmax(height), avg(mass), min(age) from jungle group by forest where animal=elephant;
54
+
```
55
+
replaces the file with this code
56
+
```sql
57
+
SELECTMAX(height), AVG(mass), MIN(age) FROM jungle GROUP BY forest WHERE animal=elephant;
58
+
```
59
+
60
+
2.c. `readsql sql_in_python_variable_example.py` command, while `sql_in_python_variable_example.py` is a Python file with code as below,
29
61
```python
30
62
defget_query():
31
63
limit =6
32
64
sql =f"SELEct speed from world where animal='dolphin' limit {limit}"
33
65
return sql
34
66
```
35
-
converts it to
67
+
replaces the file with this code
36
68
```python
37
69
defget_query():
38
70
limit =6
39
71
sql =f"SELECT speed FROM world WHERE animal='dolphin' LIMIT {limit}"
40
72
return sql
41
73
```
42
74
75
+
2.c. `readsql sql_in_python_variable_example.py -py sql` command, while `sql_in_python_variable_example.py` is a Python file with code as below,
76
+
```python
77
+
defget_query():
78
+
limit =6
79
+
sql =f"SELEct speed from world where animal='dolphin' limit {limit}"
80
+
return sql
81
+
```
82
+
replaces the file with this code
83
+
```python
84
+
defget_query():
85
+
limit =6
86
+
sql =f"SELECT speed FROM world WHERE animal='dolphin' LIMIT {limit}"
87
+
return sql
88
+
```
89
+
90
+
2.d. `readsql tests -n` command outputs all of the formated SQL code in `tests` folder, files are not replaced by the formatted version (`-n` argument stand for not-replace)
91
+
43
92
# Add a pre-commit hook
44
93
How to add a [pre-commit](https://pre-commit.com/) hook of readsql?
45
94
```yaml
@@ -51,12 +100,13 @@ repos:
51
100
```
52
101
53
102
# Development
54
-
Having the repo cloned
103
+
Having the repo cloned dig into
55
104
56
-
- `python readsql tests/sql_example.sql` converts example SQL code to easier readable format
57
-
- `python readsql tests/sql_in_python_example.py`converts example SQL code in Python (it looks for variables `query`)
58
-
- we can change the SQL variable with `-py` option `python readsql tests/sql_in_python_variable_example.py -py sql`
59
-
- `python readsql "select sushi from tokyo" -s`takes the `"select sushi from tokyo"` string as input and outputs it formatted
105
+
- `python -m readsql "select sushi from tokyo" -s` takes the `"select sushi from tokyo"` string as input and outputs it formatted
106
+
- `python -m readsql tests/sql_example.sql`converts example SQL code to easier readable format
107
+
- `python -m readsql tests/sql_in_python_example.py`converts example SQL code in Python (it looks for variables `query`)
108
+
- we can change the SQL variable with `-py` option `python -m readsql tests/sql_in_python_variable_example.py -py sql`
109
+
- `python -m readsql tests`formats all Python and SQL files in `tests` folder
0 commit comments