Add import in ORM lib
This commit is contained in:
parent
41f1165a1f
commit
9dffee9bc7
1 changed files with 18 additions and 7 deletions
|
@ -1,5 +1,5 @@
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
import 'dart:collection';
|
||||||
import 'package:analyzer/dart/element/element.dart';
|
import 'package:analyzer/dart/element/element.dart';
|
||||||
import 'package:angel_orm/angel_orm.dart';
|
import 'package:angel_orm/angel_orm.dart';
|
||||||
import 'package:build/build.dart';
|
import 'package:build/build.dart';
|
||||||
|
@ -44,10 +44,21 @@ class OrmGenerator extends GeneratorForAnnotation<Orm> {
|
||||||
Library buildOrmBaseLibrary(AssetId inputId, OrmBuildContext ctx) {
|
Library buildOrmBaseLibrary(AssetId inputId, OrmBuildContext ctx) {
|
||||||
return new Library((lib) {
|
return new Library((lib) {
|
||||||
// Necessary imports
|
// Necessary imports
|
||||||
lib.directives.addAll([
|
var imports = new SplayTreeSet<String>.from(
|
||||||
new Directive.import('dart:async'),
|
['dart:async', p.basename(inputId.uri.path)]);
|
||||||
new Directive.import(p.basename(inputId.uri.path)),
|
|
||||||
]);
|
switch (ctx.ormAnnotation.type) {
|
||||||
|
case OrmType.mongoDB:
|
||||||
|
imports.add('package:mongo_dart/mongo_dart.dart');
|
||||||
|
break;
|
||||||
|
case OrmType.postgreSql:
|
||||||
|
imports.add('package:postgres/postgres.dart');
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
lib.directives.addAll(imports.map((url) => new Directive.import(url)));
|
||||||
|
|
||||||
// Add the corresponding `part`
|
// Add the corresponding `part`
|
||||||
String dbExtension;
|
String dbExtension;
|
||||||
|
@ -69,8 +80,8 @@ class OrmGenerator extends GeneratorForAnnotation<Orm> {
|
||||||
throw 'Unsupported ORM type: ${ctx.ormAnnotation.type}';
|
throw 'Unsupported ORM type: ${ctx.ormAnnotation.type}';
|
||||||
}
|
}
|
||||||
|
|
||||||
var dbFile =
|
var dbFile = p.setExtension(
|
||||||
p.setExtension(p.basename(inputId.uri.path), '.$dbExtension.orm.g.dart');
|
p.basename(inputId.uri.path), '.$dbExtension.orm.g.dart');
|
||||||
|
|
||||||
lib.body.add(new Code("part '$dbFile';"));
|
lib.body.add(new Code("part '$dbFile';"));
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue