rails-pg-extras-web 1.4.1 → 1.5.3

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
2
  SHA256:
3
- metadata.gz: abc008aaf05163eebc554ac1bb9eb7746f51fe83ff7557c4f924e5fc19b151ae
4
- data.tar.gz: 41a7833a4550b17c93a884a9abdd17b7304822db9dc85d560469469e8728791e
3
+ metadata.gz: d0867a93537ef7b75064a408a632ab466f1ff2e8163de3b6dc604b3bcaad9bbe
4
+ data.tar.gz: 2ad9ef98329c15accb2e02974fed7101611b95cae8dbf77bef77be9caa9ef6a1
5
5
  SHA512:
6
- metadata.gz: f0527a2d23300b0602a807e68fb2c058941051cac537f0828420a3cd8ac3a450df256c43dd52dba9e9556705015cd86833cea9e0c470866e3c9b5e5d60b51b05
7
- data.tar.gz: 6dcd0d8dc82528e9eaa3afd75caec3e9642c54bb7115410982914ea313b22e37fcadec35fa44884c1c987efbb98ba1470e989c55fbe8d9e06a1168644a8f7d7d
6
+ metadata.gz: e1cbdfad662c7da11b61d4675cab7eaee7c5498bda223771fa634cb5b8498da5f2bfe7c378fb370363d22c3404367e4dc1c63f8debca87ff70d81df2a6ce8dd6
7
+ data.tar.gz: a1331dbb06b9017fd36b3776f543a91fef069b62722cb31f3d229a2c6a05d8f6ba3b5aff6c1b45587de3cceebffd71dac4c75ee3be871fdefe437e1ddb143a45
@@ -7,30 +7,5 @@ module RailsPgExtrasWeb
7
7
  if Rails.env.production? && ENV['PG_EXTRAS_USER'].present? && ENV['PG_EXTRAS_PASSWORD'].present?
8
8
  http_basic_authenticate_with name: ENV['PG_EXTRAS_USER'], password: ENV['PG_EXTRAS_PASSWORD']
9
9
  end
10
-
11
- protect_from_forgery with: :exception
12
-
13
- helper_method :pg_stats_statements_enabled?
14
-
15
- private
16
-
17
- def load_queries
18
- @all_queries = {}
19
-
20
- ::RailsPGExtras::QUERIES.each do |query_name|
21
- @all_queries[query_name] = {
22
- disabled: query_disabled?(query_name),
23
- command: query_name == :kill_all
24
- }
25
- end
26
- end
27
-
28
- def query_disabled?(query_name)
29
- query_name.in?([:calls, :outliers]) && !pg_stats_statements_enabled?
30
- end
31
-
32
- def pg_stats_statements_enabled?
33
- ActiveRecord::Base.connection.extensions.include?("pg_stat_statements")
34
- end
35
10
  end
36
11
  end
@@ -1,19 +1,36 @@
1
1
  module RailsPgExtrasWeb
2
2
  class QueriesController < ApplicationController
3
3
  before_action :load_queries
4
+ helper_method :pg_stats_statements_enabled?
4
5
 
5
- def index; end
6
+ def index
7
+ @query_name = params[:query_name]&.to_sym.presence_in(@all_queries.keys)
8
+ return unless @query_name
6
9
 
7
- def run
8
- if @query_name = params[:query_name].presence
9
- begin
10
- @result = RailsPGExtras.run_query(query_name: @query_name.to_sym, in_format: :raw)
11
- rescue ActiveRecord::StatementInvalid => e
12
- @error = e.message
13
- end
14
- else
15
- redirect_to root_path
10
+ @result = RailsPGExtras.run_query(query_name: @query_name.to_sym, in_format: :raw)
11
+ rescue ActiveRecord::StatementInvalid => e
12
+ @error = e.message
13
+ end
14
+
15
+ private
16
+
17
+ def load_queries
18
+ @all_queries = {}
19
+
20
+ ::RailsPGExtras::QUERIES.each do |query_name|
21
+ @all_queries[query_name] = {
22
+ disabled: query_disabled?(query_name),
23
+ command: query_name == :kill_all
24
+ }
16
25
  end
17
26
  end
27
+
28
+ def query_disabled?(query_name)
29
+ query_name.in?([:calls, :outliers]) && !pg_stats_statements_enabled?
30
+ end
31
+
32
+ def pg_stats_statements_enabled?
33
+ ActiveRecord::Base.connection.extensions.include?("pg_stat_statements")
34
+ end
18
35
  end
19
36
  end
@@ -2,11 +2,9 @@
2
2
  <html>
3
3
  <head>
4
4
  <title>PG::Extras</title>
5
- <%= csrf_meta_tags %>
6
- <%= csp_meta_tag %>
7
5
  </head>
8
6
  <body onload="document.forms.queries.query_name.focus()">
9
- <%= form_with url: run_query_url, id: "queries" do |f| %>
7
+ <%= form_with url: queries_path, id: "queries", method: :get do |f| %>
10
8
  <%= f.select :query_name, options_for_select(@all_queries.except(:kill_all, :mandelbrot), params[:query_name]),
