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 +4 -4
- data/app/models/adhoq/execution.rb +3 -1
- data/app/views/adhoq/current_tables/index.html.slim +2 -1
- data/app/views/adhoq/queries/_query.html.slim +1 -1
- data/lib/adhoq/configuration.rb +1 -0
- data/lib/adhoq/executor/connection_wrapper.rb +12 -8
- data/lib/adhoq/global_variable.rb +1 -0
- data/lib/adhoq/storage.rb +1 -0
- data/lib/adhoq/storage/cache.rb +27 -0
- data/lib/adhoq/version.rb +1 -1
- data/spec/models/adhoq/execution_spec.rb +18 -0
- metadata +10 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 55ebbfcb4634de6d7ff7b565a620aea07cdb739c
|
4
|
+
data.tar.gz: 4a46756086ac03ff5f8564797fff26522fb0f4a2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 19c49904e45e9eedf169134bc6564448e0974af82a61862bc8fffc33c3bd1a921cb976acf7c962e34b963b38ec99ad06f21b0d0c07ec6dd3bed30856901cec1c
|
7
|
+
data.tar.gz: cae892aac89db0af6e29568fac5aac68c2adab131315fa87fdf38dd8a002e9397c8b85dd2864f4b09c0fb745799597d0a313c0c56e3e6288662d94977b6508b7
|
@@ -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
|
-
|
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
|
data/lib/adhoq/configuration.rb
CHANGED
@@ -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
|
-
|
25
|
-
|
26
|
-
|
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
|
data/lib/adhoq/storage.rb
CHANGED
@@ -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
|
data/lib/adhoq/version.rb
CHANGED
@@ -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.
|
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-
|
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.
|
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
|