mirror of https://github.com/AMT-Cheif/drift.git
move geopoly to extensions
This commit is contained in:
parent
349787ad4b
commit
5e5628d1a8
|
@ -0,0 +1,71 @@
|
|||
/// https://www.sqlite.org/geopoly.html
|
||||
/// The Geopoly Interface To The SQLite R*Tree Module
|
||||
|
||||
library geopoly;
|
||||
|
||||
import 'dart:typed_data';
|
||||
|
||||
import '../src/runtime/query_builder/query_builder.dart';
|
||||
import '../src/runtime/types/mapping.dart';
|
||||
|
||||
///
|
||||
final class GeopolyPolygonType implements CustomSqlType<GeopolyPolygon> {
|
||||
///
|
||||
const GeopolyPolygonType();
|
||||
|
||||
@override
|
||||
String mapToSqlLiteral(GeopolyPolygon dartValue) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
@override
|
||||
Object mapToSqlParameter(GeopolyPolygon dartValue) {
|
||||
switch (dartValue) {
|
||||
case GeopolyPolygonString(:final value):
|
||||
return value;
|
||||
case GeopolyPolygonBlob(:final value):
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
GeopolyPolygon read(Object fromSql) {
|
||||
return switch (fromSql) {
|
||||
Uint8List() => GeopolyPolygon.blob(fromSql),
|
||||
String() => GeopolyPolygon.text(fromSql),
|
||||
_ => throw UnimplementedError(),
|
||||
};
|
||||
}
|
||||
|
||||
@override
|
||||
String sqlTypeName(GenerationContext context) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
}
|
||||
|
||||
/// In Geopoly, a polygon can be text or a blob
|
||||
sealed class GeopolyPolygon {
|
||||
const GeopolyPolygon._();
|
||||
|
||||
const factory GeopolyPolygon.text(String value) = GeopolyPolygonString;
|
||||
|
||||
const factory GeopolyPolygon.blob(Uint8List value) = GeopolyPolygonBlob;
|
||||
}
|
||||
|
||||
///
|
||||
final class GeopolyPolygonString extends GeopolyPolygon {
|
||||
///
|
||||
final String value;
|
||||
|
||||
///
|
||||
const GeopolyPolygonString(this.value) : super._();
|
||||
}
|
||||
|
||||
///
|
||||
final class GeopolyPolygonBlob extends GeopolyPolygon {
|
||||
///
|
||||
final Uint8List value;
|
||||
|
||||
///
|
||||
const GeopolyPolygonBlob(this.value) : super._();
|
||||
}
|
|
@ -7,3 +7,5 @@ export 'runtime/query_builder/query_builder.dart' show TableInfo;
|
|||
|
||||
export 'dsl/dsl.dart'
|
||||
show Table, TableIndex, View, DriftDatabase, DriftAccessor;
|
||||
|
||||
export '../extensions/geopoly.dart';
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import 'dart:core';
|
||||
import 'dart:core' as core;
|
||||
import 'dart:core';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:collection/collection.dart';
|
||||
|
@ -81,15 +81,6 @@ final class SqlTypes {
|
|||
return dartValue.rawSqlValue;
|
||||
}
|
||||
|
||||
if (dartValue is GeopolyPolygon) {
|
||||
switch (dartValue) {
|
||||
case _StringGeopolyPolygon(:final value):
|
||||
return value;
|
||||
case _BlobGeopolyPolygon(:final value):
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
return dartValue;
|
||||
}
|
||||
|
||||
|
@ -551,25 +542,3 @@ final class _ByDialectType<T extends Object> implements DialectAwareSqlType<T> {
|
|||
return _selectType(context.typeMapping).sqlTypeName(context);
|
||||
}
|
||||
}
|
||||
|
||||
/// https://www.sqlite.org/geopoly.html
|
||||
/// In Geopoly, a polygon can be text or a blob
|
||||
sealed class GeopolyPolygon {
|
||||
const GeopolyPolygon._();
|
||||
|
||||
const factory GeopolyPolygon.text(String value) = _StringGeopolyPolygon;
|
||||
|
||||
const factory GeopolyPolygon.blob(Uint8List value) = _BlobGeopolyPolygon;
|
||||
}
|
||||
|
||||
final class _StringGeopolyPolygon extends GeopolyPolygon {
|
||||
final String value;
|
||||
|
||||
const _StringGeopolyPolygon(this.value) : super._();
|
||||
}
|
||||
|
||||
final class _BlobGeopolyPolygon extends GeopolyPolygon {
|
||||
final Uint8List value;
|
||||
|
||||
const _BlobGeopolyPolygon(this.value) : super._();
|
||||
}
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
import 'dart:convert';
|
||||
|
||||
import 'package:analyzer/dart/element/element.dart';
|
||||
import 'package:meta/meta.dart';
|
||||
import 'package:sqlparser/sqlparser.dart';
|
||||
|
||||
import '../options.dart';
|
||||
import '../backend.dart';
|
||||
import '../drift_native_functions.dart';
|
||||
import '../options.dart';
|
||||
import '../resolver/dart/helper.dart';
|
||||
import '../resolver/discover.dart';
|
||||
import '../resolver/drift/sqlparser/mapping.dart';
|
||||
|
@ -62,10 +63,30 @@ class DriftAnalysisDriver {
|
|||
|
||||
AnalysisResultCacheReader? cacheReader;
|
||||
|
||||
KnownDriftTypes? _knownTypes;
|
||||
final KnownDriftTypes knownTypes;
|
||||
|
||||
DriftAnalysisDriver(this.backend, this.options, {bool isTesting = false})
|
||||
: _isTesting = isTesting;
|
||||
@visibleForTesting
|
||||
DriftAnalysisDriver(
|
||||
this.backend,
|
||||
this.options,
|
||||
this.knownTypes, {
|
||||
bool isTesting = false,
|
||||
}) : _isTesting = isTesting;
|
||||
|
||||
static Future<DriftAnalysisDriver> init(
|
||||
DriftBackend backend,
|
||||
DriftOptions options, {
|
||||
bool isTesting = false,
|
||||
}) async {
|
||||
final driver = DriftAnalysisDriver(
|
||||
backend,
|
||||
options,
|
||||
await KnownDriftTypes.resolve(backend),
|
||||
isTesting: isTesting,
|
||||
);
|
||||
|
||||
return driver;
|
||||
}
|
||||
|
||||
SqlEngine newSqlEngine() {
|
||||
return SqlEngine(
|
||||
|
@ -90,11 +111,6 @@ class DriftAnalysisDriver {
|
|||
);
|
||||
}
|
||||
|
||||
/// Loads types important for Drift analysis.
|
||||
Future<KnownDriftTypes> loadKnownTypes() async {
|
||||
return _knownTypes ??= await KnownDriftTypes.resolve(this);
|
||||
}
|
||||
|
||||
/// For a given file under [uri], attempts to restore serialized analysis
|
||||
/// results that have been stored before.
|
||||
///
|
||||
|
@ -359,6 +375,7 @@ abstract class AnalysisResultCacheReader {
|
|||
Future<CachedDiscoveryResults?> readDiscovery(Uri uri);
|
||||
|
||||
Future<LibraryElement?> readTypeHelperFor(Uri uri);
|
||||
|
||||
Future<String?> readElementCacheFor(Uri uri);
|
||||
}
|
||||
|
||||
|
|
|
@ -344,7 +344,7 @@ class ColumnParser {
|
|||
.apply(getter.name.lexeme);
|
||||
ColumnType columnType;
|
||||
|
||||
final helper = await _resolver.resolver.driver.loadKnownTypes();
|
||||
final helper = _resolver.resolver.driver.knownTypes;
|
||||
|
||||
if (foundStartMethod == _startCustom) {
|
||||
final expression = remainingExpr.argumentList.arguments.single;
|
||||
|
|
|
@ -7,7 +7,7 @@ import 'package:analyzer/dart/element/type_provider.dart';
|
|||
import 'package:analyzer/dart/element/type_system.dart';
|
||||
import 'package:collection/collection.dart';
|
||||
|
||||
import '../../driver/driver.dart';
|
||||
import '../../backend.dart';
|
||||
import '../../driver/error.dart';
|
||||
import '../../results/results.dart';
|
||||
import '../resolver.dart';
|
||||
|
@ -32,6 +32,7 @@ class KnownDriftTypes {
|
|||
final InterfaceElement jsonTypeConverter;
|
||||
final InterfaceType driftAny;
|
||||
final InterfaceType uint8List;
|
||||
final InterfaceType geopolyPolygon;
|
||||
|
||||
KnownDriftTypes._(
|
||||
this.helperLibrary,
|
||||
|
@ -47,6 +48,7 @@ class KnownDriftTypes {
|
|||
this.driftAccessor,
|
||||
this.driftAny,
|
||||
this.uint8List,
|
||||
this.geopolyPolygon,
|
||||
);
|
||||
|
||||
/// Constructs the set of known drift types from a helper library, which is
|
||||
|
@ -73,6 +75,8 @@ class KnownDriftTypes {
|
|||
.defaultInstantiation,
|
||||
(exportNamespace.get('Uint8List') as InterfaceElement)
|
||||
.defaultInstantiation,
|
||||
(exportNamespace.get('GeopolyPolygon') as InterfaceElement)
|
||||
.defaultInstantiation,
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -98,8 +102,8 @@ class KnownDriftTypes {
|
|||
return type?.asInstanceOf(converter);
|
||||
}
|
||||
|
||||
static Future<KnownDriftTypes> resolve(DriftAnalysisDriver driver) async {
|
||||
final library = await driver.backend.readDart(uri);
|
||||
static Future<KnownDriftTypes> resolve(DriftBackend backend) async {
|
||||
final library = await backend.readDart(uri);
|
||||
|
||||
return KnownDriftTypes._fromLibrary(library);
|
||||
}
|
||||
|
@ -256,7 +260,7 @@ class DataClassInformation {
|
|||
useRowClass.getField('constructor')!.toStringValue()!;
|
||||
final generateInsertable =
|
||||
useRowClass.getField('generateInsertable')!.toBoolValue()!;
|
||||
final helper = await resolver.resolver.driver.loadKnownTypes();
|
||||
final helper = resolver.resolver.driver.knownTypes;
|
||||
|
||||
if (type is InterfaceType) {
|
||||
final found = FoundDartClass(type.element, type.typeArguments);
|
||||
|
|
|
@ -53,7 +53,7 @@ class DartViewResolver extends LocalElementResolver<DiscoveredDartView> {
|
|||
Future<TableReferenceInDartView?> _getStaticReference(
|
||||
FieldElement field) async {
|
||||
final type = field.type;
|
||||
final knownTypes = await resolver.driver.loadKnownTypes();
|
||||
final knownTypes = resolver.driver.knownTypes;
|
||||
final typeSystem = field.library.typeSystem;
|
||||
|
||||
if (type is! InterfaceType ||
|
||||
|
|
|
@ -73,8 +73,7 @@ class DiscoverStep {
|
|||
_file.discovery = NotADartLibrary();
|
||||
break;
|
||||
}
|
||||
final finder =
|
||||
_FindDartElements(this, library, await _driver.loadKnownTypes());
|
||||
final finder = _FindDartElements(this, library, _driver.knownTypes);
|
||||
await finder.find();
|
||||
|
||||
_file.errorsDuringDiscovery.addAll(finder.errors);
|
||||
|
|
|
@ -37,7 +37,7 @@ abstract class DriftElementResolver<T extends DiscoveredElement>
|
|||
return null;
|
||||
}
|
||||
|
||||
final knownTypes = await resolver.driver.loadKnownTypes();
|
||||
final knownTypes = resolver.driver.knownTypes;
|
||||
return readCustomType(
|
||||
knownTypes.helperLibrary,
|
||||
expression,
|
||||
|
@ -64,7 +64,7 @@ abstract class DriftElementResolver<T extends DiscoveredElement>
|
|||
return null;
|
||||
}
|
||||
|
||||
final knownTypes = await resolver.driver.loadKnownTypes();
|
||||
final knownTypes = resolver.driver.knownTypes;
|
||||
return readTypeConverter(
|
||||
knownTypes.helperLibrary,
|
||||
expression,
|
||||
|
@ -153,7 +153,7 @@ abstract class DriftElementResolver<T extends DiscoveredElement>
|
|||
innerType,
|
||||
false,
|
||||
this,
|
||||
await resolver.driver.loadKnownTypes(),
|
||||
resolver.driver.knownTypes,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -166,7 +166,7 @@ abstract class DriftElementResolver<T extends DiscoveredElement>
|
|||
));
|
||||
return null;
|
||||
} else {
|
||||
final knownTypes = await resolver.driver.loadKnownTypes();
|
||||
final knownTypes = resolver.driver.knownTypes;
|
||||
return validateExistingClass(columns, foundDartClass,
|
||||
source.constructorName ?? '', false, this, knownTypes);
|
||||
}
|
||||
|
|
|
@ -79,7 +79,6 @@ class TypeMapping {
|
|||
type = switch (column.sqlType) {
|
||||
ColumnDriftType() => type,
|
||||
ColumnCustomType(:final custom) => type.addHint(CustomTypeHint(custom)),
|
||||
ColumnGeopolyPolygonType() => type.addHint(const IsGeopolyPolygon()),
|
||||
};
|
||||
|
||||
if (column.typeConverter case AppliedTypeConverter c) {
|
||||
|
@ -151,7 +150,17 @@ class TypeMapping {
|
|||
}
|
||||
|
||||
if (type.hint<IsGeopolyPolygon>() != null) {
|
||||
return const ColumnType.geopolyPolygon();
|
||||
final knownTypes = driver.knownTypes;
|
||||
|
||||
return ColumnType.custom(
|
||||
CustomColumnType(
|
||||
AnnotatedDartCode.importedSymbol(
|
||||
Uri.parse('package:drift/extensions/geopoly.dart'),
|
||||
'const GeopolyPolygonType()',
|
||||
),
|
||||
knownTypes.geopolyPolygon,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return ColumnType.drift(_toDefaultType(type));
|
||||
|
|
|
@ -77,7 +77,7 @@ class DriftTableResolver extends DriftElementResolver<DiscoveredDriftTable> {
|
|||
type.builtin == DriftSqlType.int
|
||||
? EnumType.intEnum
|
||||
: EnumType.textEnum,
|
||||
await resolver.driver.loadKnownTypes(),
|
||||
resolver.driver.knownTypes,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ class DriftViewResolver extends DriftElementResolver<DiscoveredDriftView> {
|
|||
? null
|
||||
: await createTypeResolver(
|
||||
allReferences,
|
||||
await resolver.driver.loadKnownTypes(),
|
||||
resolver.driver.knownTypes,
|
||||
);
|
||||
|
||||
final context = engine.analyzeNode(
|
||||
|
|
|
@ -19,7 +19,7 @@ class FileAnalyzer {
|
|||
|
||||
Future<FileAnalysisResult> runAnalysisOn(FileState state) async {
|
||||
final result = FileAnalysisResult();
|
||||
final knownTypes = await driver.loadKnownTypes();
|
||||
final knownTypes = driver.knownTypes;
|
||||
|
||||
if (state.extension == '.dart') {
|
||||
for (final elementAnalysis in state.analysis.values) {
|
||||
|
|
|
@ -143,8 +143,6 @@ class AnnotatedDartCodeBuilder {
|
|||
addTopLevel(dartTypeNames[hasType.sqlType.builtin]!);
|
||||
case ColumnCustomType(:final custom):
|
||||
addDartType(custom.dartType);
|
||||
case ColumnGeopolyPolygonType(:final dartType):
|
||||
addTopLevel(dartType);
|
||||
}
|
||||
if (hasType.nullable) addText('?');
|
||||
}
|
||||
|
|
|
@ -750,7 +750,7 @@ final class ScalarResultColumn extends ResultColumn
|
|||
|
||||
int get _columnTypeCompatibilityHash {
|
||||
final custom = switch (sqlType) {
|
||||
ColumnDriftType() || ColumnGeopolyPolygonType() => null,
|
||||
ColumnDriftType() => null,
|
||||
ColumnCustomType(:final custom) => custom,
|
||||
};
|
||||
|
||||
|
|
|
@ -44,19 +44,11 @@ sealed class ColumnType {
|
|||
/// all.
|
||||
final DriftSqlType builtin;
|
||||
|
||||
/// Details about the custom type, if one is present.
|
||||
// CustomColumnType? get custom => switch (this) {
|
||||
// ColumnDriftType() || ColumnGeopolyPolygonType() => null,
|
||||
// ColumnCustomType(:final custom) => custom,
|
||||
// };
|
||||
|
||||
const ColumnType._(this.builtin);
|
||||
|
||||
const factory ColumnType.drift(DriftSqlType builtin) = ColumnDriftType;
|
||||
|
||||
const factory ColumnType.custom(CustomColumnType custom) = ColumnCustomType;
|
||||
|
||||
const factory ColumnType.geopolyPolygon() = ColumnGeopolyPolygonType;
|
||||
}
|
||||
|
||||
final class ColumnDriftType extends ColumnType {
|
||||
|
@ -69,13 +61,6 @@ final class ColumnCustomType extends ColumnType {
|
|||
const ColumnCustomType(this.custom) : super._(DriftSqlType.any);
|
||||
}
|
||||
|
||||
final class ColumnGeopolyPolygonType extends ColumnType {
|
||||
const ColumnGeopolyPolygonType() : super._(DriftSqlType.any);
|
||||
|
||||
DartTopLevelSymbol get dartType =>
|
||||
DartTopLevelSymbol('GeopolyPolygon', AnnotatedDartCode.drift);
|
||||
}
|
||||
|
||||
extension OperationOnTypes on HasType {
|
||||
bool get isUint8ListInDart {
|
||||
return sqlType.builtin == DriftSqlType.blob && typeConverter == null;
|
||||
|
|
|
@ -200,20 +200,17 @@ class ElementSerializer {
|
|||
}
|
||||
|
||||
Map<String, Object?> _serializeColumnType(ColumnType type) {
|
||||
switch (type) {
|
||||
case ColumnGeopolyPolygonType():
|
||||
case ColumnDriftType():
|
||||
return {
|
||||
return switch (type) {
|
||||
ColumnDriftType() => {
|
||||
'builtin': type.builtin.name,
|
||||
};
|
||||
case ColumnCustomType(:final custom):
|
||||
return {
|
||||
},
|
||||
ColumnCustomType(:final custom) => {
|
||||
'custom': {
|
||||
'dart': _serializeType(custom.dartType),
|
||||
'expression': custom.expression.toJson(),
|
||||
}
|
||||
};
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
Map<String, Object?> _serializeColumn(DriftColumn column) {
|
||||
|
|
|
@ -46,11 +46,11 @@ class AnalysisContextBackend extends DriftBackend {
|
|||
|
||||
AnalysisContextBackend(this.context, this.provider);
|
||||
|
||||
static PhysicalDriftDriver createDriver({
|
||||
static Future<PhysicalDriftDriver> createDriver({
|
||||
DriftOptions options = const DriftOptions.defaults(),
|
||||
ResourceProvider? resourceProvider,
|
||||
required String projectDirectory,
|
||||
}) {
|
||||
}) async {
|
||||
final underlyingProvider =
|
||||
resourceProvider ?? PhysicalResourceProvider.INSTANCE;
|
||||
final provider = OverlayResourceProvider(underlyingProvider);
|
||||
|
@ -62,7 +62,7 @@ class AnalysisContextBackend extends DriftBackend {
|
|||
final context = contextCollection.contextFor(projectDirectory);
|
||||
|
||||
final backend = AnalysisContextBackend(context, provider);
|
||||
final driver = DriftAnalysisDriver(backend, options);
|
||||
final driver = await DriftAnalysisDriver.init(backend, options);
|
||||
return PhysicalDriftDriver(driver, backend);
|
||||
}
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ class DriftDiscover extends Builder {
|
|||
@override
|
||||
Future<void> build(BuildStep buildStep) async {
|
||||
final backend = DriftBuildBackend(buildStep);
|
||||
final driver = DriftAnalysisDriver(backend, options);
|
||||
final driver = await DriftAnalysisDriver.init(backend, options);
|
||||
|
||||
final prepared = await driver.findLocalElements(buildStep.inputId.uri);
|
||||
final discovery = prepared.discovery;
|
||||
|
@ -84,7 +84,7 @@ class DriftAnalyzer extends Builder {
|
|||
@override
|
||||
Future<void> build(BuildStep buildStep) async {
|
||||
final backend = DriftBuildBackend(buildStep);
|
||||
final driver = DriftAnalysisDriver(backend, options)
|
||||
final driver = await DriftAnalysisDriver.init(backend, options)
|
||||
..cacheReader =
|
||||
BuildCacheReader(buildStep, findsLocalElementsReliably: true);
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import 'package:build/build.dart';
|
||||
import 'package:dart_style/dart_style.dart';
|
||||
import 'package:meta/meta.dart';
|
||||
import 'package:pub_semver/pub_semver.dart';
|
||||
|
||||
import '../../analysis/custom_result_class.dart';
|
||||
|
@ -102,7 +103,7 @@ class DriftBuilder extends Builder {
|
|||
|
||||
@override
|
||||
Future<void> build(BuildStep buildStep) async {
|
||||
final run = _DriftBuildRun(options, generationMode, buildStep);
|
||||
final run = await _DriftBuildRun.init(options, generationMode, buildStep);
|
||||
await run.run();
|
||||
}
|
||||
}
|
||||
|
@ -133,18 +134,31 @@ class _DriftBuildRun {
|
|||
Set<Uri> analyzedUris = {};
|
||||
bool _didPrintWarning = false;
|
||||
|
||||
_DriftBuildRun(this.options, this.mode, this.buildStep)
|
||||
: driver = DriftAnalysisDriver(DriftBuildBackend(buildStep), options)
|
||||
..cacheReader = BuildCacheReader(
|
||||
buildStep,
|
||||
// The discovery and analyzer builders will have emitted IR for
|
||||
// every relevant file in a previous build step that this builder
|
||||
// has a dependency on.
|
||||
findsResolvedElementsReliably:
|
||||
!mode.embeddedAnalyzer || options.hasDriftAnalyzer,
|
||||
findsLocalElementsReliably:
|
||||
!mode.embeddedAnalyzer || options.hasDriftAnalyzer,
|
||||
);
|
||||
@visibleForTesting
|
||||
_DriftBuildRun(this.options, this.mode, this.buildStep, this.driver);
|
||||
|
||||
static Future<_DriftBuildRun> init(
|
||||
DriftOptions options,
|
||||
DriftGenerationMode mode,
|
||||
BuildStep buildStep,
|
||||
) async {
|
||||
return _DriftBuildRun(
|
||||
options,
|
||||
mode,
|
||||
buildStep,
|
||||
await DriftAnalysisDriver.init(DriftBuildBackend(buildStep), options)
|
||||
..cacheReader = BuildCacheReader(
|
||||
buildStep,
|
||||
// The discovery and analyzer builders will have emitted IR for
|
||||
// every relevant file in a previous build step that this builder
|
||||
// has a dependency on.
|
||||
findsResolvedElementsReliably:
|
||||
!mode.embeddedAnalyzer || options.hasDriftAnalyzer,
|
||||
findsLocalElementsReliably:
|
||||
!mode.embeddedAnalyzer || options.hasDriftAnalyzer,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> run() async {
|
||||
await _warnAboutDeprecatedOptions();
|
||||
|
|
|
@ -21,7 +21,7 @@ Future<List<DriftElement>> extractDriftElementsFromDatabase(
|
|||
final logger = Logger('extractDriftElementsFromDatabase');
|
||||
final uri = Uri.parse('db.drift');
|
||||
final backend = _SingleFileNoAnalyzerBackend(logger, uri);
|
||||
final driver = DriftAnalysisDriver(
|
||||
final driver = await DriftAnalysisDriver.init(
|
||||
backend,
|
||||
DriftOptions.defaults(
|
||||
sqliteAnalysisOptions: SqliteAnalysisOptions(
|
||||
|
|
|
@ -209,7 +209,6 @@ class QueryWriter {
|
|||
String code;
|
||||
|
||||
switch (column.sqlType) {
|
||||
case ColumnGeopolyPolygonType():
|
||||
case ColumnDriftType():
|
||||
final method = isNullable ? 'readNullable' : 'read';
|
||||
code = 'row.$method<$rawDartType>($dartLiteral)';
|
||||
|
|
|
@ -345,7 +345,6 @@ class RowMappingWriter {
|
|||
final String sqlType;
|
||||
switch (column.sqlType) {
|
||||
case ColumnDriftType():
|
||||
case ColumnGeopolyPolygonType():
|
||||
sqlType = writer.drift(column.sqlType.builtin.toString());
|
||||
case ColumnCustomType(:final custom):
|
||||
sqlType = writer.dartCode(custom.expression);
|
||||
|
|
|
@ -213,7 +213,6 @@ abstract class TableOrViewWriter {
|
|||
|
||||
switch (column.sqlType) {
|
||||
case ColumnDriftType():
|
||||
case ColumnGeopolyPolygonType():
|
||||
additionalParams['type'] =
|
||||
emitter.drift(column.sqlType.builtin.toString());
|
||||
case ColumnCustomType(:final custom):
|
||||
|
|
|
@ -147,7 +147,6 @@ abstract class _NodeOrWriter {
|
|||
|
||||
switch (converter.sqlType) {
|
||||
case ColumnDriftType():
|
||||
case ColumnGeopolyPolygonType():
|
||||
sqlDartType =
|
||||
AnnotatedDartCode([dartTypeNames[converter.sqlType.builtin]!]);
|
||||
case ColumnCustomType(:final custom):
|
||||
|
@ -209,8 +208,6 @@ abstract class _NodeOrWriter {
|
|||
AnnotatedDartCode innerColumnType(ColumnType type, {bool nullable = false}) {
|
||||
return AnnotatedDartCode.build((b) {
|
||||
switch (type) {
|
||||
case ColumnGeopolyPolygonType(:final dartType):
|
||||
b.addTopLevel(dartType);
|
||||
case ColumnDriftType():
|
||||
b.addTopLevel(dartTypeNames[type.builtin]!);
|
||||
case ColumnCustomType(:final custom):
|
||||
|
@ -247,7 +244,6 @@ abstract class _NodeOrWriter {
|
|||
|
||||
switch (column.sqlType) {
|
||||
case ColumnDriftType():
|
||||
case ColumnGeopolyPolygonType():
|
||||
break;
|
||||
case ColumnCustomType(:final custom):
|
||||
// Also specify the custom type since it can't be inferred from the
|
||||
|
|
|
@ -8,7 +8,7 @@ import 'test_utils.dart';
|
|||
|
||||
void main() {
|
||||
test('handles cyclic imports', () async {
|
||||
final state = TestBackend.inTest({
|
||||
final state = await TestBackend.inTest({
|
||||
'a|lib/entry.dart': '''
|
||||
import 'package:drift/drift.dart';
|
||||
|
||||
|
@ -42,7 +42,7 @@ CREATE TABLE bars (
|
|||
group("reports error when an import can't be found", () {
|
||||
for (final extension in const ['drift', 'moor']) {
|
||||
test('in $extension files', () async {
|
||||
final backend = TestBackend.inTest({
|
||||
final backend = await TestBackend.inTest({
|
||||
'a|lib/a.$extension': '''
|
||||
import 'b.$extension';
|
||||
''',
|
||||
|
@ -56,7 +56,7 @@ import 'b.$extension';
|
|||
}
|
||||
|
||||
test('in a dart file', () async {
|
||||
final backend = TestBackend.inTest({
|
||||
final backend = await TestBackend.inTest({
|
||||
'a|lib/a.dart': '''
|
||||
import 'package:drift/drift.dart';
|
||||
|
||||
|
@ -74,7 +74,7 @@ class Database {
|
|||
});
|
||||
|
||||
test('resolves tables and queries', () async {
|
||||
final backend = TestBackend.inTest({
|
||||
final backend = await TestBackend.inTest({
|
||||
'a|lib/database.dart': r'''
|
||||
import 'package:drift/drift.dart';
|
||||
|
||||
|
@ -178,7 +178,7 @@ class ProgrammingLanguages extends Table {
|
|||
});
|
||||
|
||||
test('still supports .moor files', () async {
|
||||
final state = TestBackend.inTest({
|
||||
final state = await TestBackend.inTest({
|
||||
'a|lib/main.dart': '''
|
||||
import 'package:drift/drift.dart';
|
||||
|
||||
|
@ -203,7 +203,7 @@ CREATE TABLE users (
|
|||
});
|
||||
|
||||
test('supports multiple references between same entities', () async {
|
||||
final state = TestBackend.inTest({
|
||||
final state = await TestBackend.inTest({
|
||||
'a|lib/a.dart': '''
|
||||
import 'package:drift/drift.dart';
|
||||
|
||||
|
@ -231,7 +231,7 @@ class ThisTable extends Table {
|
|||
});
|
||||
|
||||
test('supports references across files', () async {
|
||||
final state = TestBackend.inTest({
|
||||
final state = await TestBackend.inTest({
|
||||
'a|lib/this_table.dart': '''
|
||||
import 'package:drift/drift.dart';
|
||||
|
||||
|
@ -272,7 +272,7 @@ class OtherTable extends Table {
|
|||
});
|
||||
|
||||
test('reports sensible error for missing table', () async {
|
||||
final state = TestBackend.inTest({
|
||||
final state = await TestBackend.inTest({
|
||||
'a|lib/a.drift': '''
|
||||
getCompanyCustomersCount:
|
||||
SELECT COUNT(*) AS "count"
|
||||
|
|
|
@ -75,7 +75,7 @@ sqlite:
|
|||
});
|
||||
|
||||
test('reports error about table when module is not imported', () async {
|
||||
final backend = TestBackend.inTest({
|
||||
final backend = await TestBackend.inTest({
|
||||
'a|lib/a.drift': 'CREATE VIRTUAL TABLE place_spellfix USING spellfix1;',
|
||||
});
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ import 'test_utils.dart';
|
|||
|
||||
void main() {
|
||||
test('finds dart expressions', () async {
|
||||
final backend = TestBackend.inTest({
|
||||
final backend = await TestBackend.inTest({
|
||||
'a|lib/main.drift': '''
|
||||
import 'foo.dart';
|
||||
|
||||
|
@ -26,7 +26,7 @@ var expr_0 = const MyConverter();
|
|||
|
||||
test('only includes direct imports if no Dart expressions are used',
|
||||
() async {
|
||||
final backend = TestBackend.inTest({
|
||||
final backend = await TestBackend.inTest({
|
||||
'a|lib/main.drift': '''
|
||||
import 'foo.dart';
|
||||
import '2.drift';
|
||||
|
@ -48,7 +48,7 @@ import 'bar.dart';
|
|||
});
|
||||
|
||||
test('finds nested dart imports', () async {
|
||||
final backend = TestBackend.inTest({
|
||||
final backend = await TestBackend.inTest({
|
||||
'a|lib/a.drift': '''
|
||||
import 'b.drift';
|
||||
|
||||
|
@ -72,7 +72,7 @@ import 'import.dart';
|
|||
});
|
||||
|
||||
test('does not throw for invalid import', () async {
|
||||
final backend = TestBackend.inTest({
|
||||
final backend = await TestBackend.inTest({
|
||||
'a|lib/a.drift': '''
|
||||
import 'b.drift';
|
||||
import 'does_not_exist.drift';
|
||||
|
@ -96,8 +96,8 @@ import 'c.drift';
|
|||
expect(result.temporaryDartFile, isNot(contains('import')));
|
||||
});
|
||||
|
||||
test('throws if entrypoint does not exist', () {
|
||||
final backend = TestBackend.inTest({});
|
||||
test('throws if entrypoint does not exist', () async {
|
||||
final backend = await TestBackend.inTest({});
|
||||
|
||||
expect(
|
||||
() =>
|
||||
|
@ -106,8 +106,8 @@ import 'c.drift';
|
|||
);
|
||||
});
|
||||
|
||||
test('throws if entrypoint is invalid', () {
|
||||
final backend = TestBackend.inTest({
|
||||
test('throws if entrypoint is invalid', () async {
|
||||
final backend = await TestBackend.inTest({
|
||||
'a|lib/main.drift': '! this not a valid drift file !',
|
||||
});
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ import 'test_utils.dart';
|
|||
|
||||
void main() {
|
||||
test('analyzes views referencing Dart tables', () async {
|
||||
final state = TestBackend.inTest({
|
||||
final state = await TestBackend.inTest({
|
||||
'a|lib/db.dart': '''
|
||||
import 'package:drift/drift.dart';
|
||||
import 'dart:io';
|
||||
|
|
|
@ -5,7 +5,7 @@ import 'test_utils.dart';
|
|||
|
||||
void main() {
|
||||
test('gracefully handles daos with invalid types', () async {
|
||||
final state = TestBackend.inTest({
|
||||
final state = await TestBackend.inTest({
|
||||
'a|lib/bar.dart': '''
|
||||
import 'package:drift/drift.dart';
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ import '../../test_utils.dart';
|
|||
void main() {
|
||||
group('reports a warning', () {
|
||||
test('when the table is not a class type', () async {
|
||||
final state = TestBackend.inTest(
|
||||
final state = await TestBackend.inTest(
|
||||
{
|
||||
'a|lib/main.dart': '''
|
||||
import 'package:drift/drift.dart';
|
||||
|
@ -26,7 +26,7 @@ class Foo extends Table {
|
|||
});
|
||||
|
||||
test('when the column is not a symbol literal', () async {
|
||||
final state = TestBackend.inTest(
|
||||
final state = await TestBackend.inTest(
|
||||
{
|
||||
'a|lib/main.dart': '''
|
||||
import 'package:drift/drift.dart';
|
||||
|
@ -48,7 +48,7 @@ class Foo extends Table {
|
|||
});
|
||||
|
||||
test('includes referenced table in database', () async {
|
||||
final state = TestBackend.inTest(
|
||||
final state = await TestBackend.inTest(
|
||||
{
|
||||
'a|lib/main.dart': '''
|
||||
import 'package:drift/drift.dart';
|
||||
|
@ -78,7 +78,7 @@ class Database {}
|
|||
});
|
||||
|
||||
test('when the referenced column does not exist', () async {
|
||||
final state = TestBackend.inTest(
|
||||
final state = await TestBackend.inTest(
|
||||
{
|
||||
'a|lib/main.dart': '''
|
||||
import 'package:drift/drift.dart';
|
||||
|
@ -106,7 +106,7 @@ class Database {}
|
|||
});
|
||||
|
||||
test('resolves reference', () async {
|
||||
final state = TestBackend.inTest(
|
||||
final state = await TestBackend.inTest(
|
||||
{
|
||||
'a|lib/main.dart': '''
|
||||
import 'package:drift/drift.dart';
|
||||
|
@ -149,7 +149,7 @@ class Database {}
|
|||
});
|
||||
|
||||
test('resolves self-references', () async {
|
||||
final state = TestBackend.inTest(
|
||||
final state = await TestBackend.inTest(
|
||||
{
|
||||
'a|lib/main.dart': '''
|
||||
import 'package:drift/drift.dart';
|
||||
|
|
|
@ -9,7 +9,7 @@ void main() {
|
|||
test(
|
||||
'It should rename the table and column name to its snake case version by default',
|
||||
() async {
|
||||
final state = TestBackend.inTest(
|
||||
final state = await TestBackend.inTest(
|
||||
{
|
||||
'a|lib/main.dart': '''
|
||||
import 'package:drift/drift.dart';
|
||||
|
@ -36,7 +36,7 @@ class Database {}
|
|||
|
||||
test('It should rename the table and column name to its snake case version',
|
||||
() async {
|
||||
final state = TestBackend.inTest(
|
||||
final state = await TestBackend.inTest(
|
||||
{
|
||||
'a|lib/main.dart': '''
|
||||
import 'package:drift/drift.dart';
|
||||
|
@ -64,7 +64,7 @@ class Database {}
|
|||
});
|
||||
|
||||
test('It should not rename the table and column name', () async {
|
||||
final state = TestBackend.inTest(
|
||||
final state = await TestBackend.inTest(
|
||||
{
|
||||
'a|lib/main.dart': '''
|
||||
import 'package:drift/drift.dart';
|
||||
|
@ -93,7 +93,7 @@ class Database {}
|
|||
});
|
||||
test('It should rename the table and column name to its camel case version',
|
||||
() async {
|
||||
final state = TestBackend.inTest(
|
||||
final state = await TestBackend.inTest(
|
||||
{
|
||||
'a|lib/main.dart': '''
|
||||
import 'package:drift/drift.dart';
|
||||
|
@ -122,7 +122,7 @@ class Database {}
|
|||
test(
|
||||
'It should rename the table and column name to its constant case version',
|
||||
() async {
|
||||
final state = TestBackend.inTest(
|
||||
final state = await TestBackend.inTest(
|
||||
{
|
||||
'a|lib/main.dart': '''
|
||||
import 'package:drift/drift.dart';
|
||||
|
@ -150,7 +150,7 @@ class Database {}
|
|||
});
|
||||
test('It should rename the table and column name to its pascal case version',
|
||||
() async {
|
||||
final state = TestBackend.inTest(
|
||||
final state = await TestBackend.inTest(
|
||||
{
|
||||
'a|lib/main.dart': '''
|
||||
import 'package:drift/drift.dart';
|
||||
|
@ -178,7 +178,7 @@ class Database {}
|
|||
});
|
||||
test('It should rename the table and column name to its lower case version',
|
||||
() async {
|
||||
final state = TestBackend.inTest(
|
||||
final state = await TestBackend.inTest(
|
||||
{
|
||||
'a|lib/main.dart': '''
|
||||
import 'package:drift/drift.dart';
|
||||
|
@ -207,7 +207,7 @@ class Database {}
|
|||
});
|
||||
test('It should rename the table and column name to its upper case version',
|
||||
() async {
|
||||
final state = TestBackend.inTest(
|
||||
final state = await TestBackend.inTest(
|
||||
{
|
||||
'a|lib/main.dart': '''
|
||||
import 'package:drift/drift.dart';
|
||||
|
@ -235,7 +235,7 @@ class Database {}
|
|||
});
|
||||
|
||||
test('recognizes custom column types', () async {
|
||||
final state = TestBackend.inTest({
|
||||
final state = await TestBackend.inTest({
|
||||
'a|lib/main.dart': '''
|
||||
import 'package:drift/drift.dart';
|
||||
|
||||
|
@ -256,7 +256,6 @@ class TestTable extends Table {
|
|||
expect(column.sqlType.builtin, DriftSqlType.any);
|
||||
switch (column.sqlType) {
|
||||
case ColumnDriftType():
|
||||
case ColumnGeopolyPolygonType():
|
||||
break;
|
||||
case ColumnCustomType(:final custom):
|
||||
expect(custom.dartType.toString(), 'List<String>');
|
||||
|
@ -266,7 +265,7 @@ class TestTable extends Table {
|
|||
|
||||
group('customConstraint analysis', () {
|
||||
test('reports errors', () async {
|
||||
final state = TestBackend.inTest({
|
||||
final state = await TestBackend.inTest({
|
||||
'a|lib/a.dart': '''
|
||||
import 'package:drift/drift.dart';
|
||||
|
||||
|
@ -285,7 +284,7 @@ class TestTable extends Table {
|
|||
});
|
||||
|
||||
test('resolves foreign key references', () async {
|
||||
final state = TestBackend.inTest({
|
||||
final state = await TestBackend.inTest({
|
||||
'a|lib/a.dart': '''
|
||||
import 'package:drift/drift.dart';
|
||||
|
||||
|
@ -326,7 +325,7 @@ class TestTable extends Table {
|
|||
});
|
||||
|
||||
test('warns about missing `NOT NULL`', () async {
|
||||
final state = TestBackend.inTest({
|
||||
final state = await TestBackend.inTest({
|
||||
'a|lib/a.dart': '''
|
||||
import 'package:drift/drift.dart';
|
||||
|
||||
|
@ -345,7 +344,7 @@ class TestTable extends Table {
|
|||
});
|
||||
|
||||
test('applies constraints', () async {
|
||||
final state = TestBackend.inTest({
|
||||
final state = await TestBackend.inTest({
|
||||
'a|lib/a.dart': '''
|
||||
import 'package:drift/drift.dart';
|
||||
|
||||
|
|
|
@ -7,8 +7,8 @@ import '../../test_utils.dart';
|
|||
void main() {
|
||||
late TestBackend state;
|
||||
|
||||
setUpAll(() {
|
||||
state = TestBackend(const {
|
||||
setUpAll(() async {
|
||||
state = await TestBackend.init(const {
|
||||
'a|lib/invalid_no_unnamed_constructor.dart': '''
|
||||
import 'package:drift/drift.dart';
|
||||
|
||||
|
@ -408,7 +408,7 @@ class Companies extends Table {
|
|||
});
|
||||
|
||||
test('handles `ANY` columns', () async {
|
||||
final backend = TestBackend.inTest({
|
||||
final backend = await TestBackend.inTest({
|
||||
'a|lib/a.drift': '''
|
||||
import 'row.dart';
|
||||
|
||||
|
@ -528,7 +528,7 @@ class FooData {
|
|||
|
||||
group('records as row types', () {
|
||||
test('supported with explicit record', () async {
|
||||
final state = TestBackend.inTest(
|
||||
final state = await TestBackend.inTest(
|
||||
{
|
||||
'a|lib/a.dart': '''
|
||||
import 'package:drift/drift.dart';
|
||||
|
@ -562,7 +562,7 @@ class Users extends Table {
|
|||
});
|
||||
|
||||
test('supported with implicit record', () async {
|
||||
final state = TestBackend.inTest(
|
||||
final state = await TestBackend.inTest(
|
||||
{
|
||||
'a|lib/a.dart': '''
|
||||
import 'package:drift/drift.dart';
|
||||
|
|
|
@ -7,7 +7,7 @@ void main() {
|
|||
final mainUri = Uri.parse('package:a/main.dart');
|
||||
|
||||
test('parses schema version getter', () async {
|
||||
final backend = TestBackend.inTest({
|
||||
final backend = await TestBackend.inTest({
|
||||
'a|lib/main.dart': r'''
|
||||
import 'package:drift/drift.dart';
|
||||
|
||||
|
@ -27,7 +27,7 @@ class MyDatabase extends _$MyDatabase {
|
|||
});
|
||||
|
||||
test('parses schema version field', () async {
|
||||
final backend = TestBackend.inTest({
|
||||
final backend = await TestBackend.inTest({
|
||||
'a|lib/main.dart': r'''
|
||||
import 'package:drift/drift.dart';
|
||||
|
||||
|
@ -47,7 +47,7 @@ class MyDatabase extends _$MyDatabase {
|
|||
});
|
||||
|
||||
test('does not warn about missing tables parameter', () async {
|
||||
final backend = TestBackend.inTest({
|
||||
final backend = await TestBackend.inTest({
|
||||
'a|lib/main.dart': r'''
|
||||
import 'package:drift/drift.dart';
|
||||
|
||||
|
@ -69,7 +69,7 @@ class MyDatabase2 extends _$MyDatabase {
|
|||
});
|
||||
|
||||
test('supports inheritance for daos', () async {
|
||||
final state = TestBackend.inTest({
|
||||
final state = await TestBackend.inTest({
|
||||
'a|lib/database.dart': r'''
|
||||
import 'package:drift/drift.dart';
|
||||
|
||||
|
@ -115,7 +115,7 @@ class ProductsDao extends BaseProductsDao with _$ProductDaoMixin {
|
|||
});
|
||||
|
||||
test('only includes duplicate elements once', () async {
|
||||
final state = TestBackend.inTest({
|
||||
final state = await TestBackend.inTest({
|
||||
'a|lib/main.dart': '''
|
||||
import 'package:drift/drift.dart';
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ void main() {
|
|||
late TestBackend backend;
|
||||
|
||||
setUpAll(() async {
|
||||
backend = TestBackend({
|
||||
backend = await TestBackend.init({
|
||||
'a|lib/main.dart': '''
|
||||
import 'package:drift/drift.dart';
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ import '../../test_utils.dart';
|
|||
void main() {
|
||||
group('reports a warning', () {
|
||||
test('when the table is not a class type', () async {
|
||||
final backend = TestBackend.inTest({
|
||||
final backend = await TestBackend.inTest({
|
||||
'a|lib/main.dart': '''
|
||||
import 'package:drift/drift.dart';
|
||||
|
||||
|
@ -29,7 +29,7 @@ class Foo extends Table {
|
|||
});
|
||||
|
||||
test('when the table is not a symbol literal', () async {
|
||||
final backend = TestBackend.inTest({
|
||||
final backend = await TestBackend.inTest({
|
||||
'a|lib/main.dart': '''
|
||||
import 'package:drift/drift.dart';
|
||||
|
||||
|
@ -54,7 +54,7 @@ class Foo extends Table {
|
|||
});
|
||||
|
||||
test('when the referenced table does not exist', () async {
|
||||
final backend = TestBackend.inTest({
|
||||
final backend = await TestBackend.inTest({
|
||||
'a|lib/main.dart': '''
|
||||
import 'package:drift/drift.dart';
|
||||
|
||||
|
@ -83,7 +83,7 @@ class Foo extends Table {
|
|||
});
|
||||
|
||||
test('resolves reference', () async {
|
||||
final backend = TestBackend.inTest({
|
||||
final backend = await TestBackend.inTest({
|
||||
'a|lib/main.dart': '''
|
||||
import 'package:drift/drift.dart';
|
||||
|
||||
|
@ -116,7 +116,7 @@ class Foo extends Table {
|
|||
});
|
||||
|
||||
test('resolves self-references', () async {
|
||||
final backend = TestBackend.inTest({
|
||||
final backend = await TestBackend.inTest({
|
||||
'a|lib/main.dart': '''
|
||||
import 'package:drift/drift.dart';
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ import '../../test_utils.dart';
|
|||
|
||||
void main() {
|
||||
test('resolves index', () async {
|
||||
final backend = TestBackend.inTest({
|
||||
final backend = await TestBackend.inTest({
|
||||
'a|lib/a.dart': '''
|
||||
import 'package:drift/drift.dart';
|
||||
|
||||
|
@ -41,7 +41,7 @@ class MyTable extends Table {
|
|||
});
|
||||
|
||||
test('warns about missing columns', () async {
|
||||
final backend = TestBackend.inTest({
|
||||
final backend = await TestBackend.inTest({
|
||||
'a|lib/a.dart': '''
|
||||
import 'package:drift/drift.dart';
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ import '../../test_utils.dart';
|
|||
|
||||
void main() {
|
||||
test('warns about invalid column', () async {
|
||||
final backend = TestBackend.inTest({
|
||||
final backend = await TestBackend.inTest({
|
||||
'a|lib/main.dart': '''
|
||||
import 'package:drift/drift.dart';
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ import '../../test_utils.dart';
|
|||
|
||||
void main() {
|
||||
test('can define abstract tables', () async {
|
||||
final test = TestBackend.inTest({
|
||||
final test = await TestBackend.inTest({
|
||||
'a|lib/main.dart': '''
|
||||
import 'package:drift/drift.dart';
|
||||
|
||||
|
|
|
@ -11,8 +11,8 @@ void main() {
|
|||
late TestBackend backend;
|
||||
late FileState state;
|
||||
|
||||
setUpAll(() {
|
||||
backend = TestBackend({
|
||||
setUpAll(() async {
|
||||
backend = await TestBackend.init({
|
||||
'a|lib/main.dart': r'''
|
||||
import 'package:drift/drift.dart';
|
||||
|
||||
|
|
|
@ -8,8 +8,8 @@ import '../../test_utils.dart';
|
|||
void main() {
|
||||
late TestBackend backend;
|
||||
|
||||
setUpAll(() {
|
||||
backend = TestBackend({
|
||||
setUpAll(() async {
|
||||
backend = await TestBackend.init({
|
||||
'a|lib/main.dart': '''
|
||||
import 'package:drift/drift.dart';
|
||||
|
||||
|
@ -335,7 +335,7 @@ class Pianos extends Table {
|
|||
});
|
||||
|
||||
test('reads custom constraints from table', () async {
|
||||
final backend = TestBackend.inTest({
|
||||
final backend = await TestBackend.inTest({
|
||||
'a|lib/a.dart': '''
|
||||
import 'package:drift/drift.dart';
|
||||
|
||||
|
@ -377,7 +377,7 @@ class WithConstraints extends Table {
|
|||
});
|
||||
|
||||
test('warns about foreign key references from customConstraints', () async {
|
||||
final backend = TestBackend.inTest({
|
||||
final backend = await TestBackend.inTest({
|
||||
'a|lib/a.dart': '''
|
||||
import 'package:drift/drift.dart';
|
||||
|
||||
|
@ -410,7 +410,7 @@ class WithConstraints extends Table {
|
|||
});
|
||||
|
||||
test('can resolve references from import', () async {
|
||||
final backend = TestBackend.inTest({
|
||||
final backend = await TestBackend.inTest({
|
||||
'a|lib/topic.dart': '''
|
||||
import 'package:drift/drift.dart';
|
||||
|
||||
|
@ -452,7 +452,7 @@ class Videos extends Table {
|
|||
});
|
||||
|
||||
test('supports autoIncrement on int64 columns', () async {
|
||||
final backend = TestBackend.inTest({
|
||||
final backend = await TestBackend.inTest({
|
||||
'a|lib/a.dart': '''
|
||||
import 'package:drift/drift.dart';
|
||||
|
||||
|
|
|
@ -6,8 +6,8 @@ import '../../test_utils.dart';
|
|||
void main() {
|
||||
late TestBackend state;
|
||||
|
||||
setUp(() {
|
||||
state = TestBackend({
|
||||
setUp(() async {
|
||||
state = await TestBackend.init({
|
||||
'a|lib/json.dart': '''
|
||||
import 'package:drift/drift.dart';
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ void main() {
|
|||
final mainUri = Uri.parse('package:a/main.dart');
|
||||
|
||||
test('does not allow autoIncrement() to have a unique constraint', () async {
|
||||
final backend = TestBackend.inTest({
|
||||
final backend = await TestBackend.inTest({
|
||||
'a|lib/main.dart': '''
|
||||
import 'package:drift/drift.dart';
|
||||
|
||||
|
@ -29,7 +29,7 @@ class Test extends Table {
|
|||
});
|
||||
|
||||
test('does not allow primary key to have a unique constraint', () async {
|
||||
final backend = TestBackend.inTest({
|
||||
final backend = await TestBackend.inTest({
|
||||
'a|lib/main.dart': '''
|
||||
import 'package:drift/drift.dart';
|
||||
|
||||
|
@ -55,7 +55,7 @@ class Test extends Table {
|
|||
test(
|
||||
'does not allow primary key to have a unique constraint through override',
|
||||
() async {
|
||||
final backend = TestBackend.inTest({
|
||||
final backend = await TestBackend.inTest({
|
||||
'a|lib/main.dart': '''
|
||||
import 'package:drift/drift.dart';
|
||||
|
||||
|
@ -84,7 +84,7 @@ class Test extends Table {
|
|||
});
|
||||
|
||||
test('warns about duplicate unique declarations', () async {
|
||||
final backend = TestBackend.inTest({
|
||||
final backend = await TestBackend.inTest({
|
||||
'a|lib/main.dart': '''
|
||||
import 'package:drift/drift.dart';
|
||||
|
||||
|
@ -108,7 +108,7 @@ class Test extends Table {
|
|||
});
|
||||
|
||||
test('parses unique key definitions', () async {
|
||||
final backend = TestBackend.inTest({
|
||||
final backend = await TestBackend.inTest({
|
||||
'a|lib/main.dart': '''
|
||||
import 'package:drift/drift.dart';
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ import '../../test_utils.dart';
|
|||
|
||||
void main() {
|
||||
test('can analyze Dart view', () async {
|
||||
final backend = TestBackend.inTest({
|
||||
final backend = await TestBackend.inTest({
|
||||
'a|lib/main.dart': '''
|
||||
import 'package:drift/drift.dart';
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ import '../test_utils.dart';
|
|||
void main() {
|
||||
group('drift files', () {
|
||||
test('finds local elements', () async {
|
||||
final backend = TestBackend.inTest({
|
||||
final backend = await TestBackend.inTest({
|
||||
'a|lib/main.drift': '''
|
||||
CREATE TABLE foo (bar INTEGER);
|
||||
|
||||
|
@ -41,7 +41,7 @@ CREATE VIEW my_view AS SELECT whatever FROM unknown_table;
|
|||
});
|
||||
|
||||
test('reports syntax errors', () async {
|
||||
final backend = TestBackend.inTest({
|
||||
final backend = await TestBackend.inTest({
|
||||
'a|lib/main.drift': '''
|
||||
CREATE TABLE valid_1 (bar INTEGER);
|
||||
|
||||
|
@ -64,7 +64,7 @@ CREATE TABLE valid_2 (bar INTEGER);
|
|||
});
|
||||
|
||||
test('warns about duplicate elements', () async {
|
||||
final backend = TestBackend.inTest({
|
||||
final backend = await TestBackend.inTest({
|
||||
'a|lib/main.drift': '''
|
||||
CREATE TABLE a (id INTEGER);
|
||||
CREATE VIEW a AS VALUES(1,2,3);
|
||||
|
@ -82,7 +82,7 @@ CREATE VIEW a AS VALUES(1,2,3);
|
|||
|
||||
group('imports', () {
|
||||
test('are resolved', () async {
|
||||
final backend = TestBackend.inTest({
|
||||
final backend = await TestBackend.inTest({
|
||||
'a|lib/a.drift': "import 'b.drift';",
|
||||
'a|lib/b.drift': "CREATE TABLE foo (bar INTEGER);",
|
||||
});
|
||||
|
@ -106,7 +106,7 @@ CREATE VIEW a AS VALUES(1,2,3);
|
|||
});
|
||||
|
||||
test('can handle circular imports', () async {
|
||||
final backend = TestBackend.inTest({
|
||||
final backend = await TestBackend.inTest({
|
||||
'a|lib/a.drift': "import 'a.drift'; import 'b.drift';",
|
||||
'a|lib/b.drift': "import 'a.drift';",
|
||||
});
|
||||
|
@ -119,7 +119,7 @@ CREATE VIEW a AS VALUES(1,2,3);
|
|||
|
||||
group('dart files', () {
|
||||
test('fails for part files', () async {
|
||||
final backend = TestBackend.inTest({
|
||||
final backend = await TestBackend.inTest({
|
||||
'a|lib/a.dart': '''
|
||||
part of 'b.dart';
|
||||
''',
|
||||
|
@ -136,7 +136,7 @@ part 'a.dart';
|
|||
});
|
||||
|
||||
test('finds tables', () async {
|
||||
final backend = TestBackend.inTest({
|
||||
final backend = await TestBackend.inTest({
|
||||
'a|lib/a.dart': '''
|
||||
import 'package:drift/drift.dart';
|
||||
|
||||
|
@ -172,7 +172,7 @@ class Groups extends Table {
|
|||
});
|
||||
|
||||
test('ignores abstract tables', () async {
|
||||
final backend = TestBackend.inTest({
|
||||
final backend = await TestBackend.inTest({
|
||||
'a|lib/a.dart': '''
|
||||
import 'package:drift/drift.dart';
|
||||
|
||||
|
@ -208,7 +208,7 @@ abstract class BaseRelationTable extends Table {
|
|||
});
|
||||
|
||||
test('table name errors', () async {
|
||||
final backend = TestBackend.inTest({
|
||||
final backend = await TestBackend.inTest({
|
||||
'a|lib/expr.dart': '''
|
||||
import 'package:drift/drift.dart';
|
||||
|
||||
|
@ -239,7 +239,7 @@ class InvalidGetter extends Table {
|
|||
});
|
||||
|
||||
test('warns about duplicate elements', () async {
|
||||
final backend = TestBackend.inTest({
|
||||
final backend = await TestBackend.inTest({
|
||||
'a|lib/a.dart': '''
|
||||
import 'package:drift/drift.dart';
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ import '../../test_utils.dart';
|
|||
|
||||
void main() {
|
||||
test('view created', () async {
|
||||
final state = TestBackend.inTest({
|
||||
final state = await TestBackend.inTest({
|
||||
'foo|lib/table.drift': '''
|
||||
CREATE TABLE t (id INTEGER NOT NULL PRIMARY KEY, name TEXT NOT NULL);
|
||||
''',
|
||||
|
@ -34,7 +34,7 @@ void main() {
|
|||
});
|
||||
|
||||
test('view created from another view', () async {
|
||||
final state = TestBackend.inTest({
|
||||
final state = await TestBackend.inTest({
|
||||
'foo|lib/table.drift': '''
|
||||
CREATE TABLE t (id INTEGER NOT NULL PRIMARY KEY, name TEXT NOT NULL);
|
||||
''',
|
||||
|
@ -68,7 +68,7 @@ void main() {
|
|||
});
|
||||
|
||||
test('view without table', () async {
|
||||
final state = TestBackend.inTest({
|
||||
final state = await TestBackend.inTest({
|
||||
'foo|lib/a.drift': '''
|
||||
CREATE VIEW random_view AS
|
||||
SELECT name FROM t WHERE id % 2 = 0;
|
||||
|
@ -82,7 +82,7 @@ void main() {
|
|||
});
|
||||
|
||||
test('does not allow nested columns', () async {
|
||||
final state = TestBackend.inTest({
|
||||
final state = await TestBackend.inTest({
|
||||
'foo|lib/a.drift': '''
|
||||
CREATE TABLE foo (bar INTEGER NOT NULL PRIMARY KEY);
|
||||
|
||||
|
@ -102,7 +102,7 @@ void main() {
|
|||
test('imported views are analyzed', () async {
|
||||
// Regression test for https://github.com/simolus3/drift/issues/1639
|
||||
|
||||
final testState = TestBackend.inTest({
|
||||
final testState = await TestBackend.inTest({
|
||||
'a|lib/imported.drift': '''
|
||||
CREATE TABLE a (
|
||||
b TEXT NOT NULL
|
||||
|
@ -124,7 +124,7 @@ query: SELECT * FROM my_view;
|
|||
});
|
||||
|
||||
test('picks valid Dart names for columns', () async {
|
||||
final testState = TestBackend.inTest({
|
||||
final testState = await TestBackend.inTest({
|
||||
'a|lib/a.drift': '''
|
||||
CREATE VIEW IF NOT EXISTS repro AS
|
||||
SELECT 1,
|
||||
|
@ -148,7 +148,7 @@ CREATE VIEW IF NOT EXISTS repro AS
|
|||
});
|
||||
|
||||
test('copies type converter from table', () async {
|
||||
final backend = TestBackend.inTest({
|
||||
final backend = await TestBackend.inTest({
|
||||
'a|lib/a.drift': '''
|
||||
import 'converter.dart';
|
||||
|
||||
|
@ -185,7 +185,7 @@ TypeConverter<Object, int> createConverter() => throw UnimplementedError();
|
|||
});
|
||||
|
||||
test('can declare type converter on view column', () async {
|
||||
final backend = TestBackend.inTest({
|
||||
final backend = await TestBackend.inTest({
|
||||
'a|lib/a.drift': '''
|
||||
import 'converter.dart';
|
||||
|
||||
|
@ -223,7 +223,7 @@ TypeConverter<Object, int> createConverter() => throw UnimplementedError();
|
|||
});
|
||||
|
||||
test('supports enum columns', () async {
|
||||
final backend = TestBackend.inTest({
|
||||
final backend = await TestBackend.inTest({
|
||||
'a|lib/a.drift': '''
|
||||
import 'enums.dart';
|
||||
|
||||
|
@ -280,7 +280,7 @@ enum MyEnum {
|
|||
String expectedSql,
|
||||
DriftOptions options,
|
||||
) async {
|
||||
final backend = TestBackend.inTest(
|
||||
final backend = await TestBackend.inTest(
|
||||
{'a|lib/a.drift': definition},
|
||||
options: options,
|
||||
);
|
||||
|
|
|
@ -6,7 +6,7 @@ import '../../test_utils.dart';
|
|||
|
||||
void main() {
|
||||
test('parse nested CTE', () async {
|
||||
final backend = TestBackend.inTest({
|
||||
final backend = await TestBackend.inTest({
|
||||
'a|lib/test.drift': '''
|
||||
test:
|
||||
SELECT
|
||||
|
@ -38,7 +38,7 @@ SELECT
|
|||
});
|
||||
|
||||
test('recognizes CTE clause', () async {
|
||||
final backend = TestBackend.inTest({
|
||||
final backend = await TestBackend.inTest({
|
||||
'a|lib/test.drift': '''
|
||||
test:
|
||||
WITH RECURSIVE
|
||||
|
@ -70,7 +70,7 @@ WITH RECURSIVE
|
|||
});
|
||||
|
||||
test('finds the underlying table when aliased through CTE', () async {
|
||||
final backend = TestBackend.inTest({
|
||||
final backend = await TestBackend.inTest({
|
||||
'a|lib/test.drift': '''
|
||||
CREATE TABLE foo (
|
||||
id INT NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||
|
|
|
@ -5,7 +5,7 @@ import '../../test_utils.dart';
|
|||
|
||||
void main() {
|
||||
test('can use existing row classes in drift files', () async {
|
||||
final state = TestBackend.inTest({
|
||||
final state = await TestBackend.inTest({
|
||||
'a|lib/db.drift': '''
|
||||
import 'rows.dart';
|
||||
|
||||
|
@ -61,7 +61,7 @@ class ExistingForView {
|
|||
});
|
||||
|
||||
test('can use generic row classes', () async {
|
||||
final state = TestBackend.inTest({
|
||||
final state = await TestBackend.inTest({
|
||||
'a|lib/generic.dart': '''
|
||||
//@dart=2.13
|
||||
typedef StringRow = GenericRow<String>;
|
||||
|
@ -105,7 +105,7 @@ CREATE TABLE drift_ints (
|
|||
|
||||
group('can use records', () {
|
||||
test('with explicit structure', () async {
|
||||
final state = TestBackend.inTest({
|
||||
final state = await TestBackend.inTest({
|
||||
'a|lib/a.drift': '''
|
||||
import 'helper.dart';
|
||||
|
||||
|
@ -135,7 +135,7 @@ typedef MyRecord = ({String foo, int? bar});
|
|||
});
|
||||
|
||||
test('implicitly', () async {
|
||||
final state = TestBackend.inTest({
|
||||
final state = await TestBackend.inTest({
|
||||
'a|lib/a.drift': '''
|
||||
CREATE TABLE foo (
|
||||
foo TEXT NOT NULL,
|
||||
|
|
|
@ -5,7 +5,7 @@ import '../../test_utils.dart';
|
|||
|
||||
void main() {
|
||||
test('reports an error when importing a part file into .drift', () async {
|
||||
final state = TestBackend.inTest({
|
||||
final state = await TestBackend.inTest({
|
||||
'a|lib/base.dart': '''
|
||||
import 'package:drift/drift.dart';
|
||||
|
||||
|
|
|
@ -84,7 +84,7 @@ void main() {
|
|||
|
||||
test('integration tests with drift files and experimental inference',
|
||||
() async {
|
||||
final state = TestBackend.inTest(
|
||||
final state = await TestBackend.inTest(
|
||||
const {
|
||||
'foo|lib/a.drift': '''
|
||||
CREATE TABLE numbers (foo REAL NOT NULL);
|
||||
|
|
|
@ -8,7 +8,7 @@ const _options = DriftOptions.defaults(modules: [SqlModule.fts5]);
|
|||
void main() {
|
||||
group('reports error', () {
|
||||
test('for missing content table', () async {
|
||||
final state = TestBackend.inTest({
|
||||
final state = await TestBackend.inTest({
|
||||
'a|lib/main.drift': '''
|
||||
CREATE VIRTUAL TABLE fts USING fts5(a, c, content=tbl);
|
||||
''',
|
||||
|
@ -23,7 +23,7 @@ CREATE VIRTUAL TABLE fts USING fts5(a, c, content=tbl);
|
|||
});
|
||||
|
||||
test('for invalid rowid of content table', () async {
|
||||
final state = TestBackend.inTest({
|
||||
final state = await TestBackend.inTest({
|
||||
'a|lib/main.drift': '''
|
||||
CREATE TABLE tbl (a, b, c, my_pk INTEGER PRIMARY KEY);
|
||||
|
||||
|
@ -39,7 +39,7 @@ CREATE VIRTUAL TABLE fts USING fts5(a, c, content=tbl, content_rowid=d);
|
|||
});
|
||||
|
||||
test('when referencing an unknown column', () async {
|
||||
final state = TestBackend.inTest({
|
||||
final state = await TestBackend.inTest({
|
||||
'a|lib/main.drift': '''
|
||||
CREATE TABLE tbl (a, b, c, d INTEGER PRIMARY KEY);
|
||||
|
||||
|
@ -54,7 +54,7 @@ CREATE VIRTUAL TABLE fts USING fts5(e, c, content=tbl, content_rowid=d);
|
|||
});
|
||||
|
||||
test('finds referenced table', () async {
|
||||
final state = TestBackend.inTest({
|
||||
final state = await TestBackend.inTest({
|
||||
'a|lib/main.drift': '''
|
||||
CREATE TABLE tbl (a, b, c, d INTEGER PRIMARY KEY);
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ import '../../test_utils.dart';
|
|||
|
||||
void main() {
|
||||
test('drift files can import original dart source', () async {
|
||||
final state = TestBackend.inTest({
|
||||
final state = await TestBackend.inTest({
|
||||
'a|lib/base.dart': r'''
|
||||
import 'package:drift/drift.dart';
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ import '../../test_utils.dart';
|
|||
void main() {
|
||||
// https://github.com/simolus3/drift/issues/2097#issuecomment-1273008383
|
||||
test('virtual columns are not required for inserts', () async {
|
||||
final state = TestBackend.inTest(
|
||||
final state = await TestBackend.inTest(
|
||||
{
|
||||
'foo|lib/a.drift': r'''
|
||||
CREATE TABLE IF NOT EXISTS nodes (
|
||||
|
|
|
@ -6,7 +6,7 @@ import '../../test_utils.dart';
|
|||
void main() {
|
||||
// Regression test for https://github.com/simolus3/drift/issues/754
|
||||
test('supports fts5 tables with external content', () async {
|
||||
final state = TestBackend.inTest({
|
||||
final state = await TestBackend.inTest({
|
||||
'foo|lib/a.drift': '''
|
||||
CREATE TABLE tbl(a INTEGER PRIMARY KEY, b TEXT, c TEXT);
|
||||
CREATE VIRTUAL TABLE fts_idx USING fts5(b, c, content='tbl', content_rowid='a');
|
||||
|
|
|
@ -20,7 +20,7 @@ query: INSERT INTO foo VALUES (?, ?, ?)
|
|||
|
||||
void main() {
|
||||
test('does not support newer sqlite features by default', () async {
|
||||
final state = TestBackend.inTest(_content);
|
||||
final state = await TestBackend.inTest(_content);
|
||||
|
||||
final file = await state.analyze('package:a/main.drift');
|
||||
expect(
|
||||
|
@ -38,7 +38,7 @@ void main() {
|
|||
});
|
||||
|
||||
test('supports newer sqlite features', () async {
|
||||
final state = TestBackend.inTest(
|
||||
final state = await TestBackend.inTest(
|
||||
_content,
|
||||
options: const DriftOptions.defaults(
|
||||
sqliteAnalysisOptions: SqliteAnalysisOptions(
|
||||
|
|
|
@ -14,7 +14,7 @@ enum Fruit {
|
|||
void main() {
|
||||
group('warns about invalid type converter value', () {
|
||||
test('in table definition', () async {
|
||||
final backend = TestBackend.inTest({
|
||||
final backend = await TestBackend.inTest({
|
||||
'a|lib/a.drift': '''
|
||||
import 'enum.dart';
|
||||
|
||||
|
@ -38,7 +38,7 @@ CREATE TABLE a (
|
|||
});
|
||||
|
||||
test('for query', () async {
|
||||
final backend = TestBackend.inTest({
|
||||
final backend = await TestBackend.inTest({
|
||||
'a|lib/a.drift': '''
|
||||
import 'enum.dart';
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ import '../../test_utils.dart';
|
|||
|
||||
void main() {
|
||||
test('reports foreign keys in drift model', () async {
|
||||
final backend = TestBackend.inTest({
|
||||
final backend = await TestBackend.inTest({
|
||||
'a|lib/a.drift': '''
|
||||
CREATE TABLE a (
|
||||
foo INTEGER PRIMARY KEY,
|
||||
|
@ -56,7 +56,7 @@ CREATE TABLE b (
|
|||
});
|
||||
|
||||
test('recognizes aliases to rowid', () async {
|
||||
final state = TestBackend.inTest({
|
||||
final state = await TestBackend.inTest({
|
||||
'foo|lib/a.drift': '''
|
||||
CREATE TABLE users (
|
||||
id INTEGER PRIMARY KEY,
|
||||
|
@ -84,7 +84,7 @@ CREATE TABLE b (
|
|||
});
|
||||
|
||||
test('parses enum columns', () async {
|
||||
final state = TestBackend.inTest({
|
||||
final state = await TestBackend.inTest({
|
||||
'a|lib/a.drift': '''
|
||||
import 'enum.dart';
|
||||
|
||||
|
@ -168,7 +168,7 @@ CREATE TABLE b (
|
|||
});
|
||||
|
||||
test('does not allow converters for enum columns', () async {
|
||||
final state = TestBackend.inTest({
|
||||
final state = await TestBackend.inTest({
|
||||
'a|lib/a.drift': '''
|
||||
import 'enum.dart';
|
||||
|
||||
|
@ -200,7 +200,7 @@ CREATE TABLE b (
|
|||
});
|
||||
|
||||
test('does not allow enum types for non-enums', () async {
|
||||
final state = TestBackend.inTest({
|
||||
final state = await TestBackend.inTest({
|
||||
'a|lib/a.drift': '''
|
||||
import 'enum.dart';
|
||||
|
||||
|
@ -223,7 +223,7 @@ CREATE TABLE b (
|
|||
});
|
||||
|
||||
test('supports JSON KEY annotation', () async {
|
||||
final state = TestBackend.inTest({
|
||||
final state = await TestBackend.inTest({
|
||||
'a|lib/a.drift': '''
|
||||
CREATE TABLE waybills (
|
||||
parent INT JSON KEY parentDoc NULL,
|
||||
|
@ -244,7 +244,7 @@ CREATE TABLE waybills (
|
|||
});
|
||||
|
||||
test('recognizes documentation comments', () async {
|
||||
final state = TestBackend.inTest({
|
||||
final state = await TestBackend.inTest({
|
||||
'a|lib/a.drift': '''
|
||||
CREATE TABLE IF NOT EXISTS currencies (
|
||||
-- The name of this currency
|
||||
|
@ -266,7 +266,7 @@ CREATE TABLE IF NOT EXISTS currencies (
|
|||
});
|
||||
|
||||
test('can use custom types', () async {
|
||||
final state = TestBackend.inTest({
|
||||
final state = await TestBackend.inTest({
|
||||
'a|lib/a.drift': '''
|
||||
import 'b.dart';
|
||||
|
||||
|
@ -289,7 +289,6 @@ class MyType implements CustomSqlType<String> {}
|
|||
|
||||
switch (column.sqlType) {
|
||||
case ColumnDriftType():
|
||||
case ColumnGeopolyPolygonType():
|
||||
fail('expect custom type');
|
||||
case ColumnCustomType(:final custom):
|
||||
expect(custom.dartType.toString(), 'String');
|
||||
|
|
|
@ -7,7 +7,7 @@ import '../../test_utils.dart';
|
|||
|
||||
void main() {
|
||||
test('supports virtual tables across drift files', () async {
|
||||
final state = TestBackend.inTest(
|
||||
final state = await TestBackend.inTest(
|
||||
{
|
||||
'a|lib/table.drift': '''
|
||||
CREATE TABLE example_table (
|
||||
|
@ -43,7 +43,7 @@ exampleSearch: SELECT example_table.**, s.* FROM example_table
|
|||
});
|
||||
|
||||
test('query virtual tables with unknown function', () async {
|
||||
final state = TestBackend.inTest(
|
||||
final state = await TestBackend.inTest(
|
||||
{
|
||||
'a|lib/table.drift': '''
|
||||
CREATE TABLE example_table (
|
||||
|
@ -72,7 +72,7 @@ SELECT rowid, highlight(example_table_search, 0, '[match]', '[match]') name,
|
|||
});
|
||||
|
||||
test('supports spellfix1 tables', () async {
|
||||
final state = TestBackend.inTest(
|
||||
final state = await TestBackend.inTest(
|
||||
{'a|lib/a.drift': 'CREATE VIRTUAL TABLE demo USING spellfix1;'},
|
||||
options: DriftOptions.defaults(
|
||||
dialect: DialectOptions(
|
||||
|
|
|
@ -8,7 +8,7 @@ import '../../test_utils.dart';
|
|||
|
||||
void main() {
|
||||
Future<Iterable<SqlQuery>> analyzeQueries(String driftFile) async {
|
||||
final state = TestBackend.inTest({'a|lib/a.drift': driftFile});
|
||||
final state = await TestBackend.inTest({'a|lib/a.drift': driftFile});
|
||||
|
||||
final result = await state.analyze('package:a/a.drift');
|
||||
return result.fileAnalysis!.resolvedQueries.values;
|
||||
|
|
|
@ -8,7 +8,7 @@ import 'utils.dart';
|
|||
|
||||
void main() {
|
||||
test('recognizes existing row classes', () async {
|
||||
final state = TestBackend.inTest({
|
||||
final state = await TestBackend.inTest({
|
||||
'a|lib/a.drift': '''
|
||||
import 'a.dart';
|
||||
|
||||
|
@ -35,7 +35,7 @@ class MyRow {
|
|||
});
|
||||
|
||||
test('can use named constructors', () async {
|
||||
final state = TestBackend.inTest({
|
||||
final state = await TestBackend.inTest({
|
||||
'a|lib/a.drift': '''
|
||||
import 'a.dart';
|
||||
|
||||
|
@ -75,7 +75,7 @@ class MyRow {
|
|||
});
|
||||
|
||||
test("warns if existing row classes don't exist", () async {
|
||||
final state = TestBackend.inTest({
|
||||
final state = await TestBackend.inTest({
|
||||
'a|lib/a.drift': '''
|
||||
import 'a.dart';
|
||||
|
||||
|
@ -91,7 +91,7 @@ foo WITH MyRow: SELECT 'hello world', 2;
|
|||
});
|
||||
|
||||
test('resolves existing row class', () async {
|
||||
final state = TestBackend.inTest({
|
||||
final state = await TestBackend.inTest({
|
||||
'a|lib/a.drift': '''
|
||||
import 'a.dart';
|
||||
|
||||
|
@ -122,7 +122,7 @@ class MyRow {
|
|||
|
||||
group('matches', () {
|
||||
test('single column type', () async {
|
||||
final state = TestBackend.inTest({
|
||||
final state = await TestBackend.inTest({
|
||||
'a|lib/a.drift': '''
|
||||
foo WITH int: SELECT 1 AS r;
|
||||
''',
|
||||
|
@ -139,7 +139,7 @@ foo WITH int: SELECT 1 AS r;
|
|||
});
|
||||
|
||||
test('single table', () async {
|
||||
final state = TestBackend.inTest({
|
||||
final state = await TestBackend.inTest({
|
||||
'a|lib/a.drift': '''
|
||||
import 'a.dart';
|
||||
|
||||
|
@ -166,7 +166,7 @@ typedef MyRow = TblData;
|
|||
});
|
||||
|
||||
test('single table with custom row class', () async {
|
||||
final state = TestBackend.inTest({
|
||||
final state = await TestBackend.inTest({
|
||||
'a|lib/a.drift': '''
|
||||
import 'a.dart';
|
||||
|
||||
|
@ -195,7 +195,7 @@ class MyTableRow {
|
|||
});
|
||||
|
||||
test('alternative to table class', () async {
|
||||
final state = TestBackend.inTest({
|
||||
final state = await TestBackend.inTest({
|
||||
'a|lib/a.drift': '''
|
||||
import 'a.dart';
|
||||
|
||||
|
@ -229,7 +229,7 @@ class MyQueryRow {
|
|||
|
||||
group('nested column', () {
|
||||
test('single column into field', () async {
|
||||
final state = TestBackend.inTest({
|
||||
final state = await TestBackend.inTest({
|
||||
'a|lib/a.drift': '''
|
||||
import 'a.dart';
|
||||
|
||||
|
@ -263,7 +263,7 @@ class MyQueryRow {
|
|||
});
|
||||
|
||||
test('single column into single-element record', () async {
|
||||
final state = TestBackend.inTest({
|
||||
final state = await TestBackend.inTest({
|
||||
'a|lib/a.drift': '''
|
||||
import 'a.dart';
|
||||
|
||||
|
@ -298,7 +298,7 @@ class MyQueryRow {
|
|||
});
|
||||
|
||||
test('custom result set', () async {
|
||||
final state = TestBackend.inTest(
|
||||
final state = await TestBackend.inTest(
|
||||
{
|
||||
'a|lib/a.drift': '''
|
||||
import 'a.dart';
|
||||
|
@ -344,7 +344,7 @@ class JsonStructure {
|
|||
});
|
||||
|
||||
test('table', () async {
|
||||
final state = TestBackend.inTest({
|
||||
final state = await TestBackend.inTest({
|
||||
'a|lib/a.drift': '''
|
||||
import 'a.dart';
|
||||
|
||||
|
@ -382,7 +382,7 @@ class MyRow {
|
|||
});
|
||||
|
||||
test('table as alternative to row class', () async {
|
||||
final state = TestBackend.inTest(
|
||||
final state = await TestBackend.inTest(
|
||||
{
|
||||
'a|lib/a.drift': '''
|
||||
import 'a.dart';
|
||||
|
@ -425,7 +425,7 @@ class MyRow {
|
|||
|
||||
group('nested LIST query', () {
|
||||
test('single column type', () async {
|
||||
final state = TestBackend.inTest({
|
||||
final state = await TestBackend.inTest({
|
||||
'a|lib/a.drift': '''
|
||||
import 'a.dart';
|
||||
|
||||
|
@ -461,7 +461,7 @@ class MyQueryRow {
|
|||
});
|
||||
|
||||
test('custom result set with class', () async {
|
||||
final state = TestBackend.inTest({
|
||||
final state = await TestBackend.inTest({
|
||||
'a|lib/a.drift': '''
|
||||
import 'a.dart';
|
||||
|
||||
|
@ -503,7 +503,7 @@ class MyNestedTable {
|
|||
});
|
||||
|
||||
test('custom result set with record', () async {
|
||||
final state = TestBackend.inTest(
|
||||
final state = await TestBackend.inTest(
|
||||
{
|
||||
'a|lib/a.drift': '''
|
||||
import 'a.dart';
|
||||
|
@ -545,7 +545,7 @@ class MyRow {
|
|||
});
|
||||
|
||||
test('into record', () async {
|
||||
final state = TestBackend.inTest(
|
||||
final state = await TestBackend.inTest(
|
||||
{
|
||||
'a|lib/a.drift': '''
|
||||
import 'a.dart';
|
||||
|
@ -586,7 +586,7 @@ typedef MyRow = (int, List<TblData>);
|
|||
test(
|
||||
'default record',
|
||||
() async {
|
||||
final state = TestBackend.inTest(
|
||||
final state = await TestBackend.inTest(
|
||||
{
|
||||
'a|lib/a.drift': '''
|
||||
import 'a.dart';
|
||||
|
@ -625,7 +625,7 @@ foo WITH Record: SELECT 1 AS a, LIST(SELECT * FROM tbl) AS b FROM tbl;
|
|||
);
|
||||
|
||||
test('mix', () async {
|
||||
final state = TestBackend.inTest({
|
||||
final state = await TestBackend.inTest({
|
||||
'a|lib/a.drift': '''
|
||||
import 'a.dart';
|
||||
|
||||
|
@ -685,7 +685,7 @@ class MyRow {
|
|||
|
||||
group('error', () {
|
||||
test('when the specified class has no default constructor', () async {
|
||||
final state = TestBackend.inTest({
|
||||
final state = await TestBackend.inTest({
|
||||
'a|lib/a.drift': '''
|
||||
import 'a.dart';
|
||||
|
||||
|
@ -705,7 +705,7 @@ class MyRow {
|
|||
});
|
||||
|
||||
test('when the desired constructor does not exist', () async {
|
||||
final state = TestBackend.inTest({
|
||||
final state = await TestBackend.inTest({
|
||||
'a|lib/a.drift': '''
|
||||
import 'a.dart';
|
||||
|
||||
|
@ -725,7 +725,7 @@ class MyRow {
|
|||
});
|
||||
|
||||
test('when there is a parameter with no matching column', () async {
|
||||
final state = TestBackend.inTest({
|
||||
final state = await TestBackend.inTest({
|
||||
'a|lib/a.drift': '''
|
||||
import 'a.dart';
|
||||
|
||||
|
@ -745,7 +745,7 @@ class MyRow {
|
|||
});
|
||||
|
||||
test('when a record has too many positional fields', () async {
|
||||
final state = TestBackend.inTest(
|
||||
final state = await TestBackend.inTest(
|
||||
{
|
||||
'a|lib/a.drift': '''
|
||||
import 'a.dart';
|
||||
|
@ -767,7 +767,7 @@ typedef MyRow = (int, String, DateTime);
|
|||
});
|
||||
|
||||
test('when a record has an unmatched named field', () async {
|
||||
final state = TestBackend.inTest(
|
||||
final state = await TestBackend.inTest(
|
||||
{
|
||||
'a|lib/a.drift': '''
|
||||
import 'a.dart';
|
||||
|
@ -788,7 +788,7 @@ typedef MyRow = (int, {String d});
|
|||
});
|
||||
|
||||
test('when there is a type mismatch on a scalar column', () async {
|
||||
final state = TestBackend.inTest({
|
||||
final state = await TestBackend.inTest({
|
||||
'a|lib/a.drift': '''
|
||||
import 'a.dart';
|
||||
|
||||
|
@ -808,7 +808,7 @@ class MyRow {
|
|||
});
|
||||
|
||||
test('when a list column is not a list', () async {
|
||||
final state = TestBackend.inTest({
|
||||
final state = await TestBackend.inTest({
|
||||
'a|lib/a.drift': '''
|
||||
import 'a.dart';
|
||||
|
||||
|
@ -832,7 +832,7 @@ class MyRow {
|
|||
test(
|
||||
'when there is a type mismatch on a nested scalar column',
|
||||
() async {
|
||||
final state = TestBackend.inTest({
|
||||
final state = await TestBackend.inTest({
|
||||
'a|lib/a.drift': '''
|
||||
import 'a.dart';
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ import '../../test_utils.dart';
|
|||
|
||||
void main() {
|
||||
test('experimental inference - integration test', () async {
|
||||
final state = TestBackend.inTest({
|
||||
final state = await TestBackend.inTest({
|
||||
'foo|lib/a.drift': '''
|
||||
CREATE TABLE artists (
|
||||
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||
|
|
|
@ -76,7 +76,7 @@ q: SELECT * FROM t WHERE i IN ?1;
|
|||
});
|
||||
|
||||
test('warns about default values outside of expressions', () async {
|
||||
final state = TestBackend.inTest({
|
||||
final state = await TestBackend.inTest({
|
||||
'foo|lib/a.drift': r'''
|
||||
CREATE TABLE foo (
|
||||
id INT NOT NULL PRIMARY KEY,
|
||||
|
@ -96,7 +96,7 @@ all ($limit = 3): SELECT * FROM foo LIMIT $limit;
|
|||
});
|
||||
|
||||
test('warns when placeholder are used in insert with columns', () async {
|
||||
final state = TestBackend.inTest({
|
||||
final state = await TestBackend.inTest({
|
||||
'foo|lib/a.drift': r'''
|
||||
CREATE TABLE foo (
|
||||
id INT NOT NULL PRIMARY KEY,
|
||||
|
@ -118,7 +118,7 @@ in: INSERT INTO foo (id) $placeholder;
|
|||
test(
|
||||
'warns when nested results appear in compound statements',
|
||||
() async {
|
||||
final state = TestBackend.inTest({
|
||||
final state = await TestBackend.inTest({
|
||||
'foo|lib/a.drift': '''
|
||||
CREATE TABLE foo (
|
||||
id INT NOT NULL PRIMARY KEY,
|
||||
|
@ -142,7 +142,7 @@ all: SELECT foo.** FROM foo UNION ALL SELECT foo.** FROM foo;
|
|||
test(
|
||||
'warns when nested query appear in nested query',
|
||||
() async {
|
||||
final state = TestBackend.inTest({
|
||||
final state = await TestBackend.inTest({
|
||||
'foo|lib/a.drift': '''
|
||||
CREATE TABLE foo (
|
||||
id INT NOT NULL PRIMARY KEY,
|
||||
|
@ -175,7 +175,7 @@ all: SELECT foo.**, LIST(SELECT *, LIST(SELECT * FROM foo) FROM foo) FROM foo;
|
|||
}
|
||||
|
||||
test('in top-level queries', () async {
|
||||
state = TestBackend.inTest({
|
||||
state = await TestBackend.inTest({
|
||||
'foo|lib/a.drift': '''
|
||||
CREATE TABLE foo (
|
||||
id INT NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||
|
@ -189,7 +189,7 @@ test: INSERT INTO foo VALUES (?)
|
|||
});
|
||||
|
||||
test('in CREATE TRIGGER statements', () async {
|
||||
state = TestBackend.inTest({
|
||||
state = await TestBackend.inTest({
|
||||
'foo|lib/a.drift': '''
|
||||
CREATE TABLE foo (
|
||||
id INT NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||
|
@ -205,7 +205,7 @@ END;
|
|||
});
|
||||
|
||||
test('in @create statements', () async {
|
||||
state = TestBackend.inTest({
|
||||
state = await TestBackend.inTest({
|
||||
'foo|lib/a.drift': '''
|
||||
CREATE TABLE foo (
|
||||
id INT NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||
|
|
|
@ -5,7 +5,7 @@ import '../../test_utils.dart';
|
|||
|
||||
void main() {
|
||||
test('select from view', () async {
|
||||
final backend = TestBackend.inTest({
|
||||
final backend = await TestBackend.inTest({
|
||||
'foo|lib/a.drift': '''
|
||||
CREATE TABLE artists (
|
||||
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||
|
|
|
@ -9,7 +9,7 @@ import 'utils.dart';
|
|||
|
||||
void main() {
|
||||
test('respects explicit type arguments', () async {
|
||||
final state = TestBackend.inTest({
|
||||
final state = await TestBackend.inTest({
|
||||
'foo|lib/main.drift': '''
|
||||
bar(?1 AS TEXT, :foo AS BOOLEAN): SELECT ?, :foo;
|
||||
''',
|
||||
|
@ -29,7 +29,7 @@ bar(?1 AS TEXT, :foo AS BOOLEAN): SELECT ?, :foo;
|
|||
});
|
||||
|
||||
test('can read from builtin tables', () async {
|
||||
final state = TestBackend.inTest({
|
||||
final state = await TestBackend.inTest({
|
||||
'a|lib/main.drift': '''
|
||||
testQuery: SELECT * FROM sqlite_schema;
|
||||
''',
|
||||
|
@ -43,7 +43,7 @@ testQuery: SELECT * FROM sqlite_schema;
|
|||
});
|
||||
|
||||
test('reads REQUIRED syntax', () async {
|
||||
final state = TestBackend.inTest({
|
||||
final state = await TestBackend.inTest({
|
||||
'foo|lib/main.drift': '''
|
||||
bar(REQUIRED ?1 AS TEXT OR NULL, REQUIRED :foo AS BOOLEAN): SELECT ?, :foo;
|
||||
''',
|
||||
|
@ -64,7 +64,7 @@ bar(REQUIRED ?1 AS TEXT OR NULL, REQUIRED :foo AS BOOLEAN): SELECT ?, :foo;
|
|||
});
|
||||
|
||||
test('infers result set for views', () async {
|
||||
final state = TestBackend.inTest({
|
||||
final state = await TestBackend.inTest({
|
||||
'foo|lib/main.drift': r'''
|
||||
CREATE VIEW my_view AS SELECT 'foo', 2;
|
||||
|
||||
|
@ -90,7 +90,7 @@ query: SELECT * FROM my_view;
|
|||
});
|
||||
|
||||
test('infers nested result set for views', () async {
|
||||
final state = TestBackend.inTest({
|
||||
final state = await TestBackend.inTest({
|
||||
'foo|lib/main.drift': r'''
|
||||
CREATE VIEW my_view AS SELECT 'foo', 2;
|
||||
|
||||
|
@ -123,7 +123,7 @@ query: SELECT foo.**, bar.** FROM my_view foo, my_view bar;
|
|||
});
|
||||
|
||||
test('infers nested result sets for custom result sets', () async {
|
||||
final state = TestBackend.inTest({
|
||||
final state = await TestBackend.inTest({
|
||||
'foo|lib/main.drift': r'''
|
||||
query: SELECT 1 AS a, b.** FROM (SELECT 2 AS b, 3 AS c) AS b;
|
||||
''',
|
||||
|
@ -154,7 +154,7 @@ query: SELECT 1 AS a, b.** FROM (SELECT 2 AS b, 3 AS c) AS b;
|
|||
|
||||
for (final dateTimeAsText in [false, true]) {
|
||||
test('analyzing date times (stored as text: $dateTimeAsText)', () async {
|
||||
final state = TestBackend.inTest(
|
||||
final state = await TestBackend.inTest(
|
||||
{
|
||||
'foo|lib/foo.drift': r'''
|
||||
CREATE TABLE foo (
|
||||
|
@ -202,7 +202,7 @@ q3: SELECT datetime('now');
|
|||
}
|
||||
|
||||
test('resolves nested result sets', () async {
|
||||
final state = TestBackend.inTest({
|
||||
final state = await TestBackend.inTest({
|
||||
'foo|lib/main.drift': r'''
|
||||
CREATE TABLE points (
|
||||
id INTEGER NOT NULL PRIMARY KEY,
|
||||
|
@ -243,7 +243,7 @@ FROM routes
|
|||
});
|
||||
|
||||
test('resolves nullability of aliases in nested result sets', () async {
|
||||
final state = TestBackend.inTest({
|
||||
final state = await TestBackend.inTest({
|
||||
'foo|lib/main.drift': r'''
|
||||
CREATE TABLE tableA1 (id INTEGER);
|
||||
CREATE TABLE tableB1 (id INTEGER);
|
||||
|
@ -285,7 +285,7 @@ LEFT JOIN tableB1 AS tableB2 -- nullable
|
|||
|
||||
test('supports custom functions', () async {
|
||||
final withoutOptions =
|
||||
TestBackend.inTest({'a|lib/a.drift': 'a: SELECT my_function();'});
|
||||
await TestBackend.inTest({'a|lib/a.drift': 'a: SELECT my_function();'});
|
||||
var result = await withoutOptions.analyze('package:a/a.drift');
|
||||
expect(result.allErrors, [
|
||||
isDriftError('Function my_function could not be found')
|
||||
|
@ -294,14 +294,13 @@ LEFT JOIN tableB1 AS tableB2 -- nullable
|
|||
.withSpan('my_function()'),
|
||||
]);
|
||||
|
||||
final withOptions =
|
||||
TestBackend.inTest({'a|lib/a.drift': 'a: SELECT my_function(?, ?);'},
|
||||
options: DriftOptions.defaults(
|
||||
sqliteAnalysisOptions: SqliteAnalysisOptions(knownFunctions: {
|
||||
'my_function':
|
||||
KnownSqliteFunction.fromJson('boolean (int, text)')
|
||||
}),
|
||||
));
|
||||
final withOptions = await TestBackend.inTest(
|
||||
{'a|lib/a.drift': 'a: SELECT my_function(?, ?);'},
|
||||
options: DriftOptions.defaults(
|
||||
sqliteAnalysisOptions: SqliteAnalysisOptions(knownFunctions: {
|
||||
'my_function': KnownSqliteFunction.fromJson('boolean (int, text)')
|
||||
}),
|
||||
));
|
||||
result = await withOptions.analyze('package:a/a.drift');
|
||||
|
||||
withOptions.expectNoErrors();
|
||||
|
@ -318,7 +317,7 @@ LEFT JOIN tableB1 AS tableB2 -- nullable
|
|||
});
|
||||
|
||||
test('can cast to DATETIME and BOOLEAN', () async {
|
||||
final backend = TestBackend.inTest({
|
||||
final backend = await TestBackend.inTest({
|
||||
'a|lib/a.drift': '''
|
||||
a: SELECT CAST(1 AS BOOLEAN) AS a, CAST(2 AS DATETIME) as b;
|
||||
''',
|
||||
|
@ -337,7 +336,7 @@ a: SELECT CAST(1 AS BOOLEAN) AS a, CAST(2 AS DATETIME) as b;
|
|||
});
|
||||
|
||||
test('can cast to enum type', () async {
|
||||
final backend = TestBackend.inTest({
|
||||
final backend = await TestBackend.inTest({
|
||||
'a|lib/a.drift': '''
|
||||
import 'enum.dart';
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ import '../test_utils.dart';
|
|||
void main() {
|
||||
group('from clean state', () {
|
||||
test('resolves simple tables', () async {
|
||||
final backend = TestBackend.inTest({
|
||||
final backend = await TestBackend.inTest({
|
||||
'a|lib/a.drift': '''
|
||||
CREATE TABLE a (
|
||||
foo INTEGER PRIMARY KEY,
|
||||
|
@ -42,7 +42,7 @@ CREATE TABLE b (
|
|||
|
||||
group('references', () {
|
||||
test('self', () async {
|
||||
final backend = TestBackend.inTest({
|
||||
final backend = await TestBackend.inTest({
|
||||
'a|lib/a.drift': '''
|
||||
CREATE TABLE a (
|
||||
foo INTEGER PRIMARY KEY,
|
||||
|
@ -61,7 +61,7 @@ CREATE TABLE a (
|
|||
});
|
||||
|
||||
test('across files', () async {
|
||||
final backend = TestBackend.inTest({
|
||||
final backend = await TestBackend.inTest({
|
||||
'a|lib/a.drift': '''
|
||||
import 'b.drift';
|
||||
|
||||
|
@ -93,7 +93,7 @@ CREATE TABLE b (
|
|||
});
|
||||
|
||||
test('for triggers', () async {
|
||||
final backend = TestBackend.inTest({
|
||||
final backend = await TestBackend.inTest({
|
||||
'a|lib/a.drift': '''
|
||||
import 'b.drift';
|
||||
|
||||
|
@ -133,7 +133,7 @@ CREATE TABLE deleted_b (
|
|||
|
||||
group('non-existing', () {
|
||||
test('from table', () async {
|
||||
final backend = TestBackend.inTest({
|
||||
final backend = await TestBackend.inTest({
|
||||
'a|lib/a.drift': '''
|
||||
CREATE TABLE a (
|
||||
foo INTEGER PRIMARY KEY,
|
||||
|
@ -151,7 +151,7 @@ CREATE TABLE a (
|
|||
[isDriftError('`b` could not be found in any import.')]);
|
||||
});
|
||||
test('in a trigger', () async {
|
||||
final backend = TestBackend.inTest(const {
|
||||
final backend = await TestBackend.inTest(const {
|
||||
'foo|lib/a.drift': '''
|
||||
CREATE TRIGGER IF NOT EXISTS foo BEFORE DELETE ON bar BEGIN
|
||||
END;
|
||||
|
@ -172,7 +172,7 @@ END;
|
|||
});
|
||||
|
||||
test('emits warning on invalid import', () async {
|
||||
final backend = TestBackend.inTest({
|
||||
final backend = await TestBackend.inTest({
|
||||
'a|lib/a.drift': "import 'b.drift';",
|
||||
});
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ import '../test_utils.dart';
|
|||
void main() {
|
||||
late TestBackend tester;
|
||||
|
||||
setUpAll(() => tester = TestBackend({}));
|
||||
setUpAll(() async => tester = await TestBackend.init({}));
|
||||
tearDownAll(() => tester.dispose());
|
||||
|
||||
group('from AST', () {
|
||||
|
|
|
@ -37,24 +37,43 @@ class TestBackend extends DriftBackend {
|
|||
AnalysisContext? _dartContext;
|
||||
OverlayResourceProvider? _resourceProvider;
|
||||
|
||||
TestBackend(
|
||||
TestBackend._(
|
||||
Map<String, String> sourceContents, {
|
||||
DriftOptions options = const DriftOptions.defaults(),
|
||||
this.analyzerExperiments = const Iterable.empty(),
|
||||
}) : sourceContents = {
|
||||
for (final entry in sourceContents.entries)
|
||||
AssetId.parse(entry.key).uri.toString(): entry.value,
|
||||
} {
|
||||
driver = DriftAnalysisDriver(this, options, isTesting: true);
|
||||
}
|
||||
};
|
||||
|
||||
factory TestBackend.inTest(
|
||||
static Future<TestBackend> init(
|
||||
Map<String, String> sourceContents, {
|
||||
DriftOptions options = const DriftOptions.defaults(),
|
||||
Iterable<String> analyzerExperiments = const Iterable.empty(),
|
||||
}) {
|
||||
final backend = TestBackend(sourceContents,
|
||||
options: options, analyzerExperiments: analyzerExperiments);
|
||||
}) async {
|
||||
final backend = TestBackend._(
|
||||
sourceContents,
|
||||
options: options,
|
||||
analyzerExperiments: analyzerExperiments,
|
||||
);
|
||||
|
||||
backend.driver =
|
||||
await DriftAnalysisDriver.init(backend, options, isTesting: true);
|
||||
|
||||
return backend;
|
||||
}
|
||||
|
||||
static Future<TestBackend> inTest(
|
||||
Map<String, String> sourceContents, {
|
||||
DriftOptions options = const DriftOptions.defaults(),
|
||||
Iterable<String> analyzerExperiments = const Iterable.empty(),
|
||||
}) async {
|
||||
final backend = await TestBackend.init(
|
||||
sourceContents,
|
||||
options: options,
|
||||
analyzerExperiments: analyzerExperiments,
|
||||
);
|
||||
|
||||
addTearDown(backend.dispose);
|
||||
|
||||
return backend;
|
||||
|
@ -62,9 +81,10 @@ class TestBackend extends DriftBackend {
|
|||
|
||||
static Future<FileState> analyzeSingle(String content,
|
||||
{String asset = 'a|lib/a.drift',
|
||||
DriftOptions options = const DriftOptions.defaults()}) {
|
||||
DriftOptions options = const DriftOptions.defaults()}) async {
|
||||
final assetId = AssetId.parse(asset);
|
||||
final backend = TestBackend.inTest({asset: content}, options: options);
|
||||
final backend =
|
||||
await TestBackend.inTest({asset: content}, options: options);
|
||||
return backend.driver.fullyAnalyze(assetId.uri);
|
||||
}
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ import '../analysis/test_utils.dart';
|
|||
|
||||
void main() {
|
||||
test('finds update rules for triggers', () async {
|
||||
final state = TestBackend.inTest({
|
||||
final state = await TestBackend.inTest({
|
||||
'a|lib/a.drift': '''
|
||||
CREATE TABLE users (
|
||||
id INTEGER NOT NULL PRIMARY KEY,
|
||||
|
@ -51,7 +51,7 @@ class MyDatabase {}
|
|||
});
|
||||
|
||||
test('finds update rules for foreign key constraint', () async {
|
||||
final state = TestBackend.inTest({
|
||||
final state = await TestBackend.inTest({
|
||||
'a|lib/a.drift': '''
|
||||
CREATE TABLE a (
|
||||
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||
|
|
|
@ -95,7 +95,7 @@ CREATE VIEW user_ids AS SELECT id FROM users;
|
|||
}
|
||||
|
||||
Future<List<DriftElement>> _analyzeAndSerialize(String source) async {
|
||||
final state = TestBackend.inTest({'a|lib/a.drift': source});
|
||||
final state = await TestBackend.inTest({'a|lib/a.drift': source});
|
||||
final file = await state.analyze('package:a/a.drift');
|
||||
|
||||
final writer = SchemaWriter(file.analyzedElements.toList());
|
||||
|
|
|
@ -14,7 +14,7 @@ import '../../analysis/test_utils.dart';
|
|||
|
||||
void main() {
|
||||
test('writer integration test', () async {
|
||||
final state = TestBackend.inTest({
|
||||
final state = await TestBackend.inTest({
|
||||
'a|lib/a.drift': '''
|
||||
import 'main.dart';
|
||||
|
||||
|
|
|
@ -15,8 +15,8 @@ void main() {
|
|||
{DriftOptions options = const DriftOptions.defaults(
|
||||
generateNamedParameters: true,
|
||||
)}) async {
|
||||
final state =
|
||||
TestBackend.inTest({'a|lib/main.drift': driftFile}, options: options);
|
||||
final state = await TestBackend.inTest({'a|lib/main.drift': driftFile},
|
||||
options: options);
|
||||
final file = await state.analyze('package:a/main.drift');
|
||||
state.expectNoErrors();
|
||||
|
||||
|
|
Loading…
Reference in New Issue