11
9
  prompt: "--- select query ---"
12
10
  %>
@@ -8,3 +8,63 @@
8
8
  <h4>SQL</h4>
9
9
  <pre style='background-color: #e2e2e2; padding: 10px'>CREATE EXTENSION pg_stat_statements</pre>
10
10
  <% end %>
11
+
12
+ <% if @error %>
13
+ <span style='color: red'><%= @error %></span>
14
+ <% else %>
15
+ <% if @result && @result.any? %>
16
+ <table>
17
+ <caption><%= RubyPGExtras.description_for(query_name: @query_name) %></caption>
18
+ <thead>
19
+ <tr>
20
+ <% @result[0].keys.each do |header| %>
21
+ <th><%= header %></th>
22
+ <% end %>
23
+ </tr>
24
+ </thead>
25
+ <tbody>
26
+ <% @result.values.each do |row| %>
27
+ <tr>
28
+ <% row.each do |column| %>
29
+ <td><%= column %></td>
30
+ <% end %>
31
+ </tr>
32
+ <% end %>
33
+ </tbody>
34
+ </table>
35
+
36
+ <pre>run_at: <%= Time.now.utc %></pre>
37
+ <% else %>
38
+ <pre>No results</pre>
39
+ <% end %>
40
+ <% end %>
41
+
42
+ <style media="screen">
43
+ table {
44
+ font-family: monospace;
45
+ border-collapse: collapse;
46
+ width: 100%;
47
+ }
48
+
49
+ table th {
50
+ background-color: #c9c9;
51
+ }
52
+
53
+ table th, table td {
54
+ text-align: left;
55
+ border: 1px solid #c9c9;
56
+ padding: 3px;
57
+ }
58
+
59
+ table td {
60
+ overflow: hidden;
61
+ text-overflow: ellipsis;
62
+ white-space: nowrap;
63
+ }
64
+
65
+ table caption {
66
+ padding: 5px;
67
+ font-size: 15px;
68
+ font-weight: bold;
69
+ }
70
+ </style>
data/config/routes.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  RailsPgExtrasWeb::Engine.routes.draw do
2
- root to: "queries#index"
2
+ resources :queries, only: :index
3
3
 
4
- post "/queries/run", as: :run_query
4
+ root to: "queries#index"
5
5
  end
@@ -1,3 +1,3 @@
1
1
  module RailsPgExtrasWeb
2
- VERSION = '1.4.1'
2
+ VERSION = '1.5.3'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-pg-extras-web
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.1
4
+ version: 1.5.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tomasz Mazur
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-02-04 00:00:00.000000000 Z
11
+ date: 2021-03-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pg
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 1.4.0
33
+ version: 1.5.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 1.4.0
40
+ version: 1.5.0
41
41
  description:
42
42
  email:
43
43
  - tomasz.mazur@hey.com
@@ -52,7 +52,6 @@ files:
52
52
  - app/controllers/rails_pg_extras_web/queries_controller.rb
53
53
  - app/views/layouts/rails_pg_extras_web/application.html.erb
54
54
  - app/views/rails_pg_extras_web/queries/index.html.erb
55
- - app/views/rails_pg_extras_web/queries/run.html.erb
56
55
  - config/routes.rb
57
56
  - lib/rails-pg-extras-web.rb
58
57
  - lib/rails_pg_extras_web/engine.rb
@@ -1,59 +0,0 @@
1
- <% if @error %>
2
- <span style='color: red'><%= @error %></span>
3
- <% else %>
4
- <% if @result && @result.any? %>
5
- <table>
6
- <caption><%= RubyPGExtras.description_for(query_name: @query_name) %></caption>
7
- <thead>
8
- <tr>
9
- <% @result[0].keys.each do |header| %>
10
- <th><%= header %></th>
11
- <% end %>
12
- </tr>
13
- </thead>
14
- <tbody>
15
- <% @result.values.each do |row| %>
16
- <tr>
17
- <% row.each do |column| %>
18
- <td><%= column %></td>
19
- <% end %>
20
- </tr>
21
- <% end %>
22
- </tbody>
23
- </table>
24
-
25
- <pre>run_at: <%= Time.now.utc %></pre>
26
- <% else %>
27
- <pre>No results</pre>
28
- <% end %>
29
- <% end %>
30
-
31
- <style media="screen">
32
- table {
33
- font-family: monospace;
34
- border-collapse: collapse;
35
- width: 100%;
36
- }
37
-
38
- table th {
39
- background-color: #c9c9;
40
- }
41
-
42
- table th, table td {
43
- text-align: left;
44
- border: 1px solid #c9c9;
45
- padding: 3px;
46
- }
47
-
48
- table td {
49
- overflow: hidden;
50
- text-overflow: ellipsis;
51
- white-space: nowrap;
52
- }
53
-
54
- table caption {
55
- padding: 5px;
56
- font-size: 15px;
57
- font-weight: bold;
58
- }
59
- </style>