arql 0.1.30
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +72 -0
- data/LICENSE.txt +21 -0
- data/README.md +456 -0
- data/Rakefile +2 -0
- data/arql.gemspec +40 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/exe/arql +7 -0
- data/exe/arql_setsid_wrapper +5 -0
- data/lib/arql.rb +12 -0
- data/lib/arql/app.rb +137 -0
- data/lib/arql/cli.rb +141 -0
- data/lib/arql/commands.rb +9 -0
- data/lib/arql/commands/info.rb +52 -0
- data/lib/arql/commands/models.rb +40 -0
- data/lib/arql/commands/reconnect.rb +23 -0
- data/lib/arql/commands/redefine.rb +15 -0
- data/lib/arql/commands/show_sql.rb +25 -0
- data/lib/arql/commands/table.rb +55 -0
- data/lib/arql/connection.rb +10 -0
- data/lib/arql/definition.rb +180 -0
- data/lib/arql/ext.rb +5 -0
- data/lib/arql/ext/array.rb +65 -0
- data/lib/arql/ext/kernel.rb +5 -0
- data/lib/arql/ext/object.rb +18 -0
- data/lib/arql/ext/string.rb +5 -0
- data/lib/arql/ext/time.rb +15 -0
- data/lib/arql/id.rb +59 -0
- data/lib/arql/multi_io.rb +28 -0
- data/lib/arql/repl.rb +38 -0
- data/lib/arql/ssh_proxy.rb +31 -0
- data/lib/arql/ssh_proxy_patch.rb +88 -0
- data/lib/arql/version.rb +3 -0
- metadata +235 -0
@@ -0,0 +1,28 @@
|
|
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
|
+
|
20
|
+
def delete(io)
|
21
|
+
@targets.delete(io)
|
22
|
+
end
|
23
|
+
|
24
|
+
def include?(io)
|
25
|
+
@targets.include?(io)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/arql/repl.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'pry'
|
2
|
+
require 'pry-byebug'
|
3
|
+
require 'arql/commands'
|
4
|
+
require 'rainbow'
|
5
|
+
|
6
|
+
module Arql
|
7
|
+
class Repl
|
8
|
+
def initialize
|
9
|
+
Pry.config.prompt = Pry::Prompt.new("", "", prompt)
|
10
|
+
main_object.pry
|
11
|
+
end
|
12
|
+
|
13
|
+
def main_object
|
14
|
+
return @main if @main
|
15
|
+
@main = Object.new
|
16
|
+
@main.instance_eval do
|
17
|
+
def inspect
|
18
|
+
to_s
|
19
|
+
end
|
20
|
+
def to_s
|
21
|
+
"main"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
@main
|
25
|
+
end
|
26
|
+
|
27
|
+
def prompt
|
28
|
+
[proc do |obj, nest_level, _|
|
29
|
+
if obj == main_object && nest_level == 0
|
30
|
+
nest_level_prompt = ''
|
31
|
+
else
|
32
|
+
nest_level_prompt = "(#{obj}:#{nest_level})"
|
33
|
+
end
|
34
|
+
"%s#{Rainbow('@').green}%s#{nest_level_prompt} %s " % [Rainbow('ARQL').red, Rainbow(App.env).yellow, Rainbow('❯').green]
|
35
|
+
end]
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'net/ssh/gateway'
|
2
|
+
require 'arql/ssh_proxy_patch'
|
3
|
+
|
4
|
+
module Arql
|
5
|
+
class SSHProxy
|
6
|
+
class << self
|
7
|
+
|
8
|
+
attr_accessor :config, :ssh_gateway, :local_ssh_proxy_port
|
9
|
+
|
10
|
+
def connect(config)
|
11
|
+
@config = config
|
12
|
+
@ssh_gateway = Net::SSH::Gateway.new(config[:host], config[:user], config.slice(:port, :password).symbolize_keys.merge(keepalive: true, keepalive_interval: 30, loop_wait: 1))
|
13
|
+
@local_ssh_proxy_port = @ssh_gateway.open(config[:forward_host], config[:forward_port], config[:local_port])
|
14
|
+
end
|
15
|
+
|
16
|
+
def reconnect
|
17
|
+
reconnect! unless @ssh_gateway.active?
|
18
|
+
end
|
19
|
+
|
20
|
+
def reconnect!
|
21
|
+
@ssh_gateway.shutdown!
|
22
|
+
@ssh_gateway = Net::SSH::Gateway.new(@config[:host], @config[:user], @config.slice(:port, :password).symbolize_keys)
|
23
|
+
@ssh_gateway.open(config[:forward_host], config[:forward_port], @local_ssh_proxy_port)
|
24
|
+
end
|
25
|
+
|
26
|
+
def active?
|
27
|
+
@ssh_gateway.active?
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
require 'net/ssh/proxy/command'
|
2
|
+
|
3
|
+
module Net
|
4
|
+
module SSH
|
5
|
+
module Proxy
|
6
|
+
class Command
|
7
|
+
|
8
|
+
# Return a new socket connected to the given host and port via the
|
9
|
+
# proxy that was requested when the socket factory was instantiated.
|
10
|
+
def open(host, port, connection_options = nil)
|
11
|
+
command_line = @command_line_template.gsub(/%(.)/) {
|
12
|
+
case $1
|
13
|
+
when 'h'
|
14
|
+
host
|
15
|
+
when 'p'
|
16
|
+
port.to_s
|
17
|
+
when 'r'
|
18
|
+
remote_user = connection_options && connection_options[:remote_user]
|
19
|
+
if remote_user
|
20
|
+
remote_user
|
21
|
+
else
|
22
|
+
raise ArgumentError, "remote user name not available"
|
23
|
+
end
|
24
|
+
when '%'
|
25
|
+
'%'
|
26
|
+
else
|
27
|
+
raise ArgumentError, "unknown key: #{$1}"
|
28
|
+
end
|
29
|
+
}
|
30
|
+
command_line = '%s %s' % [ArqlSetsidWrrapper, command_line]
|
31
|
+
begin
|
32
|
+
io = IO.popen(command_line, "r+")
|
33
|
+
begin
|
34
|
+
if result = IO.select([io], nil, [io], @timeout)
|
35
|
+
if result.last.any? || io.eof?
|
36
|
+
raise "command failed"
|
37
|
+
end
|
38
|
+
else
|
39
|
+
raise "command timed out"
|
40
|
+
end
|
41
|
+
rescue StandardError
|
42
|
+
close_on_error(io)
|
43
|
+
raise
|
44
|
+
end
|
45
|
+
rescue StandardError => e
|
46
|
+
raise ConnectError, "#{e}: #{command_line}"
|
47
|
+
end
|
48
|
+
@command_line = command_line
|
49
|
+
if Gem.win_platform?
|
50
|
+
# read_nonblock and write_nonblock are not available on Windows
|
51
|
+
# pipe. Use sysread and syswrite as a replacement works.
|
52
|
+
def io.send(data, flag)
|
53
|
+
syswrite(data)
|
54
|
+
end
|
55
|
+
|
56
|
+
def io.recv(size)
|
57
|
+
sysread(size)
|
58
|
+
end
|
59
|
+
else
|
60
|
+
def io.send(data, flag)
|
61
|
+
begin
|
62
|
+
result = write_nonblock(data)
|
63
|
+
rescue IO::WaitWritable, Errno::EINTR
|
64
|
+
IO.select(nil, [self])
|
65
|
+
retry
|
66
|
+
end
|
67
|
+
result
|
68
|
+
end
|
69
|
+
|
70
|
+
def io.recv(size)
|
71
|
+
begin
|
72
|
+
result = read_nonblock(size)
|
73
|
+
rescue IO::WaitReadable, Errno::EINTR
|
74
|
+
timeout_in_seconds = 20
|
75
|
+
if IO.select([self], nil, [self], timeout_in_seconds) == nil
|
76
|
+
raise "Unexpected spurious read wakeup"
|
77
|
+
end
|
78
|
+
retry
|
79
|
+
end
|
80
|
+
result
|
81
|
+
end
|
82
|
+
end
|
83
|
+
io
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
data/lib/arql/version.rb
ADDED
metadata
ADDED
@@ -0,0 +1,235 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: arql
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.30
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Liu Xiang
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-07-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: mysql2
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.5.3
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.5.3
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: sqlite3
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.4'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.4'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: activerecord
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 6.0.3
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 6.0.3
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: activesupport
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 6.0.3
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 6.0.3
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: net-ssh-gateway
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 2.0.0
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 2.0.0
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: pry
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 0.13.1
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 0.13.1
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: pry-byebug
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 3.9.0
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 3.9.0
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: pry-doc
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 1.1.0
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 1.1.0
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: rainbow
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: 3.0.0
|
132
|
+
type: :runtime
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: 3.0.0
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: terminal-table
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - "~>"
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: 1.8.0
|
146
|
+
type: :runtime
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - "~>"
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: 1.8.0
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: table_print
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - "~>"
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: 1.5.6
|
160
|
+
type: :runtime
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - "~>"
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: 1.5.6
|
167
|
+
description: Use ActiveRecord and Pry as your favorite SQL query editor.
|
168
|
+
email:
|
169
|
+
- liuxiang921@gmail.com
|
170
|
+
executables:
|
171
|
+
- arql
|
172
|
+
- arql_setsid_wrapper
|
173
|
+
extensions: []
|
174
|
+
extra_rdoc_files: []
|
175
|
+
files:
|
176
|
+
- ".gitignore"
|
177
|
+
- CODE_OF_CONDUCT.md
|
178
|
+
- Gemfile
|
179
|
+
- Gemfile.lock
|
180
|
+
- LICENSE.txt
|
181
|
+
- README.md
|
182
|
+
- Rakefile
|
183
|
+
- arql.gemspec
|
184
|
+
- bin/console
|
185
|
+
- bin/setup
|
186
|
+
- exe/arql
|
187
|
+
- exe/arql_setsid_wrapper
|
188
|
+
- lib/arql.rb
|
189
|
+
- lib/arql/app.rb
|
190
|
+
- lib/arql/cli.rb
|
191
|
+
- lib/arql/commands.rb
|
192
|
+
- lib/arql/commands/info.rb
|
193
|
+
- lib/arql/commands/models.rb
|
194
|
+
- lib/arql/commands/reconnect.rb
|
195
|
+
- lib/arql/commands/redefine.rb
|
196
|
+
- lib/arql/commands/show_sql.rb
|
197
|
+
- lib/arql/commands/table.rb
|
198
|
+
- lib/arql/connection.rb
|
199
|
+
- lib/arql/definition.rb
|
200
|
+
- lib/arql/ext.rb
|
201
|
+
- lib/arql/ext/array.rb
|
202
|
+
- lib/arql/ext/kernel.rb
|
203
|
+
- lib/arql/ext/object.rb
|
204
|
+
- lib/arql/ext/string.rb
|
205
|
+
- lib/arql/ext/time.rb
|
206
|
+
- lib/arql/id.rb
|
207
|
+
- lib/arql/multi_io.rb
|
208
|
+
- lib/arql/repl.rb
|
209
|
+
- lib/arql/ssh_proxy.rb
|
210
|
+
- lib/arql/ssh_proxy_patch.rb
|
211
|
+
- lib/arql/version.rb
|
212
|
+
homepage: https://github.com/lululau/arql
|
213
|
+
licenses:
|
214
|
+
- MIT
|
215
|
+
metadata: {}
|
216
|
+
post_install_message:
|
217
|
+
rdoc_options: []
|
218
|
+
require_paths:
|
219
|
+
- lib
|
220
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
221
|
+
requirements:
|
222
|
+
- - ">="
|
223
|
+
- !ruby/object:Gem::Version
|
224
|
+
version: 2.3.0
|
225
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
226
|
+
requirements:
|
227
|
+
- - ">="
|
228
|
+
- !ruby/object:Gem::Version
|
229
|
+
version: '0'
|
230
|
+
requirements: []
|
231
|
+
rubygems_version: 3.1.2
|
232
|
+
signing_key:
|
233
|
+
specification_version: 4
|
234
|
+
summary: Rails ActiveRecord + Pry is the best SQL query editor
|
235
|
+
test_files: []
|