arql 0.1.31 → 0.1.32

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 720e28d1a714ac8e3d116c6f63ef734476895b28502df43a486a9f7f4348430f
4
- data.tar.gz: 654c7011a05dc8631c418504953def7870d33d2fa22922fb3292992e8dbe6ff4
3
+ metadata.gz: 48ce3b7b50ccdb8ab338b73e1895b73cd7ebec18ef779c18931603353e709d12
4
+ data.tar.gz: 3a9bf2b11cdf4be30ab58590aedb81ea2944f6341ca26fd2ab584c9a490cb512
5
5
  SHA512:
6
- metadata.gz: a5f9271ae382fa37b7ec06907d17a17b47129390f4f0f144aff1b0cf4bbb8ee9bad7fda54cf5afb8d4029d3b02f92725de51968a345367c06c2298eef54c91a6
7
- data.tar.gz: 72cbb2b5895da48dcb93b252d43882b6f6005cbe1638d284135e61404fee9a0e96f0ce0db3d585a3b23b2fa256381b37ee05f5abec4072e8af4c452f61608747
6
+ metadata.gz: 1cb190b2e90d18b08ccc98878b5db934ebb1e008fc4aba6a850fd4e384e917d02f14837700a06aca8bc5bdc7799a8ea6ffd5c737bb38260304f60166db3a63ce
7
+ data.tar.gz: 3b9c6e813b91904cf39bd044c1ac86925802f52d6f0a4e7a7d3f10f2309db812e01cecb0476555bbcb751df73f640c941fe3e307a96c05f9101d854659e53a70
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- arql (0.1.31)
4
+ arql (0.1.32)
5
5
  activerecord (~> 6.0.3)
6
6
  activesupport (~> 6.0.3)
7
7
  mysql2 (~> 0.5.3)
@@ -29,14 +29,14 @@ GEM
29
29
  tzinfo (~> 1.1)
30
30
  zeitwerk (~> 2.2, >= 2.2.2)
31
31
  byebug (11.1.3)
32
- coderay (1.1.2)
33
- concurrent-ruby (1.1.6)
34
- i18n (1.8.2)
32
+ coderay (1.1.3)
33
+ concurrent-ruby (1.1.7)
34
+ i18n (1.8.5)
35
35
  concurrent-ruby (~> 1.0)
36
36
  method_source (1.0.0)
37
37
  minitest (5.14.1)
38
38
  mysql2 (0.5.3)
39
- net-ssh (6.0.2)
39
+ net-ssh (6.1.0)
40
40
  net-ssh-gateway (2.0.0)
41
41
  net-ssh (>= 4.0.0)
42
42
  pry (0.13.1)
@@ -59,7 +59,7 @@ GEM
59
59
  thread_safe (~> 0.1)
60
60
  unicode-display_width (1.7.0)
61
61
  yard (0.9.25)
62
- zeitwerk (2.3.0)
62
+ zeitwerk (2.4.0)
63
63
 
64
64
  PLATFORMS
65
65
  ruby
@@ -37,7 +37,7 @@ module Arql
37
37
  end
38
38
 
39
39
  opts.on('-aDB_ADAPTER', '--db-adapter=DB_ADAPTER', 'Specify database Adapter, default is mysql2') do |db_adapter|
40
- @options.dapter = db_adapter
40
+ @options.adapter = db_adapter
41
41
  end
42
42
 
43
43
  opts.on('-hDB_HOST', '--db-host=DB_HOST', 'Specify database host') do |db_host|
@@ -2,4 +2,64 @@ module Kernel
2
2
  def sql(sql)
3
3
  ActiveRecord::Base.connection.exec_query(sql)
4
4
  end
5
+
6
+ def print_tables(format = :md)
7
+ require 'terminal-table'
8
+
9
+ tables = ActiveRecord::Base.connection.tables.map do |table_name|
10
+ {
11
+ table: table_name,
12
+ table_comment: ActiveRecord::Base.connection.table_comment(table_name) || '',
13
+ columns: ::ActiveRecord::Base.connection.columns(table_name)
14
+ }
15
+ end
16
+
17
+ outputs = tables.map do |table|
18
+ table_name = table[:table]
19
+ table_comment = table[:table_comment]
20
+ case format
21
+ when :md
22
+ "# #{table_name} #{table_comment}\n\n" +
23
+ Terminal::Table.new { |t|
24
+ t.headings = ['PK', 'Name', 'SQL Type', 'Limit', 'Precision', 'Scale', 'Default', 'Nullable', 'Comment']
25
+ t.rows = table[:columns].map { |column|
26
+ pk = if column.name == ::ActiveRecord::Base.connection.primary_key(table_name)
27
+ 'Y'
28
+ else
29
+ ''
30
+ end
31
+ [pk, "`#{column.name}`", column.sql_type, column.sql_type_metadata.limit || '', column.sql_type_metadata.precision || '',
32
+ column.sql_type_metadata.scale || '', column.default || '', column.null, column.comment || '']
33
+ }
34
+ t.style = {
35
+ border_top: false,
36
+ border_bottom: false,
37
+ border_i: '|'
38
+ }
39
+ }.to_s.lines.map { |l| ' ' + l }.join
40
+ when :org
41
+ "* #{table_name} #{table_comment}\n\n" +
42
+ Terminal::Table.new { |t|
43
+ t.headings = ['PK', 'Name', 'SQL Type', 'Limit', 'Precision', 'Scale', 'Default', 'Nullable', 'Comment']
44
+ t.rows = table[:columns].map { |column|
45
+ pk = if column.name == ::ActiveRecord::Base.connection.primary_key(table_name)
46
+ 'Y'
47
+ else
48
+ ''
49
+ end
50
+ [pk, "=#{column.name}=", column.sql_type, column.sql_type_metadata.limit || '', column.sql_type_metadata.precision || '',
51
+ column.sql_type_metadata.scale || '', column.default || '', column.null, column.comment || '']
52
+ }
53
+ t.style = {
54
+ border_top: false,
55
+ border_bottom: false,
56
+ }
57
+ }.to_s.lines.map { |l| ' ' + l.gsub(/^\+|\+$/, '|') }.join
58
+ when :sql
59
+ "-- Table: #{table_name}\n\n" + ActiveRecord::Base.connection.exec_query("show create table `#{table_name}`").rows.last.last + ';'
60
+ end
61
+ end
62
+
63
+ outputs.each { |out| puts out; puts }
64
+ end
5
65
  end
@@ -1,3 +1,3 @@
1
1
  module Arql
2
- VERSION = "0.1.31"
2
+ VERSION = "0.1.32"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: arql
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.31
4
+ version: 0.1.32
5
5
  platform: ruby
6
6
  authors:
7
7
  - Liu Xiang
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-07-21 00:00:00.000000000 Z
11
+ date: 2020-08-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mysql2