Skip to content

Commit

Permalink
Merge pull request #347 from trilogy-group/er_diagram_links
Browse files Browse the repository at this point in the history
Er diagram links
  • Loading branch information
k1LoW authored Apr 9, 2022
2 parents d59d55e + 6996b45 commit 87a9662
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 5 deletions.
2 changes: 1 addition & 1 deletion datasource/datasource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ var tests = []struct {
{config.DSN{URL: "pg://postgres:pgpass@localhost:55432/testdb?sslmode=disable"}, "testdb", 17, 12},
{config.DSN{URL: "json://../testdata/testdb.json"}, "testdb", 11, 12},
{config.DSN{URL: "https://raw.githubusercontent.com/k1LoW/tbls/main/testdata/testdb.json"}, "testdb", 11, 12},
{config.DSN{URL: "ms://SA:MSSQLServer-Passw0rd@localhost:11433/testdb"}, "testdb", 10, 7},
{config.DSN{URL: "ms://SA:MSSQLServer-Passw0rd@localhost:11433/testdb"}, "testdb", 11, 7},
}

func TestMain(m *testing.M) {
Expand Down
2 changes: 1 addition & 1 deletion output/md/templates/table.md.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
{{- if .er -}}
## {{ "Relations" | lookup }}

![er]({{ .baseUrl }}{{ .Table.Name }}.{{ .erFormat }})
![er]({{ .baseUrl }}{{ .Table.Name | escape }}.{{ .erFormat }})

{{ end -}}
---
Expand Down
4 changes: 4 additions & 0 deletions output/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/k1LoW/tbls/dict"
"github.com/k1LoW/tbls/schema"
"gitlab.com/golang-commonmark/mdurl"
)

// Output is interface for output
Expand Down Expand Up @@ -43,6 +44,9 @@ func Funcs(d *dict.Dict) map[string]interface{} {
return d.Lookup(text)
},
"label_join": LabelJoin,
"escape": func(text string) string {
return mdurl.Encode(text)
},
}
}

Expand Down
1 change: 1 addition & 0 deletions sample/mssql/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Sample database document.
| [CamelizeTable](CamelizeTable.md) | 2 | | BASIC TABLE | |
| [hyphen-table](hyphen-table.md) | 3 | | BASIC TABLE | |
| [administrator.blogs](administrator.blogs.md) | 6 | admin blogs | BASIC TABLE | |
| [name with spaces](name%20with%20spaces.md) | 1 | | VIEW | |

## Relations

Expand Down
33 changes: 33 additions & 0 deletions sample/mssql/name with spaces.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# name with spaces

## Description

<details>
<summary><strong>Table Definition</strong></summary>

```sql
CREATE VIEW "name with spaces" AS (
SELECT TOP 1 p.title
FROM posts AS p
);
```

</details>

## Referenced Tables

- [posts](posts.md)

## Columns

| Name | Type | Default | Nullable | Children | Parents | Comment |
| ---- | ---- | ------- | -------- | -------- | ------- | ------- |
| title | varchar(255) | | false | | | |

## Relations

![er](name%20with%20spaces.svg)

---

> Generated by [tbls](https://github.com/k1LoW/tbls)
26 changes: 26 additions & 0 deletions sample/mssql/name with spaces.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 15 additions & 3 deletions sample/mssql/schema.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions testdata/ddl/mssql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ DROP TYPE IF EXISTS post_types;
DROP TABLE IF EXISTS user_options;
DROP TABLE IF EXISTS users;
DROP SCHEMA IF EXISTS administrator;
DROP VIEW IF EXISTS "name with spaces";

CREATE TABLE users (
id int NOT NULL IDENTITY(1,1) PRIMARY KEY,
Expand Down Expand Up @@ -165,3 +166,8 @@ BEGIN
UPDATE users SET updated = GETDATE()
WHERE id = ( SELECT user_id FROM deleted)
END;

CREATE VIEW "name with spaces" AS (
SELECT TOP 1 p.title
FROM posts AS p
);

0 comments on commit 87a9662

Please sign in to comment.