erde 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/.gitignore +1 -0
- data/CHANGELOG.md +4 -0
- data/README.md +4 -0
- data/erde.gemspec +2 -0
- data/lib/erde/cli.rb +42 -2
- data/lib/erde/template.dot.erb +24 -0
- data/lib/erde/version.rb +1 -1
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7c80277ab7aff1fa8b988fc0414cc96f4c2619f8
|
4
|
+
data.tar.gz: d19998855f85ade4eadb28ee1c04e3317d282e7a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 37a82e7f74a09ed9d9c13f7bce3c72bf5b7effc4a338898c70e885c55ccd0f358c435bc12fb68064d2574d8316ee3de19503720a4f177f674aacb1b7bad2c7f5
|
7
|
+
data.tar.gz: 419c5ad4e0e179a14ef52a791c650d733c34c5a0e27ce83a5838fe75e164cec4f79b0f5b1a560e3bbabbf289a1175c2b7707f7bca3f940394b9d3fc365e87f53
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -9,6 +9,10 @@ Make sure you have [Graphviz](http://graphviz.org/) installed and available in y
|
|
9
9
|
bin/erde file docs/schema.txt docs/schema.png
|
10
10
|
~~~
|
11
11
|
|
12
|
+
~~~txt
|
13
|
+
bin/erde database postgres://user:password@localhost/your_database docs/schema.png
|
14
|
+
~~~
|
15
|
+
|
12
16
|
## Text Schema Format
|
13
17
|
~~~txt
|
14
18
|
[identities]
|
data/erde.gemspec
CHANGED
data/lib/erde/cli.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
require "erde"
|
2
2
|
require "pathname"
|
3
3
|
require "open3"
|
4
|
+
require "sequel"
|
5
|
+
require "erb"
|
4
6
|
|
5
7
|
class Erde::CLI
|
6
8
|
def self.start(*args)
|
@@ -13,6 +15,12 @@ class Erde::CLI
|
|
13
15
|
hash_schema = text_transformer.to_hash
|
14
16
|
end
|
15
17
|
|
18
|
+
if command == "database"
|
19
|
+
url = args.shift.strip
|
20
|
+
database_transformer = Erde::DatabaseTransformer.new(url)
|
21
|
+
hash_schema = database_transformer.to_hash
|
22
|
+
end
|
23
|
+
|
16
24
|
hash_transformer = Erde::HashTransformer.new(hash_schema)
|
17
25
|
dot_schema = hash_transformer.to_dot
|
18
26
|
|
@@ -28,12 +36,15 @@ class Erde::HashTransformer
|
|
28
36
|
end
|
29
37
|
|
30
38
|
def to_dot
|
39
|
+
template = File.read(File.expand_path("../template.dot.erb", __FILE__))
|
40
|
+
|
31
41
|
schema_string = ""
|
32
42
|
schema_string << "digraph tables {"
|
33
|
-
schema_string << "node [shape=
|
43
|
+
schema_string << "node [shape=plaintext rankdir=LR];"
|
34
44
|
|
35
45
|
@hash.each_pair do |table_name, table_schema|
|
36
|
-
|
46
|
+
renderer = ERB.new(template)
|
47
|
+
schema_string << renderer.result(binding)
|
37
48
|
|
38
49
|
table_schema['relations'].each_pair do |column, target|
|
39
50
|
schema_string << "#{table_name}:#{column} -> #{target['table']}:#{target['column']};"
|
@@ -46,6 +57,35 @@ class Erde::HashTransformer
|
|
46
57
|
end
|
47
58
|
end
|
48
59
|
|
60
|
+
class Erde::DatabaseTransformer
|
61
|
+
def initialize(url)
|
62
|
+
@url = url
|
63
|
+
end
|
64
|
+
|
65
|
+
def to_hash
|
66
|
+
generated_hash = {}
|
67
|
+
|
68
|
+
Sequel.connect(@url) do |db|
|
69
|
+
db.tables.each do |table|
|
70
|
+
generated_hash[table] = {}
|
71
|
+
generated_hash[table]['columns'] = []
|
72
|
+
generated_hash[table]['relations'] = {}
|
73
|
+
|
74
|
+
generated_hash[table]['columns'] = db.schema(table).map(&:first)
|
75
|
+
|
76
|
+
db.foreign_key_list(table).each do |foreign_key|
|
77
|
+
generated_hash[table]['relations'][foreign_key[:columns].first] = {
|
78
|
+
'table' => foreign_key[:table],
|
79
|
+
'column' => foreign_key[:key].first
|
80
|
+
}
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
generated_hash
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
49
89
|
class Erde::TextTransformer
|
50
90
|
def initialize(text)
|
51
91
|
@lines = text.lines
|
@@ -0,0 +1,24 @@
|
|
1
|
+
<%= table_name %> [label=<
|
2
|
+
|
3
|
+
<TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0" CELLPADDING="2" STYLE="ROUNDED" ROWS="*">
|
4
|
+
<TR>
|
5
|
+
<TD BORDER="1" SIDES="B">
|
6
|
+
<FONT FACE="Helvetica Neue Bold" POINT-SIZE="14"><%= table_name %></FONT>
|
7
|
+
</TD>
|
8
|
+
</TR>
|
9
|
+
<TR>
|
10
|
+
<TD>
|
11
|
+
<TABLE BORDER="0" CELLBORDER="0" CELLSPACING="2" CELLPADDING="0">
|
12
|
+
<% for @column in table_schema['columns'] %>
|
13
|
+
<TR>
|
14
|
+
<TD ALIGN="LEFT" PORT="<%= @column %>">
|
15
|
+
<FONT FACE="Helvetica Neue" POINT-SIZE="12"><%= @column %></FONT>
|
16
|
+
</TD>
|
17
|
+
</TR>
|
18
|
+
<% end %>
|
19
|
+
</TABLE>
|
20
|
+
</TD>
|
21
|
+
</TR>
|
22
|
+
</TABLE>
|
23
|
+
|
24
|
+
>];
|
data/lib/erde/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: erde
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Strauß
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-06-
|
11
|
+
date: 2016-06-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '5.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: sequel
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '4.0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '4.0'
|
55
69
|
description: Generate good looking Entity-Relationship-Diagrams from text files or
|
56
70
|
a PostgreSQL database.
|
57
71
|
email:
|
@@ -74,6 +88,7 @@ files:
|
|
74
88
|
- erde.gemspec
|
75
89
|
- lib/erde.rb
|
76
90
|
- lib/erde/cli.rb
|
91
|
+
- lib/erde/template.dot.erb
|
77
92
|
- lib/erde/version.rb
|
78
93
|
homepage: https://github.com/edgycircle/erde
|
79
94
|
licenses:
|