adhoq 0.3.0 → 0.4.0

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
  SHA1:
3
- metadata.gz: 47ea5ea847453ee2fd5a5fbd5e8c8d09e579998f
4
- data.tar.gz: 40fe3bee5c8f7e289c52d5ef02e42cbce70f854e
3
+ metadata.gz: 55ebbfcb4634de6d7ff7b565a620aea07cdb739c
4
+ data.tar.gz: 4a46756086ac03ff5f8564797fff26522fb0f4a2
5
5
  SHA512:
6
- metadata.gz: 4e61736b80b3946ea4ade7f4014641dc96362ee7a945d1bd24074a5edfd0c7ef9e21646c5afe24f6f5f0731d7d19c2db35130f04e41ada1fdcee8a1a88f3b472
7
- data.tar.gz: 3d7131fee5b46181dec95018313b3284e99dac5ac029d864cef5eb87970d7337b57e7c46ca954f66c412402c5ce56a93a9627ad3fcdefe9ee10a3f44d88a988f
6
+ metadata.gz: 19c49904e45e9eedf169134bc6564448e0974af82a61862bc8fffc33c3bd1a921cb976acf7c962e34b963b38ec99ad06f21b0d0c07ec6dd3bed30856901cec1c
7
+ data.tar.gz: cae892aac89db0af6e29568fac5aac68c2adab131315fa87fdf38dd8a002e9397c8b85dd2864f4b09c0fb745799597d0a313c0c56e3e6288662d94977b6508b7
@@ -10,7 +10,9 @@ module Adhoq
10
10
  def generate_report!
11
11
  build_report.generate!
12
12
  update_attributes(status: :success)
13
- rescue
13
+ rescue => e
14
+ Rails.logger.error(e)
15
+ self.report = nil
14
16
  update_attributes(status: :failure)
15
17
  end
16
18
 
@@ -14,7 +14,8 @@ ul.list-unstyled.tables
14
14
  table.table.table-striped.table-hover.table-bordered
15
15
  caption
16
16
  span.name= ar_class.table_name
17
- small.count #{ar_class.unscoped.count} rows
17
+ - unless Adhoq.config.hide_rows_count
18
+ small.count #{ar_class.unscoped.count} rows
18
19
  thead
19
20
  tr
20
21
  th.col-sm-1.pk PK
@@ -43,6 +43,6 @@ section.query
43
43
  th.status= human(Adhoq::Execution, :status)
44
44
  th.report
45
45
  tbody
46
- - query.executions.recent_first.each do |exec|
46
+ - query.executions.recent_first.preload(:report).each do |exec|
47
47
  - next if exec.report.try(:on_the_fly?)
48
48
  = render 'execution', query: query, exec: exec
@@ -18,6 +18,7 @@ module Adhoq
18
18
 
19
19
  config_accessor :database_connection
20
20
  config_accessor :hidden_model_names
21
+ config_accessor :hide_rows_count
21
22
 
22
23
  config_accessor :async_execution
23
24
  config_accessor :job_queue_name
@@ -1,29 +1,33 @@
1
1
  module Adhoq
2
2
  class Executor
3
3
  class ConnectionWrapper
4
- attr_reader :connection
5
-
6
4
  def initialize
7
- @connection = Adhoq.config.callablize(:database_connection).call
8
5
  end
9
6
 
10
7
  def select(query)
11
- with_sandbox do
8
+ with_sandbox do |connection|
12
9
  connection.exec_query(query)
13
10
  end
14
11
  end
15
12
 
16
13
  def explain(query)
17
- with_sandbox do
14
+ with_sandbox do |connection|
18
15
  connection.explain(query)
19
16
  end
20
17
  end
21
18
 
19
+ def with_connection
20
+ connection = Adhoq.config.callablize(:database_connection).call
21
+ yield(connection)
22
+ end
23
+
22
24
  def with_sandbox
23
25
  result = nil
24
- connection.transaction do
25
- result = yield
26
- raise ActiveRecord::Rollback
26
+ with_connection do |connection|
27
+ connection.transaction do
28
+ result = yield(connection)
29
+ raise ActiveRecord::Rollback
30
+ end
27
31
  end
28
32
  result
29
33
  end
@@ -28,6 +28,7 @@ module Adhoq
28
28
  when :local_file then Adhoq::Storage::LocalFile
29
29
  when :s3 then Adhoq::Storage::S3
30
30
  when :on_the_fly then Adhoq::Storage::OnTheFly
31
+ when :cache then Adhoq::Storage::Cache
31
32
  else
32
33
  raise NotImplementedError
33
34
  end
