niceql 0.1.21 → 0.1.22

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 2efccbbe22d5da01e7efe8fca21ed008f78e4eb1
4
- data.tar.gz: b4290f066aef1b5c18e1199e291c093ff22d26ba
2
+ SHA256:
3
+ metadata.gz: b00aaefbdb5837f56163c43dfd8c3599add288f5d71e0df6aad33760771562bb
4
+ data.tar.gz: 06544b54f77cd4cc54a1b5b44ae8d1438bf57a9b6efc29c9408de7d35c75c8d9
5
5
  SHA512:
6
- metadata.gz: 88846a6a3a4efea29e1c1d71eec1a2400c1b3fdf51d61cb4dcc428dace318aa55ff725f51ab13f82ca86fb9c57204c664aee35e99abee21c9c0f47654a8790c6
7
- data.tar.gz: 7806bad02c6f18dfa5efca5d5b290dbca3726f42213edff413b2e8032bd52b14bea8d1980bffd0703c8af156a83203184694ef9196e5fdbef67265a94bff7802
6
+ metadata.gz: 5580c574b821e14a804252e7f2037341ca3e8c98d9b0b33d22057557cad29b4d1f4701773b2018a29183002280566861ccad962877b29bfcfda0db412d91f69b
7
+ data.tar.gz: 9d3ef9a43ab6b97e08c577521486e1b9c0151ba62848a47f096c0d31c521c0ff9b997795d3f8d62b78d4252ad8cd94fad8f8614032847dde5ad2f8fbc28cc830
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ # 0.1.22
2
+ * multi query formatting
3
+
1
4
  # 0.1.21
2
5
  * fix bug for SQL started with comment
3
6
 
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 ./console from bin and look for examples ).
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
- # see colors in irb %)
101
- #=> SELECT *
102
- #=> FROM ( VALUES(1), (2) ) AS tmp
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
- puts Niceql::Prettifier.prettify_pg_err(<<-ERR )
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
- SELECT err
115
- FROM ( VALUES(1), (2) )
116
- ORDER BY 1
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
  #
@@ -1,3 +1,3 @@
1
1
  module Niceql
2
- VERSION = "0.1.21"
2
+ VERSION = "0.1.22"
3
3
  end
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.21
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-04 00:00:00.000000000 Z
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.6.11
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