niceql 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +8 -11
- data/lib/niceql/version.rb +1 -1
- data/lib/niceql.rb +9 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c26e1a06c6e958f8464ffc4b07ab1cfb1d74b2a0
|
4
|
+
data.tar.gz: b393a24a91b6eed2a63b74d5ab8fd61e36912d8e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 463b0ef4514b12ab300b217592a0dfb613f36ddb87adcee5bc1a31142c4f3998cb041b1d5a0c97dee456a09f730714d4e88f044090975e06e2590377b16a881e
|
7
|
+
data.tar.gz: 1f062cccda0a333b196628db1a2235c144cf105c5398bb36eed92ffb62d776b2d75197a139e58b3269dbf0f772b9d6f6c9e8b800e9bf126aaf64aa2f57c4f064
|
data/README.md
CHANGED
@@ -39,7 +39,10 @@ Or install it yourself as:
|
|
39
39
|
### With ActiveRecord
|
40
40
|
|
41
41
|
```ruby
|
42
|
-
#
|
42
|
+
# puts prettified to_sql ( you need to call puts otherwise to_niceql looks ugly )
|
43
|
+
Model.scope.puts_niceql
|
44
|
+
|
45
|
+
# only formatting without colorization can run as SQL query in connection.execute
|
43
46
|
Model.scope.to_niceql
|
44
47
|
|
45
48
|
# prettify PG errors
|
@@ -82,20 +85,14 @@ ERR
|
|
82
85
|
```
|
83
86
|
## Limitations
|
84
87
|
|
85
|
-
Right now
|
86
|
-
Also if your console support more colors or different schemes, or you prefer different colorization you can override ColorizeString
|
87
|
-
methods. Current color are selected with dark and white console themes in mind, so it works good for dark, and good enough for white.
|
88
|
-
|
89
|
-
|
90
|
-
## Development
|
91
|
-
|
92
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
88
|
+
Right now gem detects only uppercased form of verbs with very simple indentation and parsing options.
|
93
89
|
|
94
|
-
|
90
|
+
## Customizing colors
|
91
|
+
If your console support more colors or different schemes, or you prefer different colorization, then you can override ColorizeString methods. Current color are selected with dark and white console themes in mind, so niceql colorization works good for dark, and good enough for white.
|
95
92
|
|
96
93
|
## Contributing
|
97
94
|
|
98
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
95
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/alekseyl/niceql.
|
99
96
|
|
100
97
|
## License
|
101
98
|
|
data/lib/niceql/version.rb
CHANGED
data/lib/niceql.rb
CHANGED
@@ -19,13 +19,17 @@ module Niceql
|
|
19
19
|
module ArExtentions
|
20
20
|
def explain_err
|
21
21
|
begin
|
22
|
-
connection.execute( "EXPLAIN #{
|
22
|
+
connection.execute( "EXPLAIN #{to_nicesql}" )
|
23
23
|
rescue StandardError => e
|
24
24
|
puts Prettifier.prettify_err(e )
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
-
def
|
28
|
+
def to_nicesql
|
29
|
+
Prettifier.prettify_sql(to_sql, false)
|
30
|
+
end
|
31
|
+
|
32
|
+
def puts_niceql( colorize = true )
|
29
33
|
puts Prettifier.prettify_sql( to_sql, colorize )
|
30
34
|
end
|
31
35
|
end
|
@@ -66,13 +70,15 @@ module Niceql
|
|
66
70
|
parentness = []
|
67
71
|
|
68
72
|
sql = sql.gsub(STRINGS){ |str| StringColorize.colorize_str(str) } if colorize
|
73
|
+
first_verb = true
|
69
74
|
|
70
75
|
sql.gsub( /(#{VERBS}|#{BRACKETS})/) do |verb|
|
71
76
|
add_new_line = false
|
72
77
|
if 'SELECT' == verb
|
73
78
|
indent += 1
|
74
79
|
parentness.last[:nested] = true if parentness.last
|
75
|
-
add_new_line =
|
80
|
+
add_new_line = !first_verb
|
81
|
+
first_verb = false
|
76
82
|
elsif verb == '('
|
77
83
|
parentness << { nested: false }
|
78
84
|
indent += 1
|
@@ -90,7 +96,6 @@ module Niceql
|
|
90
96
|
add_new_line = verb[/(#{INLINE_VERBS})/].nil?
|
91
97
|
end
|
92
98
|
verb = StringColorize.colorize_verb(verb) if !['(', ')'].include?(verb) && colorize
|
93
|
-
|
94
99
|
add_new_line ? "\n#{' ' * indent}" + verb : verb
|
95
100
|
end
|
96
101
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
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.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- alekseyl
|
@@ -95,7 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
95
95
|
version: '0'
|
96
96
|
requirements: []
|
97
97
|
rubyforge_project:
|
98
|
-
rubygems_version: 2.6.
|
98
|
+
rubygems_version: 2.6.13
|
99
99
|
signing_key:
|
100
100
|
specification_version: 4
|
101
101
|
summary: This is simple and nice sql prettifier, it splits, indent and colorize SQL
|