@@ -4,6 +4,7 @@ module Adhoq
4
4
  autoload 'LocalFile', 'adhoq/storage/local_file'
5
5
  autoload 'S3', 'adhoq/storage/s3'
6
6
  autoload 'OnTheFly', 'adhoq/storage/on_the_fly'
7
+ autoload 'Cache', 'adhoq/storage/cache'
7
8
 
8
9
  def with_new_identifier(suffix = nil, seed = Time.now)
9
10
  dirname, fname_seed = ['%Y-%m-%d', '%H%M%S.%L'].map {|f| seed.strftime(f) }
@@ -0,0 +1,27 @@
1
+ module Adhoq
2
+ module Storage
3
+ class Cache
4
+ attr_reader :identifier
5
+
6
+ def initialize(cache, prefix = "", expire = 300)
7
+ @cache = cache
8
+ @identifier = @prefix = prefix
9
+ @expire = expire
10
+ end
11
+
12
+ def store(suffix = nil, seed = Time.now, &block)
13
+ Adhoq::Storage.with_new_identifier(suffix, seed) do |identifier|
14
+ @cache.write(@prefix + identifier, yield.read, expires_in: @expire)
15
+ end
16
+ end
17
+
18
+ def direct_download?
19
+ false
20
+ end
21
+
22
+ def get(identifier)
23
+ @cache.read(@prefix + identifier)
24
+ end
25
+ end
26
+ end
27
+ end
@@ -1,3 +1,3 @@
1
1
  module Adhoq
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
@@ -21,5 +21,23 @@ module Adhoq
21
21
  # Accessable only once
22
22
  expect(execution.report.data).to be_nil
23
23
  end
24
+
25
+ describe '#generate_report!' do
26
+ subject { -> { execution.generate_report! } }
27
+
28
+ let(:execution) { Execution.new(query: query, raw_sql: query.query, report_format: 'csv') }
29
+
30
+ context 'when execute query successfully' do
31
+ let(:query) { create(:adhoq_query, query: 'SELECT name, description FROM adhoq_queries') }
32
+
33
+ it { is_expected.to change { execution.status.to_s }.to('success') }
34
+ end
35
+
36
+ context 'when execute query failed' do
37
+ let(:query) { create(:adhoq_query, query: 'INVALID SQL') }
38
+
39
+ it { is_expected.to change { execution.status.to_s }.to('failure') }
40
+ end
41
+ end
24
42
  end
25
43
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: adhoq
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kyosuke MOROHASHI
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-05-08 00:00:00.000000000 Z
11
+ date: 2018-08-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -456,6 +456,7 @@ files:
456
456
  - lib/adhoq/reporter/xlsx.rb
457
457
  - lib/adhoq/result.rb
458
458
  - lib/adhoq/storage.rb
459
+ - lib/adhoq/storage/cache.rb
459
460
  - lib/adhoq/storage/fog_storage.rb
460
461
  - lib/adhoq/storage/local_file.rb
461
462
  - lib/adhoq/storage/on_the_fly.rb
@@ -497,23 +498,23 @@ required_rubygems_version: !ruby/object:Gem::Requirement
497
498
  version: '0'
498
499
  requirements: []
499
500
  rubyforge_project:
500
- rubygems_version: 2.6.11
501
+ rubygems_version: 2.5.2.2
501
502
  signing_key:
502
503
  specification_version: 4
503
504
  summary: DB management console in the wild.
504
505
  test_files:
505
- - spec/adhoq/executor/connection_wrapper_spec.rb
506
- - spec/adhoq/executor_spec.rb
507
- - spec/adhoq/global_variable_spec.rb
508
- - spec/adhoq/reporter/csv_spec.rb
509
506
  - spec/adhoq/reporter/json_spec.rb
507
+ - spec/adhoq/reporter/csv_spec.rb
510
508
  - spec/adhoq/reporter/xlsx_spec.rb
511
509
  - spec/adhoq/storage_spec.rb
510
+ - spec/adhoq/executor_spec.rb
511
+ - spec/adhoq/executor/connection_wrapper_spec.rb
512
+ - spec/adhoq/global_variable_spec.rb
512
513
  - spec/factories/adhoq_queries.rb
514
+ - spec/models/adhoq/report_spec.rb
513
515
  - spec/models/adhoq/execution_spec.rb
514
516
  - spec/models/adhoq/query_spec.rb
515
- - spec/models/adhoq/report_spec.rb
516
- - spec/support/activejob_helper.rb
517
517
  - spec/support/feature_spec_helper.rb
518
+ - spec/support/activejob_helper.rb
518
519
  - spec/support/have_values_in_xlsx_sheet_matcher.rb
519
520
  - spec/spec_helper.rb