arpry 0.2.0 → 0.3.0

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: 2db01731aef25421eaef49a72b1a89d4e36476bcb44841cb957ad6cb9082d2a4
4
- data.tar.gz: 4c070847760cb4a1b638b5dbcbf7304cb3e195d2cbbf873fd0b115a659407761
3
+ metadata.gz: cc115cecaf26c426cc0eb12660c865579941de482cd5c04b1b757eb62038ca6e
4
+ data.tar.gz: e29210c78f1a7d2685f14d1ac14f2ac2029e7b3ea25f298d64fed038eb12ec41
5
5
  SHA512:
6
- metadata.gz: bcd25b8f5f2d61776052019695d0d17a0602806bca913e1f273980d8ded2ab69f859a4129f8018d2d4b39a746593e3ac7813c99d9461983cc2cbc8df8c993671
7
- data.tar.gz: 322477d5332c84d396dcae64c980c72052d5c8efb5108019106a1741b1f54eebf0d534f64c94888aa4b6b1ea58285ce66f010c79f0057e06af19c28c65e6dbad
6
+ metadata.gz: 19b2a6032392028d8efa6bf37265b6fbc4fed08bdaa65a0b4486d4d7f877f15e016c79e3079aa4520e3865c385214d8ad16293be8080f891cfa13f333d18c388
7
+ data.tar.gz: 12794da7d0774a2c48fda0df77fd03bd5de3dc9bd68ac86a24ec97dc18948941e1496e2a1894a922e0131cff6e89b713ffb8a0af5e13293ce0700a4d4387c742
data/README.md CHANGED
@@ -11,20 +11,13 @@ You can get the same experience as Rails Console to explore database with not-Ra
11
11
 
12
12
  ## Installation
13
13
 
14
- Add this line to your application's Gemfile:
14
+ ```bash
15
+ $ gem install arpry
15
16
 
16
- ```ruby
17
- gem 'arpry'
17
+ # Install adapter gem(s) you need
18
+ $ gem install sqlite3 # Or pg, mysql2, ...
18
19
  ```
19
20
 
20
- And then execute:
21
-
22
- $ bundle
23
-
24
- Or install it yourself as:
25
-
26
- $ gem install arpry
27
-
28
21
  ## Usage
29
22
 
30
23
  Explore database with `arpry` command.
@@ -35,6 +28,8 @@ $ arpry /path/to/databasefile.sqlite3
35
28
 
36
29
  # For postgresql
37
30
  $ arpry --adapter postgresql --host localhost --user YOUR_USER_NAME --password YOUR_PASSWORD --database YOUR_DB_NAME
31
+
32
+ # Probably it works with other RDBMS such as MySQL.
38
33
  ```
39
34
 
40
35
  See `arpry --help` for more information of command line options.
data/lib/arpry/cli.rb CHANGED
@@ -11,7 +11,8 @@ module Arpry
11
11
 
12
12
  ApplicationRecord.establish_connection(@params)
13
13
 
14
- generate_classes
14
+ classes = generate_classes
15
+ define_foreign_keys(classes)
15
16
 
16
17
  binding.pry(Namespace)
17
18
 
@@ -37,12 +38,14 @@ module Arpry
37
38
  end
38
39
 
39
40
  def generate_classes
40
- classes = ApplicationRecord.connection.tables.map do |table|
41
+ ApplicationRecord.connection.tables.map do |table|
41
42
  Namespace.const_set(table.classify, Class.new(ApplicationRecord) do
42
43
  self.table_name = table
43
44
  end)
44
45
  end
46
+ end
45
47
 
48
+ def define_foreign_keys(classes)
46
49
  relations = Array.new(classes.size) do
47
50
  Array.new(classes.size)
48
51
  end
@@ -56,6 +59,12 @@ module Arpry
56
59
 
57
60
  relations[idx][ref_klass_idx] = col.name
58
61
  end
62
+
63
+ klass.connection.foreign_keys(klass.table_name).each do |fk|
64
+ ref_klass_idx = classes.find_index {|c| c.table_name == fk.to_table }
65
+ next unless ref_klass_idx
66
+ relations[idx][ref_klass_idx] = fk.options[:column]
67
+ end
59
68
  end
60
69
 
61
70
  relations.each.with_index do |row, idx|
data/lib/arpry/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Arpry
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: arpry
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Masataka Pocke Kuwabara
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-12-31 00:00:00.000000000 Z
11
+ date: 2019-01-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord