Skip to content

Commit 45507e7

Browse files
authored
feat: add --omit-entity-name-quotes option for dbml (#114)
1 parent f25c7bb commit 45507e7

File tree

7 files changed

+143
-55
lines changed

7 files changed

+143
-55
lines changed

dbterd/adapters/targets/dbml.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,11 @@ def parse(manifest: Manifest, catalog: Catalog, **kwargs) -> str:
3737

3838
# Build DBML content
3939
dbml = "//Tables (based on the selection criteria)\n"
40+
quote = "" if kwargs.get("omit_entity_name_quotes") else '"'
4041
for table in tables:
4142
dbml += f"//--configured at schema: {table.database}.{table.schema}\n"
42-
dbml += 'Table "{table}" {{\n{columns}\n\n Note: {table_note}\n}}\n'.format(
43+
dbml += "Table {quote}{table}{quote} {{\n{columns}\n\n Note: {table_note}\n}}\n".format(
44+
quote=quote,
4345
table=table.name,
4446
columns="\n".join(
4547
[
@@ -61,8 +63,8 @@ def parse(manifest: Manifest, catalog: Catalog, **kwargs) -> str:
6163

6264
dbml += "//Refs (based on the DBT Relationship Tests)\n"
6365
for rel in relationships:
64-
key_from = f'"{rel.table_map[1]}"."{rel.column_map[1]}"'
65-
key_to = f'"{rel.table_map[0]}"."{rel.column_map[0]}"'
66+
key_from = f'{quote}{rel.table_map[1]}{quote}."{rel.column_map[1]}"'
67+
key_to = f'{quote}{rel.table_map[0]}{quote}."{rel.column_map[0]}"'
6668
dbml += f"Ref: {key_from} {get_rel_symbol(rel.type)} {key_to}\n"
6769
return dbml
6870

dbterd/cli/params.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,13 @@ def common_params(func):
5555
show_default=True,
5656
type=click.STRING,
5757
)
58+
@click.option(
59+
"--omit-entity-name-quotes",
60+
help="Flag to omit double quotes in the entity name. Currently only dbml is supported",
61+
is_flag=True,
62+
default=False,
63+
show_default=True,
64+
)
5865
@click.option(
5966
"--output",
6067
"-o",
2.15 KB
Loading
1.66 KB
Loading

docs/nav/guide/cli-references.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,33 @@ Currently, it supports the following keys in the format:
404404
dbterd run --entity-name-format table # with table name only
405405
```
406406

407+
### dbterd run --omit-entity-name-quotes
408+
409+
Flag to omit the double quotes in the generated entity name. Currently only `dbml` is supported.
410+
411+
> Default to `False`
412+
413+
Enabled it to allow `dbdocs` to recognize the schemas and display them as grouping:
414+
415+
- With quotes:
416+
417+
![dbdocs-enf-with-quotes](../../assets/images/dbdocs-enf-with-quotes.png)
418+
419+
- Without quotes:
420+
421+
![dbdocs-enf-without-quotes](../../assets/images/dbdocs-enf-without-quotes.png)
422+
423+
> ⚠️ As of 2024 June: DBML doesn't support nested schema in the entity name which means 'database.schema.table' won't be allowed, but 'schema.table' does!
424+
425+
**Examples:**
426+
=== "CLI"
427+
428+
```bash
429+
dbterd run --entity-name-format resource.package.model --omit-entity-name-quotes # ❌
430+
dbterd run --entity-name-format database.schema.table --omit-entity-name-quotes # ❌
431+
dbterd run --entity-name-format schema.table --omit-entity-name-quotes # ✅
432+
```
433+
407434
### dbterd run --dbt-cloud
408435

409436
Decide to download artifact files from dbt Cloud Job Run instead of compiling locally.

poetry.lock

Lines changed: 60 additions & 50 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)