rails_sql_prettifier 6.1.5 → 7.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-gemset +1 -1
- data/CHANGELOG.md +4 -17
- data/README.md +8 -11
- data/docker-compose.yml +2 -11
- data/lib/rails_sql_prettifier/version.rb +1 -1
- data/lib/rails_sql_prettifier.rb +7 -15
- data/rails_sql_prettifier.gemspec +3 -4
- metadata +6 -28
- data/.byebug_history +0 -34
- data/Dockerfile_30 +0 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f0915544aab1e8904934de1a1267a8d40964918a3dfdf7ab167c81a9d8b58b28
|
4
|
+
data.tar.gz: c5106dc3115d142d47efeaa17b44c67582d74cb0ff820e4b627b4189025b02d2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 599c98fb30699026e7da016d223a21cc8741f03b1c2dbcd0288f733b652075ec8cffb269d1da4d36fbcb0f04dfce196b4b611c29aa32dc84d88ebac2a2d351b7
|
7
|
+
data.tar.gz: ab7080d1422d87aa5d75b59763625b151980f34b6724cb8138ca8065003ec02cc8dd9a139dd3303e33c4524ac4b8cf9557c77e9d04e71148e45548476f3f0d0d
|
data/.ruby-gemset
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
rails_sql_prettifier
|
data/CHANGELOG.md
CHANGED
@@ -1,19 +1,6 @@
|
|
1
|
-
#
|
2
|
-
*
|
3
|
-
* niceql version set to ~> 0.6 (fixed https://github.com/alekseyl/niceql/issues/16 !)
|
1
|
+
#7.0.2
|
2
|
+
* active record versioning is properly aligned now
|
4
3
|
|
5
|
-
#
|
6
|
-
* fixed issue [#20](https://github.com/alekseyl/niceql/issues/20)
|
7
|
-
* adding support for multiple ruby versions testing using docker-compose
|
4
|
+
#7.0.0
|
8
5
|
|
9
|
-
|
10
|
-
* Now AR is a dependency not a development dependency
|
11
|
-
|
12
|
-
# 6.1.0
|
13
|
-
|
14
|
-
* This a active record prior to 7.0 version and >= 6.1 compatible niceql integration
|
15
|
-
ar < 6.0 breaking change:
|
16
|
-
* StatementInvalid initialization ahs a breaking change: starting version 6 it has named param sql: for original query )
|
17
|
-
|
18
|
-
ar <= 6.1:
|
19
|
-
* Starting from 6.1 connection_db_config method replaced connection_config which was a hash
|
6
|
+
* current master branch
|
data/README.md
CHANGED
@@ -6,7 +6,7 @@ This gem started as a code extraction from niceql version 0.4.x.
|
|
6
6
|
|
7
7
|
It has versioning aligned to the ActiveRecord versions, niceql prior to 0.5 version had hardcoded logic branches based on ActiveRecord versioning.
|
8
8
|
|
9
|
-
That is hard to maintain and hard to test, and also coupling with AR is breaking the original idea of the niceql to be a dependentless solution, so now the niceql is a completely railsfree gem yeay! ( It still has some some checks related to AR
|
9
|
+
That is hard to maintain and hard to test, and also coupling with AR is breaking the original idea of the niceql to be a dependentless solution, so now the niceql is a completely railsfree gem yeay! ( It still has some some checks related to AR implemetations in the error prettifying methods. It will be completely decoupled in the future )
|
10
10
|
|
11
11
|
Any reasonable suggestions are welcome.
|
12
12
|
|
@@ -51,14 +51,12 @@ Or install it yourself as:
|
|
51
51
|
|
52
52
|
```ruby
|
53
53
|
Niceql.configure do |c|
|
54
|
-
# Setting pg_adapter_with_nicesql to true will
|
54
|
+
# Setting pg_adapter_with_nicesql to true will force formatting SQL queries
|
55
55
|
# before execution. Formatted SQL will lead to much better SQL-query debugging and much more clearer error messages
|
56
56
|
# if you are using Postgresql as a data source.
|
57
|
+
# BUT do not use it in production until https://github.com/alekseyl/niceql/issues/16 is resolved
|
57
58
|
#
|
58
|
-
#
|
59
|
-
# there could be other potentially uncovered bugs so its better not to
|
60
|
-
# adjust pg_adapter in production, currently there is an additional blocker for that module ProtectedEnv
|
61
|
-
# its will not allow patching PGAdapter for other than test/development envs
|
59
|
+
# You can adjust pg_adapter in production but do it at your own risk!
|
62
60
|
#
|
63
61
|
# If you need to debug SQL queries in production use exec_niceql
|
64
62
|
#
|
@@ -96,6 +94,8 @@ end
|
|
96
94
|
|
97
95
|
## Usage
|
98
96
|
|
97
|
+
### With ActiveRecord
|
98
|
+
|
99
99
|
```ruby
|
100
100
|
# puts colorized and formatted corresponding SQL query
|
101
101
|
Model.scope.niceql
|
@@ -103,7 +103,7 @@ end
|
|
103
103
|
# only formatting without colorization, you can run output of to_niceql as a SQL query in connection.execute
|
104
104
|
Model.scope.to_niceql
|
105
105
|
|
106
|
-
#
|
106
|
+
# prettify PG errors if scope runs with any
|
107
107
|
Model.scope_with_err.exec_niceql
|
108
108
|
```
|
109
109
|
|
@@ -157,10 +157,7 @@ end
|
|
157
157
|
If your console support more colors or different schemes, or if you prefer different colorization, then you can override ColorizeString methods.
|
158
158
|
Current colors were selected with dark and white console themes in mind, so a niceql colorization works good for dark, and good enough for white.
|
159
159
|
|
160
|
-
##
|
161
|
-
```bash
|
162
|
-
docker-compose up
|
163
|
-
```
|
160
|
+
##
|
164
161
|
|
165
162
|
## Contributing
|
166
163
|
|
data/docker-compose.yml
CHANGED
@@ -3,17 +3,8 @@ version: "3.7"
|
|
3
3
|
services:
|
4
4
|
test:
|
5
5
|
build: .
|
6
|
-
image:
|
7
|
-
command:
|
8
|
-
volumes:
|
9
|
-
- '.:/app'
|
10
|
-
|
11
|
-
test_3_0:
|
12
|
-
build:
|
13
|
-
context: .
|
14
|
-
dockerfile: Dockerfile_30
|
15
|
-
image: rsp_6_1_3_0
|
16
|
-
command: /bin/bash -c 'service postgresql start && rake test'
|
6
|
+
image: niceql
|
7
|
+
command: service postgresql start && rake test
|
17
8
|
volumes:
|
18
9
|
- '.:/app'
|
19
10
|
|
data/lib/rails_sql_prettifier.rb
CHANGED
@@ -2,6 +2,7 @@ require "rails_sql_prettifier/version"
|
|
2
2
|
require 'active_record'
|
3
3
|
require "niceql"
|
4
4
|
|
5
|
+
|
5
6
|
module RailsSQLPrettifier
|
6
7
|
|
7
8
|
module ArExtentions
|
@@ -27,13 +28,11 @@ module RailsSQLPrettifier
|
|
27
28
|
end
|
28
29
|
|
29
30
|
module AbstractAdapterLogPrettifier
|
30
|
-
|
31
|
-
def log( sql, *args, **kwargs, &block )
|
31
|
+
def log( sql, *args, &block )
|
32
32
|
# \n need to be placed because AR log will start with action description + time info.
|
33
33
|
# rescue sql - just to be sure Prettifier wouldn't break production
|
34
34
|
formatted_sql = "\n" + Niceql::Prettifier.prettify_sql(sql) rescue sql
|
35
|
-
|
36
|
-
super( formatted_sql, *args, **kwargs, &block )
|
35
|
+
super( formatted_sql, *args, &block )
|
37
36
|
end
|
38
37
|
end
|
39
38
|
|
@@ -54,6 +53,7 @@ module RailsSQLPrettifier
|
|
54
53
|
:prettify_pg_errors
|
55
54
|
end
|
56
55
|
|
56
|
+
|
57
57
|
def ar_using_pg_adapter?
|
58
58
|
ActiveRecord::Base.connection_db_config.adapter == 'postgresql'
|
59
59
|
end
|
@@ -70,8 +70,8 @@ module RailsSQLPrettifier
|
|
70
70
|
def configure
|
71
71
|
super
|
72
72
|
|
73
|
-
if config.pg_adapter_with_nicesql && defined?(::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter)
|
74
|
-
::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.include(PostgresAdapterNiceQL)
|
73
|
+
if config.pg_adapter_with_nicesql && defined?( ::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter )
|
74
|
+
::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.include( PostgresAdapterNiceQL)
|
75
75
|
end
|
76
76
|
|
77
77
|
::ActiveRecord::ConnectionAdapters::AbstractAdapter.prepend( AbstractAdapterLogPrettifier ) if config.prettify_active_record_log_output
|
@@ -80,13 +80,6 @@ module RailsSQLPrettifier
|
|
80
80
|
end
|
81
81
|
end
|
82
82
|
|
83
|
-
module ProtectedEnv
|
84
|
-
def protected_env?
|
85
|
-
ActiveRecord::Base.connection.migration_context.protected_environment? ||
|
86
|
-
defined?(Rails) && !(Rails.env.test? || Rails.env.development?)
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
83
|
[::ActiveRecord::Relation,
|
91
84
|
::Arel::TreeManager,
|
92
85
|
::Arel::Nodes::Node].each { |klass| klass.send(:include, ArExtentions) }
|
@@ -95,5 +88,4 @@ module RailsSQLPrettifier
|
|
95
88
|
|
96
89
|
# we need to use a prepend otherwise it's not preceding Niceql.configure in a lookup chain
|
97
90
|
Niceql.singleton_class.prepend( NiceqlExt )
|
98
|
-
|
99
|
-
end
|
91
|
+
end
|
@@ -31,18 +31,17 @@ Gem::Specification.new do |spec|
|
|
31
31
|
spec.require_paths = ["lib"]
|
32
32
|
|
33
33
|
spec.required_ruby_version = '>= 2.4'
|
34
|
-
spec.add_dependency "niceql", '~> 0.
|
35
|
-
spec.add_dependency "activerecord", '>=
|
34
|
+
spec.add_dependency "niceql", '~> 0.5'
|
35
|
+
spec.add_dependency "activerecord", '>= 7'
|
36
36
|
|
37
37
|
spec.add_development_dependency "bundler", ">= 1"
|
38
38
|
spec.add_development_dependency "rake", ">= 12.3.3"
|
39
39
|
spec.add_development_dependency "minitest", "~> 5.0"
|
40
40
|
|
41
|
-
spec.add_development_dependency "awesome_print"
|
42
41
|
spec.add_development_dependency "differ", '~> 0.1'
|
43
42
|
spec.add_development_dependency "pry-byebug", '~> 3.9'
|
44
43
|
spec.add_development_dependency 'sqlite3', '~> 1'
|
45
44
|
spec.add_development_dependency 'pg', '~> 1'
|
46
45
|
|
47
|
-
spec.add_development_dependency 'stubberry', '~> 0.
|
46
|
+
spec.add_development_dependency 'stubberry', '~> 0.1'
|
48
47
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_sql_prettifier
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 7.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- alekseyl
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-09
|
11
|
+
date: 2022-01-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: niceql
|
@@ -16,22 +16,19 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '0.
|
19
|
+
version: '0.5'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '0.
|
26
|
+
version: '0.5'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: activerecord
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '6.1'
|
34
|
-
- - "<"
|
35
32
|
- !ruby/object:Gem::Version
|
36
33
|
version: '7'
|
37
34
|
type: :runtime
|
@@ -39,9 +36,6 @@ dependencies:
|
|
39
36
|
version_requirements: !ruby/object:Gem::Requirement
|
40
37
|
requirements:
|
41
38
|
- - ">="
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
version: '6.1'
|
44
|
-
- - "<"
|
45
39
|
- !ruby/object:Gem::Version
|
46
40
|
version: '7'
|
47
41
|
- !ruby/object:Gem::Dependency
|
@@ -86,20 +80,6 @@ dependencies:
|
|
86
80
|
- - "~>"
|
87
81
|
- !ruby/object:Gem::Version
|
88
82
|
version: '5.0'
|
89
|
-
- !ruby/object:Gem::Dependency
|
90
|
-
name: awesome_print
|
91
|
-
requirement: !ruby/object:Gem::Requirement
|
92
|
-
requirements:
|
93
|
-
- - ">="
|
94
|
-
- !ruby/object:Gem::Version
|
95
|
-
version: '0'
|
96
|
-
type: :development
|
97
|
-
prerelease: false
|
98
|
-
version_requirements: !ruby/object:Gem::Requirement
|
99
|
-
requirements:
|
100
|
-
- - ">="
|
101
|
-
- !ruby/object:Gem::Version
|
102
|
-
version: '0'
|
103
83
|
- !ruby/object:Gem::Dependency
|
104
84
|
name: differ
|
105
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -162,14 +142,14 @@ dependencies:
|
|
162
142
|
requirements:
|
163
143
|
- - "~>"
|
164
144
|
- !ruby/object:Gem::Version
|
165
|
-
version: '0.
|
145
|
+
version: '0.1'
|
166
146
|
type: :development
|
167
147
|
prerelease: false
|
168
148
|
version_requirements: !ruby/object:Gem::Requirement
|
169
149
|
requirements:
|
170
150
|
- - "~>"
|
171
151
|
- !ruby/object:Gem::Version
|
172
|
-
version: '0.
|
152
|
+
version: '0.1'
|
173
153
|
description: 'This is an ActiveRecord integration for the SQL prettifier gem niceql. '
|
174
154
|
email:
|
175
155
|
- leshchuk@gmail.com
|
@@ -177,14 +157,12 @@ executables: []
|
|
177
157
|
extensions: []
|
178
158
|
extra_rdoc_files: []
|
179
159
|
files:
|
180
|
-
- ".byebug_history"
|
181
160
|
- ".gitignore"
|
182
161
|
- ".ruby-gemset"
|
183
162
|
- ".ruby-version"
|
184
163
|
- ".travis.yml"
|
185
164
|
- CHANGELOG.md
|
186
165
|
- Dockerfile
|
187
|
-
- Dockerfile_30
|
188
166
|
- Gemfile
|
189
167
|
- LICENSE.txt
|
190
168
|
- README.md
|
data/.byebug_history
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
exit
|
2
|
-
ActiveRecord::Base.connection_db_config.adapter
|
3
|
-
ActiveRecord::Base.connection_db_config.adpter
|
4
|
-
ActiveRecord::Base.connection_db_config
|
5
|
-
c
|
6
|
-
exit
|
7
|
-
si.sql
|
8
|
-
si
|
9
|
-
c
|
10
|
-
sql_body
|
11
|
-
n
|
12
|
-
s
|
13
|
-
original_sql_query
|
14
|
-
err
|
15
|
-
s
|
16
|
-
up
|
17
|
-
s
|
18
|
-
up
|
19
|
-
s
|
20
|
-
up
|
21
|
-
s
|
22
|
-
super
|
23
|
-
try(:sql)
|
24
|
-
Niceql.config.prettify_pg_errors
|
25
|
-
c
|
26
|
-
exit
|
27
|
-
err_template
|
28
|
-
si.to_s
|
29
|
-
exit
|
30
|
-
err_caret_line
|
31
|
-
err_quote_caret_offset
|
32
|
-
c
|
33
|
-
err.lines[1].index( '...' ).to_i
|
34
|
-
err_caret_line
|
data/Dockerfile_30
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
FROM ruby:3.0.3-bullseye
|
2
|
-
|
3
|
-
WORKDIR /app
|
4
|
-
RUN apt-get update && apt-get -y install lsb-release
|
5
|
-
#
|
6
|
-
RUN wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - && \
|
7
|
-
sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list' && \
|
8
|
-
apt-get update && apt-get -y install postgresql postgresql-client-12
|
9
|
-
|
10
|
-
RUN sh -c 'echo "local all all trust" > /etc/postgresql/14/main/pg_hba.conf' && \
|
11
|
-
service postgresql start && \
|
12
|
-
psql -U postgres -c 'CREATE DATABASE "niceql-test"'
|
13
|
-
|
14
|
-
RUN gem install bundler
|
15
|
-
|
16
|
-
COPY lib/rails_sql_prettifier/version.rb /app/lib/rails_sql_prettifier/version.rb
|
17
|
-
COPY rails_sql_prettifier.gemspec /app/
|
18
|
-
COPY Gemfil* /app/
|
19
|
-
#
|
20
|
-
RUN bundle install
|