niceql 0.1.25 → 0.6.1
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 +4 -4
- data/.github/dependabot.yml +6 -0
- data/.github/workflows/ci.yml +23 -0
- data/.github/workflows/rubocop.yml +17 -0
- data/.rubocop.yml +2 -0
- data/CHANGELOG.md +46 -0
- data/Gemfile +3 -1
- data/README.md +24 -16
- data/Rakefile +3 -1
- data/bin/console +1 -0
- data/lib/generators/niceql/install_generator.rb +4 -2
- data/lib/generators/templates/niceql_initializer.rb +3 -1
- data/lib/niceql/version.rb +3 -1
- data/lib/niceql.rb +399 -216
- data/niceql.gemspec +20 -10
- metadata +66 -24
- data/.travis.yml +0 -7
- data/lib/benchmark/cat.rb +0 -34
- data/lib/benchmark/gsub.rb +0 -34
- data/lib/benchmark/txt +0 -748
- data/lib/niceql/string.rb +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 286318425292a968afb8fd83fc05d8067bb03432bdf120ab3412a23119cc4128
|
4
|
+
data.tar.gz: 1a694bab19fb2281ad3e6b013b4527db6233d55885641eb2b2c76d513309b979
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7398eac94842f0f457e7323603ec21ecdae146b9ceccc84e7191f0d2d4539b8de4447f1fa33206c124bc39b5572d1df8eb054d469ea3f39b929cf6b717367d83
|
7
|
+
data.tar.gz: f9f4da9487a41a117f08c20416dac9ba8146597301a40c62d162b44013460337ed7015e2674b05d679488b7b6fe7ea9420ae36a244f90c21203eb872b7f0412c
|
@@ -0,0 +1,23 @@
|
|
1
|
+
name: CI
|
2
|
+
|
3
|
+
on: [push, pull_request]
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
test:
|
7
|
+
|
8
|
+
runs-on: ubuntu-latest
|
9
|
+
|
10
|
+
strategy:
|
11
|
+
fail-fast: false
|
12
|
+
matrix:
|
13
|
+
ruby: ["2.5", "2.6", "2.7", "3.0", "3.1"]
|
14
|
+
|
15
|
+
steps:
|
16
|
+
- uses: actions/checkout@v3
|
17
|
+
- name: Set up Ruby
|
18
|
+
uses: ruby/setup-ruby@v1
|
19
|
+
with:
|
20
|
+
bundler-cache: true # 'bundle install' and cache gems
|
21
|
+
ruby-version: ${{ matrix.ruby }}
|
22
|
+
- name: Run tests
|
23
|
+
run: bundle exec rake test
|
@@ -0,0 +1,17 @@
|
|
1
|
+
name: RuboCop
|
2
|
+
|
3
|
+
on: [push, pull_request]
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
build:
|
7
|
+
runs-on: ubuntu-latest
|
8
|
+
|
9
|
+
steps:
|
10
|
+
- uses: actions/checkout@v3
|
11
|
+
- name: Set up Ruby
|
12
|
+
uses: ruby/setup-ruby@v1
|
13
|
+
with:
|
14
|
+
ruby-version: 2.7
|
15
|
+
bundler-cache: true # 'bundle install' and cache
|
16
|
+
- name: Run RuboCop
|
17
|
+
run: bundle exec rubocop --parallel
|
data/.rubocop.yml
ADDED
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,49 @@
|
|
1
|
+
# 0.6.1
|
2
|
+
* github CI added ( PR: https://github.com/alekseyl/niceql/pull/22 many thnx to @petergoldstein )
|
3
|
+
* issue fixed https://github.com/alekseyl/niceql/issues/23
|
4
|
+
* dropped support for 2.4 ( transform_keys is missing, and I'm too lazy to backward reimplement it you can do PR if needed )
|
5
|
+
|
6
|
+
# 0.6.0
|
7
|
+
* Huge core-logic refactoring and simplification
|
8
|
+
* dollar signed literals/strings added
|
9
|
+
* strings literals issue https://github.com/alekseyl/niceql/issues/16 fixed
|
10
|
+
* strings literals colorized properly
|
11
|
+
* comments are bold and greyed now.
|
12
|
+
* code now is rubocoped with shopify rules
|
13
|
+
|
14
|
+
# 0.5.1
|
15
|
+
* No features just some code refactoring
|
16
|
+
|
17
|
+
# 0.5.0
|
18
|
+
* BREAKING CHANGE! ActiveRecord compatibility extracted to the rails_sql_prettifier gem!
|
19
|
+
If you need niceql funcitonality with rails / active_record plz include rails_sql_prettifier has a
|
20
|
+
a versioning aligned to the active_record versions and has same DSL for ActiveRecord the niceql was providing prior.
|
21
|
+
|
22
|
+
# 0.4.1
|
23
|
+
* description update
|
24
|
+
|
25
|
+
# 0.4.0
|
26
|
+
* merged PR https://github.com/alekseyl/niceql/pull/19, now Arel is also extended with niceql methods!!
|
27
|
+
* test and better niceql comparisons assertion
|
28
|
+
* tests were trialed against rails 4.2 and some additional conditions were added for later cases
|
29
|
+
|
30
|
+
# 0.3.0
|
31
|
+
* ruby forced to >= 2.4
|
32
|
+
* String match extension no longer needed
|
33
|
+
* fixed issue with missing HINT and DETAIL string ( https://github.com/alekseyl/niceql/issues/18 )
|
34
|
+
* both new and old activerecord StatementInvalid formats supported
|
35
|
+
* major prettify_pg_err refactoring ( much cleaner code now )
|
36
|
+
|
37
|
+
# 0.2.0
|
38
|
+
* Fix to issue https://github.com/alekseyl/niceql/pull/17#issuecomment-924278172. ActiveRecord base config is no longer a hash,
|
39
|
+
so it does not have dig method, hence it's breaking the ar_using_pg_adapter? method.
|
40
|
+
* active_record added as development dependency :( for proper testing cover.
|
41
|
+
|
42
|
+
# 0.1.30
|
43
|
+
* ActiveRecord pg check for config now will try both connection_db_config and connection_config for adapter verification
|
44
|
+
* prettify_pg_errors will not be set to true if ActiveRecord adapter is not using pg, i.e. ar_using_pg_adapter? is false.
|
45
|
+
* rake dev dependency bumped according to security issues
|
46
|
+
|
1
47
|
# 0.1.24/25
|
2
48
|
|
3
49
|
* No features, just strict ruby dependency for >= 2.3,
|
data/Gemfile
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
source "https://rubygems.org"
|
2
4
|
|
3
|
-
git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
|
5
|
+
git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
|
4
6
|
|
5
7
|
# Specify your gem's dependencies in niceql.gemspec
|
6
8
|
gemspec
|
data/README.md
CHANGED
@@ -1,10 +1,16 @@
|
|
1
1
|
# Niceql
|
2
2
|
|
3
|
-
|
3
|
+
**ATTENTION: After ver 0.5.0 the ActiveRecord integration is provided via standalone gem: [rails_sql_prettifier](https://github.com/alekseyl/rails_sql_prettifier)!**
|
4
|
+
|
5
|
+
This is a small, nice, simple and zero dependency solution for SQL prettifying for Ruby.
|
4
6
|
It can be used in an irb console without any dependencies ( run bin/console and look for examples ).
|
5
7
|
|
6
|
-
Any reasonable suggestions
|
8
|
+
Any reasonable suggestions are welcome.
|
9
|
+
|
10
|
+
**Please pay attention: even though issue https://github.com/alekseyl/niceql/issues/16 is resolved
|
11
|
+
still potentially UPDATE or INSERT request might corrupt your data, please don't patch pg_adapter on production!**
|
7
12
|
|
13
|
+
|
8
14
|
## Before/After
|
9
15
|
### SQL prettifier:
|
10
16
|

|
@@ -41,9 +47,11 @@ Or install it yourself as:
|
|
41
47
|
```ruby
|
42
48
|
Niceql.configure do |c|
|
43
49
|
# Setting pg_adapter_with_nicesql to true will force formatting SQL queries
|
44
|
-
# before
|
50
|
+
# before execution. Formatted SQL will lead to much better SQL-query debugging and much more clearer error messages
|
45
51
|
# if you are using Postgresql as a data source.
|
46
|
-
#
|
52
|
+
#
|
53
|
+
# Adjusting pg_adapter in production is strongly discouraged!
|
54
|
+
#
|
47
55
|
# If you need to debug SQL queries in production use exec_niceql
|
48
56
|
# default: false
|
49
57
|
# uncomment next string to enable in development
|
@@ -53,7 +61,7 @@ Niceql.configure do |c|
|
|
53
61
|
# default: false
|
54
62
|
# c.prettify_active_record_log_output = true
|
55
63
|
|
56
|
-
#
|
64
|
+
# Error prettifying is also configurable
|
57
65
|
# default: defined? ::ActiveRecord::Base && ActiveRecord::Base.configurations[Rails.env]['adapter'] == 'postgresql'
|
58
66
|
# c.prettify_pg_errors = defined? ::ActiveRecord::Base && ActiveRecord::Base.configurations[Rails.env]['adapter'] == 'postgresql'
|
59
67
|
|
@@ -79,10 +87,10 @@ end
|
|
79
87
|
|
80
88
|
## Usage
|
81
89
|
|
82
|
-
### With ActiveRecord
|
90
|
+
### With ActiveRecord ( you need rails_sql_prettifier for that! )
|
83
91
|
|
84
92
|
```ruby
|
85
|
-
# puts colorized
|
93
|
+
# puts colorized and formatted corresponding SQL query
|
86
94
|
Model.scope.niceql
|
87
95
|
|
88
96
|
# only formatting without colorization, you can run output of to_niceql as a SQL query in connection.execute
|
@@ -107,23 +115,23 @@ end
|
|
107
115
|
#=>
|
108
116
|
#=> SELECT *
|
109
117
|
#=> FROM table
|
110
|
-
|
111
|
-
|
112
|
-
|
118
|
+
|
113
119
|
|
114
|
-
|
115
|
-
puts Niceql::Prettifier.prettify_pg_err( "#{pg_err_output}\n#{sql_query}" )
|
120
|
+
puts Niceql::Prettifier.prettify_pg_err( pg_err_output, sql_query )
|
116
121
|
|
117
122
|
# to get real nice result you should execute prettified version (i.e. execute( prettified_sql ) !) of query on your DB!
|
118
123
|
# otherwise you will not get such a nice output
|
119
|
-
|
124
|
+
raw_sql = <<~SQL
|
125
|
+
SELECT err
|
126
|
+
FROM ( VALUES(1), (2) )
|
127
|
+
ORDER BY 1
|
128
|
+
SQL
|
129
|
+
|
130
|
+
puts Niceql::Prettifier.prettify_pg_err(<<~ERR, raw_sql )
|
120
131
|
ERROR: VALUES in FROM must have an alias
|
121
132
|
LINE 2: FROM ( VALUES(1), (2) )
|
122
133
|
^
|
123
134
|
HINT: For example, FROM (VALUES ...) [AS] foo.
|
124
|
-
SELECT err
|
125
|
-
FROM ( VALUES(1), (2) )
|
126
|
-
ORDER BY 1
|
127
135
|
ERR
|
128
136
|
|
129
137
|
|
data/Rakefile
CHANGED
data/bin/console
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Niceql
|
2
4
|
module Generators
|
3
5
|
class InstallGenerator < Rails::Generators::Base
|
@@ -5,10 +7,10 @@ module Niceql
|
|
5
7
|
desc "Creates Niceql initializer for your application"
|
6
8
|
|
7
9
|
def copy_initializer
|
8
|
-
template
|
10
|
+
template("niceql_initializer.rb", "config/initializers/niceql.rb")
|
9
11
|
|
10
12
|
puts "Install complete!"
|
11
13
|
end
|
12
14
|
end
|
13
15
|
end
|
14
|
-
end
|
16
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
Niceql.configure do |c|
|
2
4
|
# You can adjust pg_adapter in prooduction at your own risk!
|
3
5
|
# If you need it in production use exec_niceql
|
@@ -8,4 +10,4 @@ Niceql.configure do |c|
|
|
8
10
|
# c.indentation_base = 2
|
9
11
|
# c.open_bracket_is_newliner = false
|
10
12
|
# c.prettify_active_record_log_output = false
|
11
|
-
end
|
13
|
+
end
|
data/lib/niceql/version.rb
CHANGED