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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 17878b43fdb37376072a9ce87b9455cf42303a2a2eeacb0a382ee8b761e837cf
4
- data.tar.gz: 12054ff4ed638edef1b8fa8a37c014bd6933f499add79367032c7eb4b4087a9b
3
+ metadata.gz: 65a539e6b5575a1849475cf4a339d28f742b2c92b35ea4dfc98b26de2f2ea634
4
+ data.tar.gz: f3d0481117428f3e71123c27c22d268ea9f2d90723ff18881b93dbe50d73495b
5
5
  SHA512:
6
- metadata.gz: b66b11751c5d0dda49dd3e3b46643a954a9e2d33e7c94bab718703393cf35a1e8fb71b22d20c8a51e857eabf45ed481f5472cab18dc0a4959d20fdc418a4a4bf
7
- data.tar.gz: fb72779d24b99ed46b22e105f43f4abe9ad973a780e66c0d11f2325b89923004db5811dbc90a74c7d8b786ed7c575938675cdc865f8e8d95c4a41d5f654ab383
6
+ metadata.gz: fb59a7d19f2349f3c5994b4d48115711773e91008aa3cc9d6c0a30d20d225b3bceb3b72832ca1a281c815d6e1f698ce48675028a4533b405c39f539c616e5efd
7
+ data.tar.gz: c2659cec45e82dd7bb5a20efa3dd2635e965164a69f50c3bab8e9bd7b2f8747be51a5b150557b8821d50993694eecc2c1472ec2b778fc88a42f157f6138adc5b
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- arql (0.1.10)
4
+ arql (0.1.11)
5
5
  activerecord (~> 6.0.3)
6
6
  activesupport (~> 6.0.3)
7
7
  mysql2 (~> 0.5.3)
@@ -4,24 +4,37 @@ module Arql::Commands
4
4
  module Models
5
5
  class << self
6
6
  def models
7
- Terminal::Table.new do |t|
8
- t << ['Table Name', 'Model Class', 'Abbr']
9
- t << :separator
10
- Arql::Definition.models.each do |definition|
11
- t << [definition[:table], definition[:model].name, definition[:abbr] || '']
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
- Pry.commands.block_command 'models' do
19
- puts
20
- puts Models::models
21
- end
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
- Pry.commands.alias_command 'm', 'models'
24
- Pry.commands.alias_command 'l', 'models'
25
- Pry.commands.alias_command 'tables', 'models'
37
+ def tables
38
+ models
26
39
  end
27
40
  end
@@ -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 table_info(table_name)
16
+ def table_info_table(table_name)
16
17
  Terminal::Table.new do |t|
17
- t << ['PK', 'Name', 'SQL Type', 'Ruby Type', 'Limit', 'Precision', 'Scale', 'Default', 'Nullable', 'Comment']
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 'table' do |name|
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::table_info(table_name)
46
+ puts Table::table_info_table(table_name)
40
47
  end
48
+ end
49
+ end
41
50
 
42
- Pry.commands.alias_command 't', 'table'
51
+ module Kernel
52
+ def table(name)
53
+ Table::table_info(Table::get_table_name(name))
43
54
  end
44
55
  end
@@ -3,13 +3,19 @@ module Arql
3
3
  extend ActiveSupport::Concern
4
4
 
5
5
  def t
6
- Terminal::Table.new { |t|
7
- t << ['Attribute Name', 'Attribute Value', 'SQL Type', 'Comment']
8
- t << :separator
9
- self.class.connection.columns(self.class.table_name).each do |column|
10
- t << [column.name, read_attribute(column.name), column.sql_type, column.comment || '']
11
- end
12
- }.to_s
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}\n" + Commands::Table::table_info(table_name).to_s
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)
@@ -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
@@ -7,4 +7,12 @@ class Object
7
7
  def jj
8
8
  JSON.pretty_generate(JSON.parse(to_json))
9
9
  end
10
+
11
+ def jp
12
+ puts j
13
+ end
14
+
15
+ def jjp
16
+ puts jj
17
+ end
10
18
  end
data/lib/arql/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Arql
2
- VERSION = "0.1.10"
2
+ VERSION = "0.1.11"
3
3
  end
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.10
4
+ version: 0.1.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Liu Xiang