Skip to content

Commit

Permalink
Merge pull request #35 from k1LoW/support-cr
Browse files Browse the repository at this point in the history
Support CR `\r` and CRLF `\r\n`
  • Loading branch information
k1LoW authored Jul 13, 2018
2 parents 72db263 + 1911fab commit 4e7988f
Show file tree
Hide file tree
Showing 13 changed files with 38 additions and 30 deletions.
2 changes: 1 addition & 1 deletion output/dot/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"github.com/jessevdk/go-assets"
)

var _Assets21532ae17ad95976ac467eeaeab81f2bb1d537e4 = "digraph \"{{ .Schema.Name }}\" {\n // Config\n graph [rankdir=TB, layout=dot, fontname=\"Arial\"];\n node [shape=record, fontsize=14, margin=0.6, fontname=\"Arial\"];\n edge [fontsize=10, labelfloat=false, splines=none, fontname=\"Arial\"];\n\n // Tables\n {{- range $i, $t := .Schema.Tables }}\n \"{{ $t.Name }}\" [shape=none, label=<<table border=\"0\" cellborder=\"1\" cellspacing=\"0\" cellpadding=\"6\">\n <tr><td bgcolor=\"#EFEFEF\"><font face=\"Arial Bold\" point-size=\"18\">{{ $t.Name | html }}</font> <font color=\"#666666\">[{{ $t.Type | html }}]</font></td></tr>\n {{- range $ii, $c := $t.Columns }}\n <tr><td port=\"{{ $c.Name | html }}\" align=\"left\">{{ $c.Name | html }} <font color=\"#666666\">[{{ $c.Type | html }}]</font></td></tr>\n {{- end }}\n </table>>];\n {{- end }}\n\n // Relations\n {{- range $j, $r := .Schema.Relations }}\n \"{{ $r.Table.Name }}\":{{ $c := index $r.Columns 0 }}{{ $c.Name }} -> \"{{ $r.ParentTable.Name }}\":{{ $pc := index $r.ParentColumns 0 }}{{ $pc.Name }} [dir=back, arrowtail=crow, {{ if $r.IsAdditional }}style=\"dashed\",{{ end }} taillabel=<<table cellpadding=\"5\" border=\"0\" cellborder=\"0\"><tr><td>{{ $r.Def | html }}</td></tr></table>>];\n {{- end }}\n}\n"
var _Assets5bd148e6149bb9adcdddfcf8cc46d6e3047dbe26 = "digraph \"{{ .Table.Name }}\" {\n // Config\n graph [rankdir=TB, layout=dot, fontname=\"Arial\"];\n node [shape=record, fontsize=14, margin=0.6, fontname=\"Arial\"];\n edge [fontsize=10, labelfloat=false, splines=none, fontname=\"Arial\"];\n\n // Tables\n \"{{ .Table.Name }}\" [shape=none, label=<<table border=\"3\" cellborder=\"1\" cellspacing=\"0\" cellpadding=\"6\">\n <tr><td bgcolor=\"#EFEFEF\"><font face=\"Arial Bold\" point-size=\"18\">{{ .Table.Name | html }}</font> <font color=\"#666666\">[{{ .Table.Type | html }}]</font></td></tr>\n {{- range $ii, $c := .Table.Columns }}\n <tr><td port=\"{{ $c.Name | html }}\" align=\"left\">{{ $c.Name | html }} <font color=\"#666666\">[{{ $c.Type }}]</font></td></tr>\n {{- end }}\n </table>>];\n {{- range $i, $t := .Tables }}\n \"{{ $t.Name }}\" [shape=none, label=<<table border=\"0\" cellborder=\"1\" cellspacing=\"0\" cellpadding=\"6\">\n <tr><td bgcolor=\"#EFEFEF\"><font face=\"Arial Bold\" point-size=\"18\">{{ $t.Name | html }}</font> <font color=\"#666666\">[{{ $t.Type | html }}]</font></td></tr>\n {{- range $ii, $c := $t.Columns }}\n <tr><td port=\"{{ $c.Name | html }}\" align=\"left\">{{ $c.Name | html }} <font color=\"#666666\">[{{ $c.Type | html }}]</font></td></tr>\n {{- end }}\n </table>>];\n {{- end }}\n\n // Relations\n {{- range $i, $r := .Relations }}\n \"{{ $r.Table.Name }}\":{{ $c := index $r.Columns 0 }}{{ $c.Name }} -> \"{{ $r.ParentTable.Name }}\":{{ $pc := index $r.ParentColumns 0 }}{{ $pc.Name }} [dir=back, arrowtail=crow, {{ if $r.IsAdditional }}style =\"dashed\",{{ end }} taillabel=<<table cellpadding=\"5\" border=\"0\" cellborder=\"0\"><tr><td>{{ $r.Def | html }}</td></tr></table>>];\n {{- end }}\n}\n"
var _Assets21532ae17ad95976ac467eeaeab81f2bb1d537e4 = "digraph \"{{ .Schema.Name }}\" {\n // Config\n graph [rankdir=TB, layout=dot, fontname=\"Arial\"];\n node [shape=record, fontsize=14, margin=0.6, fontname=\"Arial\"];\n edge [fontsize=10, labelfloat=false, splines=none, fontname=\"Arial\"];\n\n // Tables\n {{- range $i, $t := .Schema.Tables }}\n \"{{ $t.Name }}\" [shape=none, label=<<table border=\"0\" cellborder=\"1\" cellspacing=\"0\" cellpadding=\"6\">\n <tr><td bgcolor=\"#EFEFEF\"><font face=\"Arial Bold\" point-size=\"18\">{{ $t.Name | html }}</font> <font color=\"#666666\">[{{ $t.Type | html }}]</font></td></tr>\n {{- range $ii, $c := $t.Columns }}\n <tr><td port=\"{{ $c.Name | html }}\" align=\"left\">{{ $c.Name | html }} <font color=\"#666666\">[{{ $c.Type | html }}]</font></td></tr>\n {{- end }}\n </table>>];\n {{- end }}\n\n // Relations\n {{- range $j, $r := .Schema.Relations }}\n \"{{ $r.Table.Name }}\":{{ $c := index $r.Columns 0 }}{{ $c.Name }} -> \"{{ $r.ParentTable.Name }}\":{{ $pc := index $r.ParentColumns 0 }}{{ $pc.Name }} [dir=back, arrowtail=crow, {{ if $r.IsAdditional }}style=\"dashed\",{{ end }} taillabel=<<table cellpadding=\"5\" border=\"0\" cellborder=\"0\"><tr><td>{{ $r.Def | html }}</td></tr></table>>];\n {{- end }}\n}\n"

