rails_sql_prettifier 6.0.6 → 6.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.byebug_history +34 -0
- data/.gitignore +1 -2
- data/.ruby-gemset +1 -1
- data/CHANGELOG.md +5 -17
- data/README.md +10 -21
- data/lib/rails_sql_prettifier/version.rb +1 -1
- data/lib/rails_sql_prettifier.rb +13 -28
- data/rails_sql_prettifier.gemspec +3 -6
- metadata +10 -54
- data/Dockerfile +0 -20
- data/Dockerfile_30 +0 -20
- data/docker-compose.yml +0 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 459c1f20e82eb14b0130418cb1161272383ae9f9f902164100b2a4d81bbabb9c
|
4
|
+
data.tar.gz: db5ee936e31bd470ac74940b2fa086e4a1aec84004cb05971c6434e8f5cb2ea1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a159e5b627abaa4ac80c70092668aad54f11f871c13a57e83585e38851d2f522273653d79871b2b087d1bce83de00c9119b6b2d7c28b60d7b75c8b13b1e3dde1
|
7
|
+
data.tar.gz: 4feabc414ccf282a7462c44527514449735b8bcdf9b2b84afe3b873735176cecbe1dcc40dfa6745b67af114391a1a38808cc3658bae4e45e8b242267932e32ce
|
data/.byebug_history
ADDED
@@ -0,0 +1,34 @@
|
|
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/.gitignore
CHANGED
data/.ruby-gemset
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
rails_sql_prettifier_ar_6
|
data/CHANGELOG.md
CHANGED
@@ -1,20 +1,8 @@
|
|
1
|
-
# 6.0
|
2
|
-
* pg_adapter_with_nicesql setting will not be set to action for protected_env
|
3
|
-
* niceql version set to ~> 0.6 (fixed https://github.com/alekseyl/niceql/issues/16 !)
|
4
|
-
|
5
|
-
#6.0.5
|
6
|
-
* fixed issue [#20](https://github.com/alekseyl/niceql/issues/20)
|
7
|
-
* adding support for multiple ruby versions testing using docker-compose
|
8
|
-
|
9
|
-
# 6.0.4
|
10
|
-
* Now AR is a dependency not a development dependency
|
11
|
-
|
12
|
-
# 6.0.3
|
13
|
-
* Fixed issue with Niceql.configure not configuring anything + test covered
|
14
|
-
|
15
|
-
#6.0.2
|
1
|
+
# 6.1.0
|
16
2
|
|
17
3
|
* This a active record prior to 7.0 version and >= 6.1 compatible niceql integration
|
18
|
-
ar < 6.0
|
19
|
-
* StatementInvalid initialization
|
4
|
+
ar < 6.0:
|
5
|
+
* StatementInvalid initialization, starting version 6 it has named param sql: for original query )
|
20
6
|
|
7
|
+
ar <= 6.1:
|
8
|
+
* Starting from 6.1 connection_db_config used as standalone object instead of connection_config
|
data/README.md
CHANGED
@@ -1,12 +1,7 @@
|
|
1
1
|
# RailsSQLPrettifier
|
2
2
|
|
3
|
-
This is an ActiveRecord integration for a niceql gem
|
4
|
-
|
5
|
-
This gem started as a code extraction from niceql version 0.4.x.
|
6
|
-
|
7
|
-
It has versioning aligned to the ActiveRecord versions, niceql prior to 0.5 version had hardcoded logic branches based on ActiveRecord versioning.
|
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 implementations in the error prettifying methods. It will be completely decoupled in the future )
|
3
|
+
This is an ActiveRecord integration for a niceql gem.
|
4
|
+
Niceql is a small, nice, simple and zero dependency solution for SQL prettifying for Ruby.
|
10
5
|
|
11
6
|
Any reasonable suggestions are welcome.
|
12
7
|
|
@@ -28,13 +23,10 @@ after:
|
|
28
23
|
|
29
24
|
## Installation
|
30
25
|
|
31
|
-
rails_sql_prettifier, has several version compatible with different active_record versions, so pay attention to the right versioning
|
32
|
-
if whenever you specify versions manually.
|
33
|
-
|
34
26
|
Add this line to your application's Gemfile:
|
35
27
|
|
36
28
|
```ruby
|
37
|
-
gem 'rails_sql_prettifier'
|
29
|
+
gem 'rails_sql_prettifier'
|
38
30
|
```
|
39
31
|
|
40
32
|
And then execute:
|
@@ -51,14 +43,12 @@ Or install it yourself as:
|
|
51
43
|
|
52
44
|
```ruby
|
53
45
|
Niceql.configure do |c|
|
54
|
-
# Setting pg_adapter_with_nicesql to true will
|
46
|
+
# Setting pg_adapter_with_nicesql to true will force formatting SQL queries
|
55
47
|
# before execution. Formatted SQL will lead to much better SQL-query debugging and much more clearer error messages
|
56
48
|
# if you are using Postgresql as a data source.
|
49
|
+
# BUT do not use it in production until https://github.com/alekseyl/niceql/issues/16 is resolved
|
57
50
|
#
|
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
|
51
|
+
# You can adjust pg_adapter in production but do it at your own risk!
|
62
52
|
#
|
63
53
|
# If you need to debug SQL queries in production use exec_niceql
|
64
54
|
#
|
@@ -96,6 +86,8 @@ end
|
|
96
86
|
|
97
87
|
## Usage
|
98
88
|
|
89
|
+
### With ActiveRecord
|
90
|
+
|
99
91
|
```ruby
|
100
92
|
# puts colorized and formatted corresponding SQL query
|
101
93
|
Model.scope.niceql
|
@@ -103,7 +95,7 @@ end
|
|
103
95
|
# only formatting without colorization, you can run output of to_niceql as a SQL query in connection.execute
|
104
96
|
Model.scope.to_niceql
|
105
97
|
|
106
|
-
#
|
98
|
+
# prettify PG errors if scope runs with any
|
107
99
|
Model.scope_with_err.exec_niceql
|
108
100
|
```
|
109
101
|
|
@@ -157,10 +149,7 @@ end
|
|
157
149
|
If your console support more colors or different schemes, or if you prefer different colorization, then you can override ColorizeString methods.
|
158
150
|
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
151
|
|
160
|
-
##
|
161
|
-
```bash
|
162
|
-
docker-compose up
|
163
|
-
```
|
152
|
+
##
|
164
153
|
|
165
154
|
## Contributing
|
166
155
|
|
data/lib/rails_sql_prettifier.rb
CHANGED
@@ -2,8 +2,8 @@ require "rails_sql_prettifier/version"
|
|
2
2
|
require 'active_record'
|
3
3
|
require "niceql"
|
4
4
|
|
5
|
-
|
6
5
|
module RailsSQLPrettifier
|
6
|
+
include Niceql
|
7
7
|
|
8
8
|
module ArExtentions
|
9
9
|
def exec_niceql
|
@@ -28,13 +28,11 @@ module RailsSQLPrettifier
|
|
28
28
|
end
|
29
29
|
|
30
30
|
module AbstractAdapterLogPrettifier
|
31
|
-
|
32
|
-
def log( sql, *args, **kwargs, &block )
|
31
|
+
def log( sql, *args, &block )
|
33
32
|
# \n need to be placed because AR log will start with action description + time info.
|
34
33
|
# rescue sql - just to be sure Prettifier wouldn't break production
|
35
34
|
formatted_sql = "\n" + Niceql::Prettifier.prettify_sql(sql) rescue sql
|
36
|
-
|
37
|
-
super( formatted_sql, *args, **kwargs, &block )
|
35
|
+
super( formatted_sql, *args, &block )
|
38
36
|
end
|
39
37
|
end
|
40
38
|
|
@@ -46,7 +44,7 @@ module RailsSQLPrettifier
|
|
46
44
|
end
|
47
45
|
end
|
48
46
|
|
49
|
-
module
|
47
|
+
module ARNiceQLConfig
|
50
48
|
extend ActiveSupport::Concern
|
51
49
|
|
52
50
|
included do
|
@@ -57,7 +55,7 @@ module RailsSQLPrettifier
|
|
57
55
|
|
58
56
|
|
59
57
|
def ar_using_pg_adapter?
|
60
|
-
ActiveRecord::Base.
|
58
|
+
ActiveRecord::Base.connection_db_config.adapter == 'postgresql'
|
61
59
|
end
|
62
60
|
|
63
61
|
def initialize
|
@@ -66,26 +64,17 @@ module RailsSQLPrettifier
|
|
66
64
|
self.prettify_active_record_log_output = false
|
67
65
|
self.prettify_pg_errors = ar_using_pg_adapter?
|
68
66
|
end
|
69
|
-
end
|
70
|
-
|
71
|
-
module NiceqlExt
|
72
|
-
def configure
|
73
|
-
super
|
74
67
|
|
75
|
-
|
76
|
-
|
77
|
-
|
68
|
+
module ClassMethods
|
69
|
+
def configure
|
70
|
+
super
|
78
71
|
|
79
|
-
|
72
|
+
::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.include(PostgresAdapterNiceQL) if config.pg_adapter_with_nicesql
|
80
73
|
|
81
|
-
|
82
|
-
end
|
83
|
-
end
|
74
|
+
::ActiveRecord::ConnectionAdapters::AbstractAdapter.prepend( AbstractAdapterLogPrettifier ) if config.prettify_active_record_log_output
|
84
75
|
|
85
|
-
|
86
|
-
|
87
|
-
ActiveRecord::Base.connection.migration_context.protected_environment? ||
|
88
|
-
defined?(Rails) && !(Rails.env.test? || Rails.env.development?)
|
76
|
+
::ActiveRecord::StatementInvalid.include( Niceql::ErrorExt ) if config.prettify_pg_errors && config.ar_using_pg_adapter?
|
77
|
+
end
|
89
78
|
end
|
90
79
|
end
|
91
80
|
|
@@ -93,9 +82,5 @@ module RailsSQLPrettifier
|
|
93
82
|
::Arel::TreeManager,
|
94
83
|
::Arel::Nodes::Node].each { |klass| klass.send(:include, ArExtentions) }
|
95
84
|
|
96
|
-
|
97
|
-
|
98
|
-
# we need to use a prepend otherwise it's not preceding Niceql.configure in a lookup chain
|
99
|
-
Niceql.singleton_class.prepend( NiceqlExt )
|
100
|
-
Niceql.extend(ProtectedEnv)
|
85
|
+
NiceQLConfig.include( ARNiceQLConfig )
|
101
86
|
end
|
@@ -31,18 +31,15 @@ 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
|
-
|
34
|
+
spec.add_dependency "niceql", '~> 0.5'
|
35
|
+
|
36
|
+
spec.add_development_dependency "activerecord", '>= 6.1', '< 7'
|
36
37
|
|
37
38
|
spec.add_development_dependency "bundler", ">= 1"
|
38
39
|
spec.add_development_dependency "rake", ">= 12.3.3"
|
39
40
|
spec.add_development_dependency "minitest", "~> 5.0"
|
40
41
|
|
41
|
-
spec.add_development_dependency "awesome_print"
|
42
42
|
spec.add_development_dependency "differ", '~> 0.1'
|
43
43
|
spec.add_development_dependency "pry-byebug", '~> 3.9'
|
44
44
|
spec.add_development_dependency 'sqlite3', '~> 1'
|
45
|
-
spec.add_development_dependency 'pg', '~> 1'
|
46
|
-
|
47
|
-
spec.add_development_dependency 'stubberry', '~> 0.2'
|
48
45
|
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: 6.
|
4
|
+
version: 6.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- alekseyl
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-01-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: niceql
|
@@ -16,34 +16,34 @@ 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
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '6.
|
33
|
+
version: '6.1'
|
34
34
|
- - "<"
|
35
35
|
- !ruby/object:Gem::Version
|
36
|
-
version: '
|
37
|
-
type: :
|
36
|
+
version: '7'
|
37
|
+
type: :development
|
38
38
|
prerelease: false
|
39
39
|
version_requirements: !ruby/object:Gem::Requirement
|
40
40
|
requirements:
|
41
41
|
- - ">="
|
42
42
|
- !ruby/object:Gem::Version
|
43
|
-
version: '6.
|
43
|
+
version: '6.1'
|
44
44
|
- - "<"
|
45
45
|
- !ruby/object:Gem::Version
|
46
|
-
version: '
|
46
|
+
version: '7'
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: bundler
|
49
49
|
requirement: !ruby/object:Gem::Requirement
|
@@ -86,20 +86,6 @@ dependencies:
|
|
86
86
|
- - "~>"
|
87
87
|
- !ruby/object:Gem::Version
|
88
88
|
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
89
|
- !ruby/object:Gem::Dependency
|
104
90
|
name: differ
|
105
91
|
requirement: !ruby/object:Gem::Requirement
|
@@ -142,34 +128,6 @@ dependencies:
|
|
142
128
|
- - "~>"
|
143
129
|
- !ruby/object:Gem::Version
|
144
130
|
version: '1'
|
145
|
-
- !ruby/object:Gem::Dependency
|
146
|
-
name: pg
|
147
|
-
requirement: !ruby/object:Gem::Requirement
|
148
|
-
requirements:
|
149
|
-
- - "~>"
|
150
|
-
- !ruby/object:Gem::Version
|
151
|
-
version: '1'
|
152
|
-
type: :development
|
153
|
-
prerelease: false
|
154
|
-
version_requirements: !ruby/object:Gem::Requirement
|
155
|
-
requirements:
|
156
|
-
- - "~>"
|
157
|
-
- !ruby/object:Gem::Version
|
158
|
-
version: '1'
|
159
|
-
- !ruby/object:Gem::Dependency
|
160
|
-
name: stubberry
|
161
|
-
requirement: !ruby/object:Gem::Requirement
|
162
|
-
requirements:
|
163
|
-
- - "~>"
|
164
|
-
- !ruby/object:Gem::Version
|
165
|
-
version: '0.2'
|
166
|
-
type: :development
|
167
|
-
prerelease: false
|
168
|
-
version_requirements: !ruby/object:Gem::Requirement
|
169
|
-
requirements:
|
170
|
-
- - "~>"
|
171
|
-
- !ruby/object:Gem::Version
|
172
|
-
version: '0.2'
|
173
131
|
description: 'This is an ActiveRecord integration for the SQL prettifier gem niceql. '
|
174
132
|
email:
|
175
133
|
- leshchuk@gmail.com
|
@@ -177,20 +135,18 @@ executables: []
|
|
177
135
|
extensions: []
|
178
136
|
extra_rdoc_files: []
|
179
137
|
files:
|
138
|
+
- ".byebug_history"
|
180
139
|
- ".gitignore"
|
181
140
|
- ".ruby-gemset"
|
182
141
|
- ".ruby-version"
|
183
142
|
- ".travis.yml"
|
184
143
|
- CHANGELOG.md
|
185
|
-
- Dockerfile
|
186
|
-
- Dockerfile_30
|
187
144
|
- Gemfile
|
188
145
|
- LICENSE.txt
|
189
146
|
- README.md
|
190
147
|
- Rakefile
|
191
148
|
- bin/console
|
192
149
|
- bin/setup
|
193
|
-
- docker-compose.yml
|
194
150
|
- err_now.png
|
195
151
|
- err_was.png
|
196
152
|
- lib/benchmark/cat.rb
|
data/Dockerfile
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
FROM ruby:2.7.5-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
|
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
|
data/docker-compose.yml
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
version: "3.7"
|
2
|
-
|
3
|
-
services:
|
4
|
-
test:
|
5
|
-
build: .
|
6
|
-
image: rsp_6_0
|
7
|
-
command: /bin/bash -c 'service postgresql start && rake test'
|
8
|
-
volumes:
|
9
|
-
- '.:/app'
|
10
|
-
|
11
|
-
test_3_0:
|
12
|
-
build:
|
13
|
-
context: .
|
14
|
-
dockerfile: Dockerfile_30
|
15
|
-
image: rsp_6_0_3_0
|
16
|
-
command: /bin/bash -c 'service postgresql start && rake test'
|
17
|
-
volumes:
|
18
|
-
- '.:/app'
|
19
|
-
|