arql 0.1.10 → 0.1.11
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/models.rb +26 -13
- data/lib/arql/commands/table.rb +29 -18
- data/lib/arql/definition.rb +20 -8
- data/lib/arql/ext/array.rb +12 -0
- data/lib/arql/ext/object.rb +8 -0
- data/lib/arql/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 65a539e6b5575a1849475cf4a339d28f742b2c92b35ea4dfc98b26de2f2ea634
|
4
|
+
data.tar.gz: f3d0481117428f3e71123c27c22d268ea9f2d90723ff18881b93dbe50d73495b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fb59a7d19f2349f3c5994b4d48115711773e91008aa3cc9d6c0a30d20d225b3bceb3b72832ca1a281c815d6e1f698ce48675028a4533b405c39f539c616e5efd
|
7
|
+
data.tar.gz: c2659cec45e82dd7bb5a20efa3dd2635e965164a69f50c3bab8e9bd7b2f8747be51a5b150557b8821d50993694eecc2c1472ec2b778fc88a42f157f6138adc5b
|
data/Gemfile.lock
CHANGED
data/lib/arql/commands/models.rb
CHANGED
@@ -4,24 +4,37 @@ module Arql::Commands
|
|
4
4
|
module Models
|
5
5
|
class << self
|
6
6
|
def models
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
end
|
7
|
+
t = []
|
8
|
+
t << ['Table Name', 'Model Class', 'Abbr']
|
9
|
+
t << nil
|
10
|
+
Arql::Definition.models.each do |definition|
|
11
|
+
t << [definition[:table], definition[:model].name, definition[:abbr] || '']
|
13
12
|
end
|
13
|
+
t
|
14
14
|
end
|
15
15
|
|
16
|
+
def models_table
|
17
|
+
Terminal::Table.new do |t|
|
18
|
+
models.each { |row| t << (row || :separator) }
|
19
|
+
end
|
20
|
+
end
|
16
21
|
end
|
22
|
+
end
|
17
23
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
24
|
+
Pry.commands.block_command 'm' do
|
25
|
+
puts
|
26
|
+
puts Models::models_table
|
27
|
+
end
|
28
|
+
|
29
|
+
Pry.commands.alias_command 'l', 'm'
|
30
|
+
end
|
31
|
+
|
32
|
+
module Kernel
|
33
|
+
def models
|
34
|
+
Arql::Commands::Models::models
|
35
|
+
end
|
22
36
|
|
23
|
-
|
24
|
-
|
25
|
-
Pry.commands.alias_command 'tables', 'models'
|
37
|
+
def tables
|
38
|
+
models
|
26
39
|
end
|
27
40
|
end
|
data/lib/arql/commands/table.rb
CHANGED
@@ -4,6 +4,7 @@ module Arql::Commands
|
|
4
4
|
module Table
|
5
5
|
class << self
|
6
6
|
def get_table_name(name)
|
7
|
+
name = name.to_s
|
7
8
|
return name if name =~ /^[a-z]/
|
8
9
|
if Object.const_defined?(name)
|
9
10
|
klass = Object.const_get(name)
|
@@ -12,33 +13,43 @@ module Arql::Commands
|
|
12
13
|
name
|
13
14
|
end
|
14
15
|
|
15
|
-
def
|
16
|
+
def table_info_table(table_name)
|
16
17
|
Terminal::Table.new do |t|
|
17
|
-
|
18
|
-
t << :separator
|
19
|
-
connection = ::ActiveRecord::Base.connection
|
20
|
-
connection.columns(table_name).each do |column|
|
21
|
-
pk = if column.name == connection.primary_key(table_name)
|
22
|
-
'Y'
|
23
|
-
else
|
24
|
-
''
|
25
|
-
end
|
26
|
-
t << [pk, column.name, column.sql_type,
|
27
|
-
column.sql_type_metadata.type, column.sql_type_metadata.limit || '',
|
28
|
-
column.sql_type_metadata.precision || '', column.sql_type_metadata.scale || '', column.default || '',
|
29
|
-
column.null, column.comment || '']
|
30
|
-
end
|
18
|
+
table_info(table_name).each { |row| t << (row || :separator) }
|
31
19
|
end
|
32
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
|
+
t << nil
|
26
|
+
connection = ::ActiveRecord::Base.connection
|
27
|
+
connection.columns(table_name).each do |column|
|
28
|
+
pk = if column.name == connection.primary_key(table_name)
|
29
|
+
'Y'
|
30
|
+
else
|
31
|
+
''
|
32
|
+
end
|
33
|
+
t << [pk, column.name, column.sql_type,
|
34
|
+
column.sql_type_metadata.type, column.sql_type_metadata.limit || '',
|
35
|
+
column.sql_type_metadata.precision || '', column.sql_type_metadata.scale || '', column.default || '',
|
36
|
+
column.null, column.comment || '']
|
37
|
+
end
|
38
|
+
t
|
39
|
+
end
|
33
40
|
end
|
34
41
|
|
35
|
-
Pry.commands.block_command '
|
42
|
+
Pry.commands.block_command 't' do |name|
|
36
43
|
table_name = Table::get_table_name(name)
|
37
44
|
puts
|
38
45
|
puts "Table: #{table_name}"
|
39
|
-
puts Table::
|
46
|
+
puts Table::table_info_table(table_name)
|
40
47
|
end
|
48
|
+
end
|
49
|
+
end
|
41
50
|
|
42
|
-
|
51
|
+
module Kernel
|
52
|
+
def table(name)
|
53
|
+
Table::table_info(Table::get_table_name(name))
|
43
54
|
end
|
44
55
|
end
|
data/lib/arql/definition.rb
CHANGED
@@ -3,13 +3,19 @@ module Arql
|
|
3
3
|
extend ActiveSupport::Concern
|
4
4
|
|
5
5
|
def t
|
6
|
-
Terminal::Table.new { |t|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
6
|
+
puts Terminal::Table.new { |t|
|
7
|
+
v.each { |row| t << (row || :separator) }
|
8
|
+
}
|
9
|
+
end
|
10
|
+
|
11
|
+
def v
|
12
|
+
t = []
|
13
|
+
t << ['Attribute Name', 'Attribute Value', 'SQL Type', 'Comment']
|
14
|
+
t << nil
|
15
|
+
self.class.connection.columns(self.class.table_name).each do |column|
|
16
|
+
t << [column.name, read_attribute(column.name), column.sql_type, column.comment || '']
|
17
|
+
end
|
18
|
+
t
|
13
19
|
end
|
14
20
|
|
15
21
|
def to_insert_sql
|
@@ -23,7 +29,13 @@ module Arql
|
|
23
29
|
class_methods do
|
24
30
|
def t
|
25
31
|
table_name = Commands::Table::get_table_name(name)
|
26
|
-
"\nTable: #{table_name}
|
32
|
+
puts "\nTable: #{table_name}"
|
33
|
+
puts Commands::Table::table_info_table(table_name)
|
34
|
+
end
|
35
|
+
|
36
|
+
def v
|
37
|
+
table_name = Commands::Table::get_table_name(name)
|
38
|
+
Commands::Table::table_info(table_name)
|
27
39
|
end
|
28
40
|
def to_insert_sql(records, batch_size=1)
|
29
41
|
to_sql(records, :skip, batch_size)
|
data/lib/arql/ext/array.rb
CHANGED
@@ -12,4 +12,16 @@ class Array
|
|
12
12
|
klass.to_upsert_sql(records, batch_size)
|
13
13
|
end.join("\n")
|
14
14
|
end
|
15
|
+
|
16
|
+
def v
|
17
|
+
raise 'Empty array' unless present?
|
18
|
+
raise 'All elements must be instances of the same ActiveRecord model class' unless map(&:class).uniq.size == 1 && first.is_a?(ActiveRecord::Base)
|
19
|
+
t = []
|
20
|
+
t << first.attribute_names
|
21
|
+
t << nil
|
22
|
+
each do |e|
|
23
|
+
t << e.attributes.values_at(*first.attribute_names)
|
24
|
+
end
|
25
|
+
t
|
26
|
+
end
|
15
27
|
end
|
data/lib/arql/ext/object.rb
CHANGED
data/lib/arql/version.rb
CHANGED