mirror of https://github.com/AMT-Cheif/drift.git
Fix moor files importing the original Dart source
This commit is contained in:
parent
1e962312ca
commit
51d5ada5c9
|
@ -50,13 +50,6 @@ abstract class AnalyzingStep extends Step {
|
|||
@override
|
||||
final bool isParsing = false;
|
||||
|
||||
List<FoundFile> _transitiveImports(Iterable<FoundFile> directImports) {
|
||||
return task
|
||||
.crawlImports(directImports)
|
||||
.where((import) => import != file)
|
||||
.toList();
|
||||
}
|
||||
|
||||
Iterable<MoorSchemaEntity> _availableEntities(List<FoundFile> imports) {
|
||||
return imports.expand<MoorSchemaEntity>((file) =>
|
||||
file.currentResult?.declaredEntities ?? const Iterable.empty());
|
||||
|
|
|
@ -9,7 +9,7 @@ class AnalyzeDartStep extends AnalyzingStep {
|
|||
final parseResult = file.currentResult as ParsedDartFile;
|
||||
|
||||
for (final accessor in parseResult.dbAccessors) {
|
||||
final transitiveImports = _transitiveImports(accessor.imports);
|
||||
final transitiveImports = task.crawlImports(accessor.imports).toList();
|
||||
|
||||
final unsortedEntities = _availableEntities(transitiveImports).toSet();
|
||||
|
||||
|
|
|
@ -0,0 +1,54 @@
|
|||
// @dart=2.9
|
||||
import 'package:moor_generator/src/analyzer/runner/results.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import '../utils.dart';
|
||||
|
||||
void main() {
|
||||
test('moor files can import original dart source', () async {
|
||||
final state = TestState.withContent({
|
||||
'a|lib/base.dart': r'''
|
||||
import 'package:moor/moor.dart';
|
||||
|
||||
part 'base.g.dart';
|
||||
|
||||
class Events extends Table {
|
||||
IntColumn get id => integer().autoIncrement()();
|
||||
|
||||
RealColumn get sumVal => real().withDefault(Constant(0))();
|
||||
}
|
||||
|
||||
class Records extends Table {
|
||||
IntColumn get id => integer().autoIncrement()();
|
||||
|
||||
IntColumn get eventId => integer()();
|
||||
|
||||
RealColumn get value => real().nullable()();
|
||||
}
|
||||
|
||||
class Units extends Table {
|
||||
IntColumn get id => integer().autoIncrement()();
|
||||
}
|
||||
|
||||
@UseMoor(include: {'customizedSQL.moor'})
|
||||
class AppDatabase extends _$AppDatabase {
|
||||
AppDatabase()
|
||||
: super(FlutterQueryExecutor.inDatabaseFolder(
|
||||
path: "db.sqlite", logStatements: true));
|
||||
}
|
||||
''',
|
||||
'a|lib/customizedSQL.moor': '''
|
||||
import 'base.dart';
|
||||
|
||||
create trigger addVal after insert on records when id = NEW.event_id BEGIN update events set sum_val = sum_val + NEW.value; END;
|
||||
''',
|
||||
});
|
||||
addTearDown(state.close);
|
||||
|
||||
final file = await state.analyze('package:a/base.dart');
|
||||
final result = file.currentResult as ParsedDartFile;
|
||||
final db = result.declaredDatabases.single;
|
||||
|
||||
expect(db.tables, hasLength(3));
|
||||
});
|
||||
}
|
Loading…
Reference in New Issue