Repository navigation
[Proposal] Support splitting DBML to multiple files #843
Replies: 3 comments 4 replies
|
I like the overall direction. File isolation plus explicit use makes sense, and it addresses the organization/reuse problem well. One thing that feels unnecessarily verbose to me is requiring .dbml in the import path. If use only targets DBML modules, then: feels cleaner than:
I’d suggest allowing extensionless imports by default and resolving them to .dbml automatically. Supporting both forms would probably be the best DX: with one of them documented as the preferred style. Also, I think aliasing may become important quickly for larger projects, especially when importing enums/tables with overlapping names. |
|
I like the proposed use / reuse model, but for some large projects I do not actually want to maintain a barrel file. I would like an optional way to import a directory as a unit and let the tool scan its .dbml files, or even allow a command such as I realize this is less explicit than the current proposal, so I would see it as optional behavior rather than the default. But for domain-organized projects it would reduce boilerplate and make refactoring easier when the folder itself is the intended boundary. If this were considered, a few details would need to be defined clearly: whether scanning is recursive, how files are ordered, how duplicate names are handled, and whether a folder import behaves more like use or reuse. |
|
Hi 0xErwin1, cnagel-wti, DBML now supports multiple files in version 8.0.0. For now, only You can check this doc page for more details: https://dbml.dbdiagram.io/syntax/module-system |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
We are in the process of evaluating options to support splitting DBML file to multiple files. We want to make a proposal and would like your input.
Use cases
Proposed design for multi-file DBML
Split your DBML schema across multiple files - keep things organized, import only what you need.
Importing with
usePick exactly what you need:
Or grab everything from a file:
Avoiding name conflicts with aliases
Handy when two files define something with the same name.
File paths
Use relative paths without the
.dbmlextension:How it works
.dbmlfile is isolated by default, nothing leaks in or out unless you explicitly say so.useis how you bring things in.What can be imported?
enumtabletablepartialschematablegrouprefrecordsCircular imports are fine
DBML is declarative, there's no execution order, so files can freely reference each other without any issues.
Imports are not transitive
If
a.dbmlimportsb.dbml, andb.dbmlimportsc.dbml,c.dbml's items are NOT available ina.dbml:This is intentional - keeps imports explicit and predictable, same behaviour as
importin JavaScript.If you desire this behavior, then you can consider "re-export" as detailed in the following section.
Re-exporting with
reusereuse=use+ re-export.It lets a file act as a barrel: importing from sub-files and re-exposing them to anyone who imports it.
The problem it solves: Say you started with one big
common.dbmland later split it into multiple files. Withoutreuse, every consumer would need to update their imports manually. Withreuse:Consumers never need to know how your files are organized internally, just point them at the barrel file.
Vision: large project workflow
For large projects, split by domain and compose everything in a single entry point:
dbdocs build ./project.dbml # builds everythingEach domain file is self-contained and only imports what it needs. In this case,
project.dbmlis the single entry point: it composes everything without declaring anything itself.How this design fits the use cases
Tagging @nyimbi, @0xErwin1, @asule90, @lucianokrebss, @lloydhumphreys
All reactions