niceql 0.1.21 → 0.1.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/CHANGELOG.md +3 -0
- data/README.md +34 -24
- data/lib/niceql.rb +11 -0
- data/lib/niceql/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b00aaefbdb5837f56163c43dfd8c3599add288f5d71e0df6aad33760771562bb
|
4
|
+
data.tar.gz: 06544b54f77cd4cc54a1b5b44ae8d1438bf57a9b6efc29c9408de7d35c75c8d9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5580c574b821e14a804252e7f2037341ca3e8c98d9b0b33d22057557cad29b4d1f4701773b2018a29183002280566861ccad962877b29bfcfda0db412d91f69b
|
7
|
+
data.tar.gz: 9d3ef9a43ab6b97e08c577521486e1b9c0151ba62848a47f096c0d31c521c0ff9b997795d3f8d62b78d4252ad8cd94fad8f8614032847dde5ad2f8fbc28cc830
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# Niceql
|
2
2
|
|
3
3
|
This is a small, nice, simple and dependentless solution for SQL prettifiyng for Ruby.
|
4
|
-
It can be used in an irb console without any dependencies ( run
|
4
|
+
It can be used in an irb console without any dependencies ( run bin/console and look for examples ).
|
5
5
|
|
6
6
|
Any reasonable suggestions on formatting/coloring are welcome
|
7
7
|
|
@@ -95,36 +95,46 @@ end
|
|
95
95
|
### Without ActiveRecord
|
96
96
|
|
97
97
|
```ruby
|
98
|
-
puts Niceql::Prettifier.prettify_sql("SELECT * FROM ( VALUES(1), (2) ) AS tmp")
|
99
98
|
|
100
|
-
|
101
|
-
|
102
|
-
|
99
|
+
puts Niceql::Prettifier.prettify_sql("SELECT * FROM ( VALUES(1), (2) ) AS tmp")
|
100
|
+
#=> SELECT *
|
101
|
+
#=> FROM ( VALUES(1), (2) ) AS tmp
|
102
|
+
|
103
|
+
puts Niceql::Prettifier.prettify_multiple("SELECT * FROM ( VALUES(1), (2) ) AS tmp; SELECT * FROM table")
|
104
|
+
|
105
|
+
#=> SELECT *
|
106
|
+
#=> FROM ( VALUES(1), (2) ) AS tmp;
|
107
|
+
#=>
|
108
|
+
#=> SELECT *
|
109
|
+
#=> FROM table
|
110
|
+
|
111
|
+
|
112
|
+
|
103
113
|
|
104
114
|
# rails combines err with query, so don't forget to do it yourself:
|
105
115
|
puts Niceql::Prettifier.prettify_pg_err( "#{pg_err_output}\n#{sql_query}" )
|
106
116
|
|
107
117
|
# to get real nice result you should execute prettified version (i.e. execute( prettified_sql ) !) of query on your DB!
|
108
118
|
# otherwise you will not get such a nice output
|
109
|
-
|
110
|
-
ERROR: VALUES in FROM must have an alias
|
111
|
-
LINE 2: FROM ( VALUES(1), (2) )
|
112
|
-
|
113
|
-
HINT: For example, FROM (VALUES ...) [AS] foo.
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
ERR
|
118
|
-
|
119
|
-
|
120
|
-
# ERROR: VALUES in FROM must have an alias
|
121
|
-
# LINE 2: FROM ( VALUES(1), (2) )
|
122
|
-
# ^
|
123
|
-
# HINT: For example, FROM (VALUES ...) [AS] foo.
|
124
|
-
# SELECT err
|
125
|
-
# FROM ( VALUES(1), (2) )
|
126
|
-
# ^
|
127
|
-
# ORDER BY 1
|
119
|
+
puts Niceql::Prettifier.prettify_pg_err(<<~ERR )
|
120
|
+
ERROR: VALUES in FROM must have an alias
|
121
|
+
LINE 2: FROM ( VALUES(1), (2) )
|
122
|
+
^
|
123
|
+
HINT: For example, FROM (VALUES ...) [AS] foo.
|
124
|
+
SELECT err
|
125
|
+
FROM ( VALUES(1), (2) )
|
126
|
+
ORDER BY 1
|
127
|
+
ERR
|
128
|
+
|
129
|
+
|
130
|
+
# ERROR: VALUES in FROM must have an alias
|
131
|
+
# LINE 2: FROM ( VALUES(1), (2) )
|
132
|
+
# ^
|
133
|
+
# HINT: For example, FROM (VALUES ...) [AS] foo.
|
134
|
+
# SELECT err
|
135
|
+
# FROM ( VALUES(1), (2) )
|
136
|
+
# ^
|
137
|
+
# ORDER BY 1
|
128
138
|
|
129
139
|
```
|
130
140
|
|
data/lib/niceql.rb
CHANGED
@@ -189,6 +189,17 @@ module Niceql
|
|
189
189
|
sql.tap{ |slf| slf.gsub!( /\s+\n/, "\n" ) }.tap{ |slf| slf.gsub!(/\s+\z/, '') }
|
190
190
|
end
|
191
191
|
|
192
|
+
def self.prettify_multiple( sql_multi, colorize = true )
|
193
|
+
sql_multi.split( /(?>#{SQL_COMMENTS})|(\;)/ ).inject(['']) { |queries, pattern|
|
194
|
+
queries.last << pattern
|
195
|
+
queries << '' if pattern == ';'
|
196
|
+
queries
|
197
|
+
}.map!{ |sql|
|
198
|
+
# we were splitting by comments and ;, so if next sql start with comment we've got a misplaced \n\n
|
199
|
+
sql.match?(/\A\s+\z/) ? nil : prettify_sql( sql, colorize )
|
200
|
+
}.compact.join("\n\n")
|
201
|
+
end
|
202
|
+
|
192
203
|
private
|
193
204
|
def self.indent_multiline( verb, indent )
|
194
205
|
#
|
data/lib/niceql/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: niceql
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.22
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- alekseyl
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-06-
|
11
|
+
date: 2018-06-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -144,7 +144,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
144
144
|
version: '0'
|
145
145
|
requirements: []
|
146
146
|
rubyforge_project:
|
147
|
-
rubygems_version: 2.
|
147
|
+
rubygems_version: 2.7.7
|
148
148
|
signing_key:
|
149
149
|
specification_version: 4
|
150
150
|
summary: This is simple and nice sql prettifier, it splits, indent and colorize SQL
|