// Assets returns go-assets FileSystem
var Assets = assets.NewFileSystem(map[string][]string{"/": []string{"schema.dot.tmpl", "table.dot.tmpl"}}, map[string]*assets.File{
Expand Down
6 changes: 4 additions & 2 deletions output/md/md.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,12 @@ func outputExists(s *schema.Schema, path string) bool {
func funcMap() map[string]interface{} {
return template.FuncMap{
"nl2br": func(text string) string {
return strings.Replace(text, "\n", "<br>", -1)
r := strings.NewReplacer("\r\n", "<br>", "\n", "<br>", "\r", "<br>")
return r.Replace(text)
},
"nl2mdnl": func(text string) string {
return strings.Replace(text, "\n", " \n", -1)
r := strings.NewReplacer("\r\n", " \n", "\n", " \n", "\r", " \n")
return r.Replace(text)
},
}
}
16 changes: 8 additions & 8 deletions output/md/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@ var _Assetsac44302fb6150a621aa9d04a0350aac972bf7e18 = "# {{ .Table.Name }}\n\n##

// Assets returns go-assets FileSystem
var Assets = assets.NewFileSystem(map[string][]string{"/": []string{"index.md.tmpl", "table.md.tmpl"}}, map[string]*assets.File{
"/": &assets.File{
Path: "/",
FileMode: 0x800001ed,
Mtime: time.Unix(1531144283, 1531144283000000000),
Data: nil,
}, "/index.md.tmpl": &assets.File{
"/index.md.tmpl": &assets.File{
Path: "/index.md.tmpl",
FileMode: 0x1a4,
Mtime: time.Unix(1531143680, 1531143680000000000),
Mtime: time.Unix(1531144926, 1531144926000000000),
Data: []byte(_Assets43889384df1c6f74d764c29d91b9d5637eb46061),
}, "/table.md.tmpl": &assets.File{
Path: "/table.md.tmpl",
FileMode: 0x1a4,
Mtime: time.Unix(1531144283, 1531144283000000000),
Mtime: time.Unix(1531144926, 1531144926000000000),
Data: []byte(_Assetsac44302fb6150a621aa9d04a0350aac972bf7e18),
}, "/": &assets.File{
Path: "/",
FileMode: 0x800001ed,
Mtime: time.Unix(1531144926, 1531144926000000000),
Data: nil,
}}, "")
2 changes: 1 addition & 1 deletion sample/mysql/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
| ---- | ------- | ------- | ---- |
| [CamelizeTable](CamelizeTable.md) | 2 | | BASE TABLE |
| [comment_stars](comment_stars.md) | 6 | | BASE TABLE |
| [comments](comments.md) | 6 | Comments<br>Multi-line table comment | BASE TABLE |
| [comments](comments.md) | 6 | Comments<br>Multi-line<br>table<br>comment | BASE TABLE |
| [logs](logs.md) | 7 | audit log table | BASE TABLE |
| [post_comments](post_comments.md) | 7 | post and comments View table | VIEW |
| [posts](posts.md) | 7 | Posts table | BASE TABLE |
Expand Down
10 changes: 6 additions & 4 deletions sample/mysql/comments.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
## Description

Comments
Multi-line table comment
Multi-line
table
comment
<details>
<summary><strong>Table Definition</strong></summary>

Expand All @@ -12,7 +14,7 @@ CREATE TABLE `comments` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`post_id` bigint(20) NOT NULL,
`user_id` int(11) NOT NULL,
`comment` text NOT NULL COMMENT 'Comment\nMulti-line column comment',
`comment` text NOT NULL COMMENT 'Comment\nMulti-line\r\ncolumn\rcomment',
`created` datetime NOT NULL,
`updated` datetime DEFAULT NULL,
PRIMARY KEY (`id`),
Expand All @@ -21,7 +23,7 @@ CREATE TABLE `comments` (
KEY `comments_post_id_user_id_idx` (`post_id`,`user_id`) USING HASH,
CONSTRAINT `comments_post_id_fk` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`),
CONSTRAINT `comments_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COMMENT='Comments\nMulti-line table comment'
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COMMENT='Comments\nMulti-line\r\ntable\rcomment'
```

</details>
Expand All @@ -34,7 +36,7 @@ CREATE TABLE `comments` (
| id | bigint(20) | | false | [logs](logs.md) | | |
| post_id | bigint(20) | | false | [comment_stars](comment_stars.md) | [posts](posts.md) | |
| user_id | int(11) | | false | [comment_stars](comment_stars.md) | [users](users.md) | |
| comment | text | | false | | | Comment<br>Multi-line column comment |
| comment | text | | false | | | Comment<br>Multi-line<br>column<br>comment |
| created | datetime | | false | | | |
| updated | datetime | | true | | | |

Expand Down
2 changes: 1 addition & 1 deletion sample/mysql/post_comments.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ CREATE VIEW post_comments AS ((select `c`.`id` AS `id`,`p`.`title` AS `title`,`u
| id | bigint(20) | 0 | true | | | comments.id |
| title | varchar(255) | | false | | | posts.title |
| post_user | varchar(50) | | true | | | posts.users.username |
| comment | text | | true | | | Comment<br>Multi-line column comment |
| comment | text | | true | | | Comment<br>Multi-line<br>column<br>comment |
| comment_user | varchar(50) | | true | | | comments.users.username |
| created | datetime | | true | | | comments.created |
| updated | datetime | | true | | | comments.updated |
Expand Down
2 changes: 1 addition & 1 deletion sample/mysql8/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
| ---- | ------- | ------- | ---- |
| [CamelizeTable](CamelizeTable.md) | 2 | | BASE TABLE |
| [comment_stars](comment_stars.md) | 6 | | BASE TABLE |
| [comments](comments.md) | 6 | Comments<br>Multi-line table comment | BASE TABLE |
| [comments](comments.md) | 6 | Comments<br>Multi-line<br>table<br>comment | BASE TABLE |
| [logs](logs.md) | 7 | audit log table | BASE TABLE |
| [post_comments](post_comments.md) | 7 | post and comments View table | VIEW |
| [posts](posts.md) | 7 | Posts table | BASE TABLE |
Expand Down
10 changes: 6 additions & 4 deletions sample/mysql8/comments.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
## Description

Comments
Multi-line table comment
Multi-line
table
comment
<details>
<summary><strong>Table Definition</strong></summary>

Expand All @@ -12,7 +14,7 @@ CREATE TABLE `comments` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`post_id` bigint(20) NOT NULL,
`user_id` int(11) NOT NULL,
`comment` text NOT NULL COMMENT 'Comment\nMulti-line column comment',
`comment` text NOT NULL COMMENT 'Comment\nMulti-line\r\ncolumn\rcomment',
`created` datetime NOT NULL,
`updated` datetime DEFAULT NULL,
PRIMARY KEY (`id`),
Expand All @@ -21,7 +23,7 @@ CREATE TABLE `comments` (
KEY `comments_post_id_user_id_idx` (`post_id`,`user_id`),
CONSTRAINT `comments_post_id_fk` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`),
CONSTRAINT `comments_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Comments\nMulti-line table comment'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Comments\nMulti-line\r\ntable\rcomment'
```

</details>
Expand All @@ -34,7 +36,7 @@ CREATE TABLE `comments` (
| id | bigint(20) | | false | [logs](logs.md) | | |
| post_id | bigint(20) | | false | [comment_stars](comment_stars.md) | [posts](posts.md) | |
| user_id | int(11) | | false | [comment_stars](comment_stars.md) | [users](users.md) | |
| comment | text | | false | | | Comment<br>Multi-line column comment |
| comment | text | | false | | | Comment<br>Multi-line<br>column<br>comment |
| created | datetime | | false | | | |
| updated | datetime | | true | | | |

Expand Down
2 changes: 1 addition & 1 deletion sample/mysql8/post_comments.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ CREATE VIEW post_comments AS (select `c`.`id` AS `id`,`p`.`title` AS `title`,`u2
| id | bigint(20) | 0 | true | | | comments.id |
| title | varchar(255) | | false | | | posts.title |
| post_user | varchar(50) | | true | | | posts.users.username |
| comment | text | | true | | | Comment<br>Multi-line column comment |
| comment | text | | true | | | Comment<br>Multi-line<br>column<br>comment |
| comment_user | varchar(50) | | true | | | comments.users.username |
| created | datetime | | true | | | comments.created |
| updated | datetime | | true | | | comments.updated |
Expand Down
2 changes: 1 addition & 1 deletion sample/postgres/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
| ---- | ------- | ------- | ---- |
| [users](users.md) | 6 | Users table | BASE TABLE |
| [posts](posts.md) | 8 | Posts table | BASE TABLE |
| [comments](comments.md) | 6 | Comments<br>Multi-line table comment | BASE TABLE |
| [comments](comments.md) | 6 | Comments<br>Multi-line<br>table<br>comment | BASE TABLE |
| [comment_stars](comment_stars.md) | 6 | | BASE TABLE |
| [logs](logs.md) | 7 | audit log table | BASE TABLE |
| [post_comments](post_comments.md) | 7 | post and comments View table | VIEW |
Expand Down
6 changes: 4 additions & 2 deletions sample/postgres/comments.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
## Description

Comments
Multi-line table comment
Multi-line
table
comment

## Columns

Expand All @@ -12,7 +14,7 @@ Multi-line table comment
| id | bigint | nextval('comments_id_seq'::regclass) | false | [logs](logs.md) | | |
| post_id | bigint | | false | [comment_stars](comment_stars.md) | [posts](posts.md) | |
| user_id | integer | | false | [comment_stars](comment_stars.md) | [users](users.md) | |
| comment | text | | false | | | Comment<br>Multi-line column comment |
| comment | text | | false | | | Comment<br>Multi-line<br>column<br>comment |
| created | timestamp without time zone | | false | | | |
| updated | timestamp without time zone | | true | | | |

Expand Down
4 changes: 2 additions & 2 deletions test/my.sql
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ CREATE TABLE comments (
id bigint AUTO_INCREMENT,
post_id bigint NOT NULL,
user_id int NOT NULL,
comment text NOT NULL COMMENT 'Comment\nMulti-line column comment',
comment text NOT NULL COMMENT 'Comment\nMulti-line\r\ncolumn\rcomment',
created datetime NOT NULL,
updated datetime,
CONSTRAINT comments_id_pk PRIMARY KEY(id),
CONSTRAINT comments_post_id_fk FOREIGN KEY(post_id) REFERENCES posts(id) MATCH SIMPLE,
CONSTRAINT comments_user_id_fk FOREIGN KEY(user_id) REFERENCES users(id) MATCH SIMPLE,
UNIQUE(post_id, user_id)
) COMMENT = 'Comments\nMulti-line table comment';
) COMMENT = 'Comments\nMulti-line\r\ntable\rcomment';
CREATE INDEX comments_post_id_user_id_idx ON comments(post_id, user_id) USING HASH;

CREATE TABLE comment_stars (
Expand Down
4 changes: 2 additions & 2 deletions test/pg.sql
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ CREATE TABLE comments (
CONSTRAINT comments_user_id_fk FOREIGN KEY(user_id) REFERENCES users(id) MATCH SIMPLE,
UNIQUE(post_id, user_id)
);
COMMENT ON TABLE comments IS E'Comments\nMulti-line table comment';
COMMENT ON COLUMN comments.comment IS E'Comment\nMulti-line column comment';
COMMENT ON TABLE comments IS E'Comments\nMulti-line\r\ntable\rcomment';
COMMENT ON COLUMN comments.comment IS E'Comment\nMulti-line\r\ncolumn\rcomment';

CREATE INDEX comments_post_id_user_id_idx ON comments USING btree(post_id, user_id);

Expand Down

0 comments on commit 4e7988f

Please # to comment.