Mixing modular Drift codegen in feature package with classic builder (database.g.dart) in app database. #3693
Replies: 1 comment
-
|
Hi! At the moment you would unfortunately have to migrate everything to the modular generation mode (the reason is that by design, the non-modular builder thinks it's fine to generate everything into a single file). Another thing worth noting is that for multi-package setups, the inner packages need to have a regular (non-dev) dependency on I've never tried this, but I think one hybrid that may work and could make the migration easier is to:
That would mean fewer changes to make at once. I've never tried this with shared code, but e.g. the drift documentation site uses both modular and non-modular builders depending on the input file path. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
TL;DR: Can I keep my app on the classic single database.g.dart build while moving one feature at a time into its own package that uses modular Drift code generation (*.drift.dart)? If yes, what’s the recommended way to wire that package into my existing app database?
Context:
The app today has many tables and DAOs generated the old way into a single database.g.dart. The goal is to incrementally extract features into separate packages and each package will use the modular codegen to produce
*.drift.dartfiles.I want to consume such packages without switching the app to modular yet.
What I've tried:
Suppose I have a feature package
audit_schemaand have table and dao files like below:Table
DAO
I run the codegen and the
audit_table.drift.dartandaudit_dao.drift.dartfiles are generated.I export the dao and table file from
audit_schema.dartIn the Application code, I have the database defined as:
where the user table and dao files are also defined in the app as :
When generating the
database.g.dartfile with the classic builder in the app, I received an error in that file when trying to reference theAudittable file, so I had to import theaudit_schema.dartfrom the package.Also, I noticed that the generated database file uses its own
$AuditTableandAuditDataclasses instead of the ones from theaudit_table.drift.dart.I wanted to know if what I have tried is the correct approach or I am missing something.
Thanks in advance.
Beta Was this translation helpful? Give feedback.
All reactions