arql 0.3.5 → 0.3.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/arql/commands/vd.rb +46 -0
- data/lib/arql/commands.rb +1 -0
- data/lib/arql/definition.rb +20 -0
- data/lib/arql/ext/array.rb +29 -0
- data/lib/arql/vd.rb +41 -0
- data/lib/arql/version.rb +1 -1
- data/lib/arql.rb +1 -0
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 26a222ddbbce9305531742f9b9f160406fe36351aaac3026a1c93879de257e35
|
4
|
+
data.tar.gz: f324c816f59dc993fca822d5482f0ee43cd973f1659abcd2f2fa48b7fd80acd7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5935a72b159a97a09dbdcfa761ba57b4375c7d78a680569ba8cd88a6f95fb9543b9d70e56d62c0973dc6a99a11347d32f87bce5f8b9ea5335c35f3176b9e5ca4
|
7
|
+
data.tar.gz: 84313b888ed601eafdce1b5e1867ca7580058b575e34de9291c489b4e318966ec169bff22c1d070960f3d1cf55020e8930b2212d78300a331ce122ccc868c87e
|
data/Gemfile.lock
CHANGED
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'arql/vd'
|
2
|
+
|
3
|
+
module Arql::Commands
|
4
|
+
module VD
|
5
|
+
class << self
|
6
|
+
def get_table_name(name)
|
7
|
+
name = name.to_s
|
8
|
+
return name if name =~ /^[a-z]/
|
9
|
+
if Object.const_defined?(name)
|
10
|
+
klass = Object.const_get(name)
|
11
|
+
return klass.table_name if klass < ActiveRecord::Base
|
12
|
+
end
|
13
|
+
name
|
14
|
+
end
|
15
|
+
|
16
|
+
def table_info_vd(table_name)
|
17
|
+
Arql::VD.new do |vd|
|
18
|
+
table_info(table_name).each { |row| vd << row }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def table_info(table_name)
|
23
|
+
t = []
|
24
|
+
t << ['PK', 'Name', 'SQL Type', 'Ruby Type', 'Limit', 'Precision', 'Scale', 'Default', 'Nullable', 'Comment']
|
25
|
+
connection = ::ActiveRecord::Base.connection
|
26
|
+
connection.columns(table_name).each do |column|
|
27
|
+
pk = if [connection.primary_key(table_name)].flatten.include?(column.name)
|
28
|
+
'Y'
|
29
|
+
else
|
30
|
+
''
|
31
|
+
end
|
32
|
+
t << [pk, column.name, column.sql_type,
|
33
|
+
column.sql_type_metadata.type, column.sql_type_metadata.limit || '',
|
34
|
+
column.sql_type_metadata.precision || '', column.sql_type_metadata.scale || '', column.default || '',
|
35
|
+
column.null, column.comment || '']
|
36
|
+
end
|
37
|
+
t
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
Pry.commands.block_command 'vd' do |name|
|
42
|
+
table_name = VD::get_table_name(name)
|
43
|
+
VD::table_info_vd(table_name)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
data/lib/arql/commands.rb
CHANGED
data/lib/arql/definition.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'arql/concerns'
|
2
|
+
require 'arql/vd'
|
2
3
|
module Arql
|
3
4
|
module Extension
|
4
5
|
extend ActiveSupport::Concern
|
@@ -9,6 +10,15 @@ module Arql
|
|
9
10
|
}
|
10
11
|
end
|
11
12
|
|
13
|
+
def vd
|
14
|
+
VD.new do |vd|
|
15
|
+
vd << ['Attribute Name', 'Attribute Value', 'SQL Type', 'Comment']
|
16
|
+
self.class.connection.columns(self.class.table_name).each do |column|
|
17
|
+
vd << [column.name, read_attribute(column.name), column.sql_type, column.comment || '']
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
12
22
|
def v
|
13
23
|
t = []
|
14
24
|
t << ['Attribute Name', 'Attribute Value', 'SQL Type', 'Comment']
|
@@ -49,6 +59,12 @@ module Arql
|
|
49
59
|
puts Commands::Table::table_info_table(table_name)
|
50
60
|
end
|
51
61
|
|
62
|
+
def vd
|
63
|
+
table_name = Commands::Table::get_table_name(name)
|
64
|
+
Commands::VD::table_info_vd(table_name)
|
65
|
+
nil
|
66
|
+
end
|
67
|
+
|
52
68
|
def v
|
53
69
|
table_name = Commands::Table::get_table_name(name)
|
54
70
|
Commands::Table::table_info(table_name)
|
@@ -229,6 +245,10 @@ module Arql
|
|
229
245
|
records.t(*attrs, **options)
|
230
246
|
end
|
231
247
|
|
248
|
+
def vd(*attrs, **options)
|
249
|
+
records.vd(*attrs, **options)
|
250
|
+
end
|
251
|
+
|
232
252
|
def v
|
233
253
|
records.v
|
234
254
|
end
|
data/lib/arql/ext/array.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'arql/vd'
|
2
|
+
|
1
3
|
class Array
|
2
4
|
def to_insert_sql(batch_size=500)
|
3
5
|
raise 'All element should be an ActiveRecord instance object' unless all? { |e| e.is_a?(ActiveRecord::Base) }
|
@@ -48,6 +50,33 @@ class Array
|
|
48
50
|
end
|
49
51
|
end
|
50
52
|
|
53
|
+
def vd(*attrs, **options)
|
54
|
+
if (attrs.present? || options.present? && options[:except]) && present? && first.is_a?(ActiveRecord::Base)
|
55
|
+
column_names = first.attribute_names.map(&:to_sym)
|
56
|
+
attrs = attrs.flat_map { |e| e.is_a?(Regexp) ? column_names.grep(e) : e }.uniq
|
57
|
+
if options.present? && options[:except]
|
58
|
+
attrs = column_names if attrs.empty?
|
59
|
+
if options[:except].is_a?(Regexp)
|
60
|
+
attrs.reject! { |e| e =~ options[:except] }
|
61
|
+
else
|
62
|
+
attrs -= [options[:except]].flatten
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
Arql::VD.new do |vd|
|
67
|
+
vd << attrs
|
68
|
+
each do |e|
|
69
|
+
vd << e.attributes.values_at(*attrs.map(&:to_s))
|
70
|
+
end
|
71
|
+
end
|
72
|
+
else
|
73
|
+
Arql::VD.new do |vd|
|
74
|
+
v.each { |row| vd << row if row }
|
75
|
+
end
|
76
|
+
end
|
77
|
+
nil
|
78
|
+
end
|
79
|
+
|
51
80
|
def v
|
52
81
|
return self unless present?
|
53
82
|
t = []
|
data/lib/arql/vd.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'csv'
|
2
|
+
|
3
|
+
module Arql
|
4
|
+
class VD
|
5
|
+
COMMAND = 'vd'
|
6
|
+
|
7
|
+
attr_accessor :rows
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
return unless check_command_installation
|
11
|
+
@rows = []
|
12
|
+
yield self
|
13
|
+
command = "#{COMMAND} -f csv"
|
14
|
+
IO.popen(command, 'w+') do |io|
|
15
|
+
io.puts(csv)
|
16
|
+
io.close_write
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def <<(row)
|
21
|
+
rows << row
|
22
|
+
end
|
23
|
+
|
24
|
+
def csv
|
25
|
+
CSV.generate do |csv|
|
26
|
+
rows.each do |row|
|
27
|
+
csv << row
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def check_command_installation
|
33
|
+
`which #{COMMAND}`
|
34
|
+
if $?.exitstatus != 0
|
35
|
+
puts "Please install vd (visidata) command, see: https://www.visidata.org/"
|
36
|
+
else
|
37
|
+
true
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
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.3.
|
4
|
+
version: 0.3.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Liu Xiang
|
@@ -245,6 +245,7 @@ files:
|
|
245
245
|
- lib/arql/commands/sandbox.rb
|
246
246
|
- lib/arql/commands/show_sql.rb
|
247
247
|
- lib/arql/commands/table.rb
|
248
|
+
- lib/arql/commands/vd.rb
|
248
249
|
- lib/arql/concerns.rb
|
249
250
|
- lib/arql/concerns/global_data_definition.rb
|
250
251
|
- lib/arql/concerns/table_data_definition.rb
|
@@ -263,6 +264,7 @@ files:
|
|
263
264
|
- lib/arql/repl.rb
|
264
265
|
- lib/arql/ssh_proxy.rb
|
265
266
|
- lib/arql/ssh_proxy_patch.rb
|
267
|
+
- lib/arql/vd.rb
|
266
268
|
- lib/arql/version.rb
|
267
269
|
homepage: https://github.com/lululau/arql
|
268
270
|
licenses:
|