dbml icon indicating copy to clipboard operation
dbml copied to clipboard

Add support for imports and exports

Open 0xErwin1 opened this issue 2 years ago • 2 comments

Hi,

I'd like to propose an enhancement to the DBML language that would ease the management of large and complex schemas, especially in projects that progress through multiple phases. I have two potential approaches I'd like to present.

Background:

At my job, we're in an advanced phase of a project using DBML, with many tables and enums already created. The need to manage and maintain code between project phases is growing, and I see an opportunity to improve modularity and code reuse with import and export support.

Proposal 1: Direct support for imports and exports

  1. Imports: Introduce new syntax to import other DBML files. For instance:
    import 'path/to/other/file.dbml'
    
  2. Exports: Allow specifying which elements from the current file should be exported.
    export Table User {
    

Proposal 2: Preprocessing system akin to C's "include"

Instead of handling imports and exports directly within the language, we could introduce a preprocessing system. Developers would use an "include" syntax to stitch together various DBML files into one during a preprocessing phase. This approach would hide the modularity from the DBML engine, which would see a single, unified file.

For example:

include "path/to/other/file.dbml"

Common Benefits:

  • Modularity: Facilitates reading and maintenance by breaking schemas into logical modules.
  • Reusability: Common definitions can be set once and then reused.

Potential Challenges:

  • Conflict resolution: Clear strategy to handle name conflicts between files.
  • Circular loading: Avoiding infinite loops from mutual imports.

I hope you find these proposals of interest. I am willing to collaborate on the implementation and clarify any questions.

Best regards

0xErwin1 avatar Oct 26 '23 13:10 0xErwin1

i think its the same as https://github.com/holistics/dbml/issues/125

asule90 avatar Dec 18 '23 11:12 asule90

Yes, I saw that, but since the last update was in 2021, I wanted to get this topic moved again.

0xErwin1 avatar Dec 18 '23 14:12 0xErwin1