arpry 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -11
- data/lib/arpry/cli.rb +11 -2
- data/lib/arpry/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cc115cecaf26c426cc0eb12660c865579941de482cd5c04b1b757eb62038ca6e
|
4
|
+
data.tar.gz: e29210c78f1a7d2685f14d1ac14f2ac2029e7b3ea25f298d64fed038eb12ec41
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
14
|
+
```bash
|
15
|
+
$ gem install arpry
|
15
16
|
|
16
|
-
|
17
|
-
gem
|
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
|
-
|
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
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.
|
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:
|
11
|
+
date: 2019-01-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|