mirror of https://github.com/AMT-Cheif/drift.git
parent
98fd6a0ef0
commit
863dbb61a9
|
@ -1,3 +1,7 @@
|
||||||
|
## 2.17.0-dev
|
||||||
|
|
||||||
|
- Fix drift using the wrong import alias in generated part files.
|
||||||
|
|
||||||
## 2.16.0
|
## 2.16.0
|
||||||
|
|
||||||
- Keep import alias when referencing existing elements in generated code
|
- Keep import alias when referencing existing elements in generated code
|
||||||
|
|
|
@ -31,13 +31,23 @@ class ImportManagerForPartFiles extends ImportManager {
|
||||||
// Part files can't add their own imports, so try to find the element in an
|
// Part files can't add their own imports, so try to find the element in an
|
||||||
// existing import.
|
// existing import.
|
||||||
for (final MapEntry(:key, :value) in _namedImports.entries) {
|
for (final MapEntry(:key, :value) in _namedImports.entries) {
|
||||||
if (value.containsKey(elementName)) {
|
final foundHere = value[elementName];
|
||||||
|
if (foundHere != null && _matchingUrl(definitionUri, foundHere)) {
|
||||||
return key;
|
return key;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool _matchingUrl(Uri wanted, Element target) {
|
||||||
|
final targetUri = target.librarySource?.uri;
|
||||||
|
if (targetUri == null || targetUri.scheme != wanted.scheme) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class NullImportManager extends ImportManager {
|
class NullImportManager extends ImportManager {
|
||||||
|
|
|
@ -38,16 +38,17 @@ CREATE INDEX b_idx /* comment should be stripped */ ON b (foo, upper(foo));
|
||||||
final result = await emulateDriftBuild(
|
final result = await emulateDriftBuild(
|
||||||
inputs: {
|
inputs: {
|
||||||
'a|lib/main.dart': r'''
|
'a|lib/main.dart': r'''
|
||||||
|
import 'dart:io' as io;
|
||||||
import 'package:drift/drift.dart' as drift;
|
import 'package:drift/drift.dart' as drift;
|
||||||
import 'tables.dart' as tables;
|
import 'tables.dart' as tables;
|
||||||
|
|
||||||
@drift.DriftDatabase(tables: [tables.Texts])
|
@drift.DriftDatabase(tables: [tables.Files])
|
||||||
class MyDatabase extends _$MyDatabase {}
|
class MyDatabase extends _$MyDatabase {}
|
||||||
''',
|
''',
|
||||||
'a|lib/tables.dart': '''
|
'a|lib/tables.dart': '''
|
||||||
import 'package:drift/drift.dart';
|
import 'package:drift/drift.dart';
|
||||||
|
|
||||||
class Texts extends Table {
|
class Files extends Table {
|
||||||
TextColumn get content => text()();
|
TextColumn get content => text()();
|
||||||
}
|
}
|
||||||
''',
|
''',
|
||||||
|
@ -59,12 +60,12 @@ class Texts extends Table {
|
||||||
'a|lib/main.drift.dart': decodedMatches(
|
'a|lib/main.drift.dart': decodedMatches(
|
||||||
allOf(
|
allOf(
|
||||||
contains(
|
contains(
|
||||||
r'class $TextsTable extends tables.Texts with '
|
r'class $FilesTable extends tables.Files with '
|
||||||
r'drift.TableInfo<$TextsTable, Text>',
|
r'drift.TableInfo<$FilesTable, File>',
|
||||||
),
|
),
|
||||||
contains(
|
contains(
|
||||||
'class Text extends drift.DataClass implements '
|
'class File extends drift.DataClass implements '
|
||||||
'drift.Insertable<Text>',
|
'drift.Insertable<File>',
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
Loading…
Reference in New Issue