Skip to content

Commit

Permalink
Respect generate_manager for modular builds
Browse files Browse the repository at this point in the history
  • Loading branch information
simolus3 committed Oct 10, 2024
1 parent 69f3c02 commit d74c077
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
1 change: 1 addition & 0 deletions drift_dev/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
}
```
- Make `build.yaml` definitions pass `build_runner doctor`.
- Fix `generate_manager` option not consistently being applied to modular builds.

## 2.20.3

Expand Down
10 changes: 7 additions & 3 deletions drift_dev/lib/src/backends/build/drift_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -290,15 +290,15 @@ class _DriftBuildRun {
}

Future<void> _generateModular(FileState entrypointState) async {
final managerWriter = DatabaseManagerWriter(writer.child(), '');

for (final element in entrypointState.analysis.values) {
final result = element.result;

if (result is DriftTable) {
TableWriter(result, writer.child()).writeInto();

final scope = writer.child();
final manager = DatabaseManagerWriter(scope, '')..addTable(result);
manager.writeTableManagers();
managerWriter.addTable(result);
} else if (result is DriftView) {
ViewWriter(result, writer.child(), null).write();
} else if (result is DriftTrigger) {
Expand Down Expand Up @@ -355,6 +355,10 @@ class _DriftBuildRun {
}

ModularAccessorWriter(writer.child(), entrypointState, driver).write();

if (options.generateManager) {
managerWriter.writeTableManagers();
}
}

Future<void> _generateMonolithic(FileState entrypointState) async {
Expand Down
22 changes: 22 additions & 0 deletions drift_dev/test/backends/build/build_integration_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,28 @@ q: INSERT INTO my_table (b, c, d) VALUES (?, ?, ?);
}, result.dartOutputs, result.writer);
});

test('can disable manager code for modular builds', () async {
final result = await emulateDriftBuild(
inputs: {
'a|lib/main.drift': '''
CREATE TABLE my_table (
a INTEGER PRIMARY KEY,
b TEXT,
c BLOB,
d ANY
) STRICT;
''',
},
modularBuild: true,
options: BuilderOptions({'generate_manager': false}),
logger: loggerThat(neverEmits(anything)),
);

checkOutputs({
'a|lib/main.drift.dart': decodedMatches(isNot(contains('Manager'))),
}, result.dartOutputs, result.writer);
});

test('supports `MAPPED BY` for columns', () async {
final results = await emulateDriftBuild(
inputs: {
Expand Down

0 comments on commit d74c077

Please sign in to comment.