arql 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/arql.gemspec +2 -2
- data/lib/arql/app.rb +40 -3
- data/lib/arql/cli.rb +12 -0
- data/lib/arql/connection.rb +0 -2
- data/lib/arql/multi_io.rb +20 -0
- data/lib/arql/version.rb +1 -1
- data/lib/arql.rb +3 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f4f6b01a4cae5f453322b2adf85b21ca4442d83dc07c504b73048b2640322af5
|
4
|
+
data.tar.gz: 78b66856a6bb72ae2247b3f1f6ea82434696fd5f5f345fda904f6017fcd4c009
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d01f9fe3b5a3264476e76eb8446054daec67648edefe1d67c7b1c97ed96f8695d924b48b4a5c7b3f60ac535ccfdb9919d2106f6517b7f898289c8970a0574642
|
7
|
+
data.tar.gz: c6be97e00d33908f45866c267b054c913e615b4f594b6baccf72d374a8e92b30136b7cd4e122cacdd7ffbf80dd1a8925b2e7e2a676edf4a2aec0f56a9058e054
|
data/Gemfile.lock
CHANGED
data/arql.gemspec
CHANGED
@@ -6,8 +6,8 @@ Gem::Specification.new do |spec|
|
|
6
6
|
spec.authors = ["Liu Xiang"]
|
7
7
|
spec.email = ["liuxiang921@gmail.com"]
|
8
8
|
|
9
|
-
spec.summary = %{Rails ActiveRecord is the best SQL query editor
|
10
|
-
spec.description = %{
|
9
|
+
spec.summary = %{Rails ActiveRecord + Pry is the best SQL query editor}
|
10
|
+
spec.description = %{Use ActiveRecord and Pry as your favorite SQL query editor.}
|
11
11
|
spec.homepage = "https://github.com/lululau/arql"
|
12
12
|
spec.license = "MIT"
|
13
13
|
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
data/lib/arql/app.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'active_support/core_ext/hash'
|
2
|
-
|
3
1
|
module Arql
|
4
2
|
class App
|
5
3
|
def initialize(options)
|
@@ -21,7 +19,7 @@ module Arql
|
|
21
19
|
port: @options.db_port
|
22
20
|
}
|
23
21
|
else
|
24
|
-
|
22
|
+
db_config
|
25
23
|
end
|
26
24
|
end
|
27
25
|
|
@@ -29,7 +27,14 @@ module Arql
|
|
29
27
|
@config ||= YAML.load(IO.read(@options.config_file)).with_indifferent_access
|
30
28
|
end
|
31
29
|
|
30
|
+
def db_config
|
31
|
+
config[:db][@options.env]
|
32
|
+
end
|
33
|
+
|
32
34
|
def run!
|
35
|
+
show_sql if should_show_sql?
|
36
|
+
write_sql if should_write_sql?
|
37
|
+
append_sql if should_append_sql?
|
33
38
|
if @options.code.present?
|
34
39
|
eval(@options.code)
|
35
40
|
elsif @options.args.present?
|
@@ -46,5 +51,37 @@ module Arql
|
|
46
51
|
def use_db_cmd_options?
|
47
52
|
@options.db_host.present?
|
48
53
|
end
|
54
|
+
|
55
|
+
def should_show_sql?
|
56
|
+
@options.show_sql || db_config[:show_sql]
|
57
|
+
end
|
58
|
+
|
59
|
+
def should_write_sql?
|
60
|
+
@options.write_sql || db_config[:write_sql]
|
61
|
+
end
|
62
|
+
|
63
|
+
def should_append_sql?
|
64
|
+
@options.append_sql || db_config[:append_sql]
|
65
|
+
end
|
66
|
+
|
67
|
+
def show_sql
|
68
|
+
@log_io ||= MultiIO.new
|
69
|
+
ActiveRecord::Base.logger = Logger.new(@log_io)
|
70
|
+
@log_io << STDOUT
|
71
|
+
end
|
72
|
+
|
73
|
+
def write_sql
|
74
|
+
write_sql_file = @options.write_sql || db_config[:write_sql]
|
75
|
+
@log_io ||= MultiIO.new
|
76
|
+
ActiveRecord::Base.logger = Logger.new(@log_io)
|
77
|
+
@log_io << File.new(write_sql_file, 'w')
|
78
|
+
end
|
79
|
+
|
80
|
+
def append_sql
|
81
|
+
write_sql_file = @options.append_sql || db_config[:append_sql]
|
82
|
+
@log_io ||= MultiIO.new
|
83
|
+
ActiveRecord::Base.logger = Logger.new(@log_io)
|
84
|
+
@log_io << File.new(write_sql_file, 'a')
|
85
|
+
end
|
49
86
|
end
|
50
87
|
end
|
data/lib/arql/cli.rb
CHANGED
@@ -78,6 +78,18 @@ module Arql
|
|
78
78
|
@options.code = code
|
79
79
|
end
|
80
80
|
|
81
|
+
opts.on('-s', '--show-sql', 'Show SQL on STDOUT') do
|
82
|
+
@options.show_sql = true
|
83
|
+
end
|
84
|
+
|
85
|
+
opts.on('-wOUTOUT', '--write-sql=OUTPUT', 'Write SQL to OUTPUT file') do |file|
|
86
|
+
@options.write_sql = file
|
87
|
+
end
|
88
|
+
|
89
|
+
opts.on('-aOUTPUT', '--append-sql=OUTPUT', 'Append SQL to OUTPUT file') do |file|
|
90
|
+
@options.append_sql = file
|
91
|
+
end
|
92
|
+
|
81
93
|
opts.on('-h', '--help', 'Prints this help') do
|
82
94
|
puts opts
|
83
95
|
exit
|
data/lib/arql/connection.rb
CHANGED
@@ -0,0 +1,20 @@
|
|
1
|
+
module Arql
|
2
|
+
class MultiIO
|
3
|
+
def initialize(*targets)
|
4
|
+
@targets = targets
|
5
|
+
end
|
6
|
+
|
7
|
+
def write(*args)
|
8
|
+
@targets.each {|t| t.write(*args)}
|
9
|
+
end
|
10
|
+
|
11
|
+
def close
|
12
|
+
@targets.each(&:close)
|
13
|
+
end
|
14
|
+
|
15
|
+
def <<(target)
|
16
|
+
@targets ||= []
|
17
|
+
@targets << target
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/arql/version.rb
CHANGED
data/lib/arql.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: arql
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Liu Xiang
|
@@ -80,7 +80,7 @@ dependencies:
|
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: 3.9.0
|
83
|
-
description:
|
83
|
+
description: Use ActiveRecord and Pry as your favorite SQL query editor.
|
84
84
|
email:
|
85
85
|
- liuxiang921@gmail.com
|
86
86
|
executables:
|
@@ -104,6 +104,7 @@ files:
|
|
104
104
|
- lib/arql/cli.rb
|
105
105
|
- lib/arql/connection.rb
|
106
106
|
- lib/arql/definition.rb
|
107
|
+
- lib/arql/multi_io.rb
|
107
108
|
- lib/arql/repl.rb
|
108
109
|
- lib/arql/version.rb
|
109
110
|
homepage: https://github.com/lululau/arql
|
@@ -128,5 +129,5 @@ requirements: []
|
|
128
129
|
rubygems_version: 3.1.2
|
129
130
|
signing_key:
|
130
131
|
specification_version: 4
|
131
|
-
summary: Rails ActiveRecord is the best SQL query editor
|
132
|
+
summary: Rails ActiveRecord + Pry is the best SQL query editor
|
132
133
|
test_files: []
|