Skip to content

Conversation

@danielgary
Copy link

@danielgary danielgary commented Sep 9, 2025

Summary

Implemented SQLite exporter with many-to-many relations and proper index exporting support. Included tests.

Issue

#14
#286

Lasting Changes (Technical)

  • Added sqlite as an export option for the cli
  • Implented SQLiteExporter class

Checklist

Please check directly on the box once each of these are done

  • Documentation (if necessary)
  • Tests (integration test/unit test)
  • Integration Tests Passed
  • Code Review

@danielgary danielgary changed the title feat: adds support for exporting to sqlite feat(dbml/core): adds support for exporting to sqlite Sep 10, 2025
@danielgary
Copy link
Author

danielgary commented Sep 15, 2025

Just curious if I missed something in this PR? I'm happy to fix if something is missing. Can someone on this project provide some guidance?

@H-DNA
Copy link
Contributor

H-DNA commented Nov 4, 2025

Hey @danielgary, sorry for the late reply. Thanks for the contribution! We'll definitely take a look at your PR when we have time. Thank you for your patience.

@H-DNA
Copy link
Contributor

H-DNA commented Nov 13, 2025

Thank you for resolving all my comments, I'll continue reviewing when I have time!

Copy link
Contributor

@H-DNA H-DNA left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the implementation most of the part is good 💯 please help consider some suggestions and add more testcases. Then I'll perform one final round of review. Thank you!

return indexArr;
}

static export(model) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since dbml v5.0.0, we have supported check constraints in model_structure. The model parameter now can contain information about check constraints.

You can look at the definition here for reference:

Please help us exporting Check constraints as well!

const allRefIds = _.flatten(database.schemaIds.map(sid => model.schemas[sid].refIds || []));
const { fksByTableId, junctionCreates, dependencyEdges } = SqliteExporter.collectForeignKeysByTable(allRefIds, model);

const allTableIds = _.flatten(database.schemaIds.map(sid => model.schemas[sid].tableIds || []));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you use flatMap instead of map + flatten?

Comment on lines +73 to +74
map.set(fq, vals);
map.set(local, vals);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if this approach would work if there are two enums in two different schemas but have the same name? For example:

Enum S1.E {
}

Enum S2.E {
}

By performing map.set(local, vals), E would be set two times and the latter would override.


const enumMap = SqliteExporter.buildEnumMap(model);

const allRefIds = _.flatten(database.schemaIds.map(sid => model.schemas[sid].refIds || []));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you use flatMap instead of map + flatten?


const tableCreates = SqliteExporter.exportTables(orderedTableIds, model, enumMap, fksByTableId);

const allIndexIds = _.flatten(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you use flatMap instead of map + flatten?

const allIndexIds = _.flatten(
(database.schemaIds || []).map(sid => {
const tIds = model.schemas[sid].tableIds || [];
return _.flatten(tIds.map(tid => model.tables[tid].indexIds || []));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you use flatMap instead of map + flatten?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The testcases are failing. Please help update the tests!
Also, can you verify that the following cases are covered in the test cases:

  • Fields that have types in the form of name(args) such as VARCHAR(255).
  • Various index types: unique, primary, functional, multi-column (unique and primary).
  • Unique constraints.
  • Default
  • Autoincrement.
  • Various referential actions.
  • Primary constraints.
  • Check constraints.
  • Enums
  • Multi-column, many-to-many, one-to-one, one-to-many, zero-to-one, zero-to-many Refs.
  • Not null constraints
  • Column types that have spaces in their names.
  • Table and column names that contain spaces in them
    You can look up the input for the test cases by reusing the other input files in the other exporters.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants