move geopoly to extensions

This commit is contained in:
Nikita Dauhashei 2024-04-14 23:51:29 +02:00
parent 349787ad4b
commit 5e5628d1a8
No known key found for this signature in database
GPG Key ID: 3B93F636D935382D
71 changed files with 394 additions and 319 deletions

View File

@ -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._();
}

View File

@ -7,3 +7,5 @@ export 'runtime/query_builder/query_builder.dart' show TableInfo;
export 'dsl/dsl.dart' export 'dsl/dsl.dart'
show Table, TableIndex, View, DriftDatabase, DriftAccessor; show Table, TableIndex, View, DriftDatabase, DriftAccessor;
export '../extensions/geopoly.dart';

View File

@ -1,5 +1,5 @@
import 'dart:core';
import 'dart:core' as core; import 'dart:core' as core;
import 'dart:core';
import 'dart:typed_data'; import 'dart:typed_data';
import 'package:collection/collection.dart'; import 'package:collection/collection.dart';
@ -81,15 +81,6 @@ final class SqlTypes {
return dartValue.rawSqlValue; return dartValue.rawSqlValue;
} }
if (dartValue is GeopolyPolygon) {
switch (dartValue) {
case _StringGeopolyPolygon(:final value):
return value;
case _BlobGeopolyPolygon(:final value):
return value;
}
}
return dartValue; return dartValue;
} }
@ -551,25 +542,3 @@ final class _ByDialectType<T extends Object> implements DialectAwareSqlType<T> {
return _selectType(context.typeMapping).sqlTypeName(context); 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._();
}

View File

@ -1,11 +1,12 @@
import 'dart:convert'; import 'dart:convert';
import 'package:analyzer/dart/element/element.dart'; import 'package:analyzer/dart/element/element.dart';
import 'package:meta/meta.dart';
import 'package:sqlparser/sqlparser.dart'; import 'package:sqlparser/sqlparser.dart';
import '../options.dart';
import '../backend.dart'; import '../backend.dart';
import '../drift_native_functions.dart'; import '../drift_native_functions.dart';
import '../options.dart';
import '../resolver/dart/helper.dart'; import '../resolver/dart/helper.dart';
import '../resolver/discover.dart'; import '../resolver/discover.dart';
import '../resolver/drift/sqlparser/mapping.dart'; import '../resolver/drift/sqlparser/mapping.dart';
@ -62,10 +63,30 @@ class DriftAnalysisDriver {
AnalysisResultCacheReader? cacheReader; AnalysisResultCacheReader? cacheReader;
KnownDriftTypes? _knownTypes; final KnownDriftTypes knownTypes;
DriftAnalysisDriver(this.backend, this.options, {bool isTesting = false}) @visibleForTesting
: _isTesting = isTesting; 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() { SqlEngine newSqlEngine() {
return SqlEngine( 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 /// For a given file under [uri], attempts to restore serialized analysis
/// results that have been stored before. /// results that have been stored before.
/// ///
@ -359,6 +375,7 @@ abstract class AnalysisResultCacheReader {
Future<CachedDiscoveryResults?> readDiscovery(Uri uri); Future<CachedDiscoveryResults?> readDiscovery(Uri uri);
Future<LibraryElement?> readTypeHelperFor(Uri uri); Future<LibraryElement?> readTypeHelperFor(Uri uri);
Future<String?> readElementCacheFor(Uri uri); Future<String?> readElementCacheFor(Uri uri);
} }

View File

@ -344,7 +344,7 @@ class ColumnParser {
.apply(getter.name.lexeme); .apply(getter.name.lexeme);
ColumnType columnType; ColumnType columnType;
final helper = await _resolver.resolver.driver.loadKnownTypes(); final helper = _resolver.resolver.driver.knownTypes;
if (foundStartMethod == _startCustom) { if (foundStartMethod == _startCustom) {
final expression = remainingExpr.argumentList.arguments.single; final expression = remainingExpr.argumentList.arguments.single;

View File

@ -7,7 +7,7 @@ import 'package:analyzer/dart/element/type_provider.dart';
import 'package:analyzer/dart/element/type_system.dart'; import 'package:analyzer/dart/element/type_system.dart';
import 'package:collection/collection.dart'; import 'package:collection/collection.dart';
import '../../driver/driver.dart'; import '../../backend.dart';
import '../../driver/error.dart'; import '../../driver/error.dart';
import '../../results/results.dart'; import '../../results/results.dart';
import '../resolver.dart'; import '../resolver.dart';
@ -32,6 +32,7 @@ class KnownDriftTypes {
final InterfaceElement jsonTypeConverter; final InterfaceElement jsonTypeConverter;
final InterfaceType driftAny; final InterfaceType driftAny;
final InterfaceType uint8List; final InterfaceType uint8List;
final InterfaceType geopolyPolygon;
KnownDriftTypes._( KnownDriftTypes._(
this.helperLibrary, this.helperLibrary,
@ -47,6 +48,7 @@ class KnownDriftTypes {
this.driftAccessor, this.driftAccessor,
this.driftAny, this.driftAny,
this.uint8List, this.uint8List,
this.geopolyPolygon,
); );
/// Constructs the set of known drift types from a helper library, which is /// Constructs the set of known drift types from a helper library, which is
@ -73,6 +75,8 @@ class KnownDriftTypes {
.defaultInstantiation, .defaultInstantiation,
(exportNamespace.get('Uint8List') as InterfaceElement) (exportNamespace.get('Uint8List') as InterfaceElement)
.defaultInstantiation, .defaultInstantiation,
(exportNamespace.get('GeopolyPolygon') as InterfaceElement)
.defaultInstantiation,
); );
} }
@ -98,8 +102,8 @@ class KnownDriftTypes {
return type?.asInstanceOf(converter); return type?.asInstanceOf(converter);
} }
static Future<KnownDriftTypes> resolve(DriftAnalysisDriver driver) async { static Future<KnownDriftTypes> resolve(DriftBackend backend) async {
final library = await driver.backend.readDart(uri); final library = await backend.readDart(uri);
return KnownDriftTypes._fromLibrary(library); return KnownDriftTypes._fromLibrary(library);
} }
@ -256,7 +260,7 @@ class DataClassInformation {
useRowClass.getField('constructor')!.toStringValue()!; useRowClass.getField('constructor')!.toStringValue()!;
final generateInsertable = final generateInsertable =
useRowClass.getField('generateInsertable')!.toBoolValue()!; useRowClass.getField('generateInsertable')!.toBoolValue()!;
final helper = await resolver.resolver.driver.loadKnownTypes(); final helper = resolver.resolver.driver.knownTypes;
if (type is InterfaceType) { if (type is InterfaceType) {
final found = FoundDartClass(type.element, type.typeArguments); final found = FoundDartClass(type.element, type.typeArguments);

View File

@ -53,7 +53,7 @@ class DartViewResolver extends LocalElementResolver<DiscoveredDartView> {
Future<TableReferenceInDartView?> _getStaticReference( Future<TableReferenceInDartView?> _getStaticReference(
FieldElement field) async { FieldElement field) async {
final type = field.type; final type = field.type;
final knownTypes = await resolver.driver.loadKnownTypes(); final knownTypes = resolver.driver.knownTypes;
final typeSystem = field.library.typeSystem; final typeSystem = field.library.typeSystem;
if (type is! InterfaceType || if (type is! InterfaceType ||

View File

@ -73,8 +73,7 @@ class DiscoverStep {
_file.discovery = NotADartLibrary(); _file.discovery = NotADartLibrary();
break; break;
} }
final finder = final finder = _FindDartElements(this, library, _driver.knownTypes);
_FindDartElements(this, library, await _driver.loadKnownTypes());
await finder.find(); await finder.find();
_file.errorsDuringDiscovery.addAll(finder.errors); _file.errorsDuringDiscovery.addAll(finder.errors);

View File

@ -37,7 +37,7 @@ abstract class DriftElementResolver<T extends DiscoveredElement>
return null; return null;
} }
final knownTypes = await resolver.driver.loadKnownTypes(); final knownTypes = resolver.driver.knownTypes;
return readCustomType( return readCustomType(
knownTypes.helperLibrary, knownTypes.helperLibrary,
expression, expression,
@ -64,7 +64,7 @@ abstract class DriftElementResolver<T extends DiscoveredElement>
return null; return null;
} }
final knownTypes = await resolver.driver.loadKnownTypes(); final knownTypes = resolver.driver.knownTypes;
return readTypeConverter( return readTypeConverter(
knownTypes.helperLibrary, knownTypes.helperLibrary,
expression, expression,
@ -153,7 +153,7 @@ abstract class DriftElementResolver<T extends DiscoveredElement>
innerType, innerType,
false, false,
this, this,
await resolver.driver.loadKnownTypes(), resolver.driver.knownTypes,
); );
} }
} }
@ -166,7 +166,7 @@ abstract class DriftElementResolver<T extends DiscoveredElement>
)); ));
return null; return null;
} else { } else {
final knownTypes = await resolver.driver.loadKnownTypes(); final knownTypes = resolver.driver.knownTypes;
return validateExistingClass(columns, foundDartClass, return validateExistingClass(columns, foundDartClass,
source.constructorName ?? '', false, this, knownTypes); source.constructorName ?? '', false, this, knownTypes);
} }

View File

@ -79,7 +79,6 @@ class TypeMapping {
type = switch (column.sqlType) { type = switch (column.sqlType) {
ColumnDriftType() => type, ColumnDriftType() => type,
ColumnCustomType(:final custom) => type.addHint(CustomTypeHint(custom)), ColumnCustomType(:final custom) => type.addHint(CustomTypeHint(custom)),
ColumnGeopolyPolygonType() => type.addHint(const IsGeopolyPolygon()),
}; };
if (column.typeConverter case AppliedTypeConverter c) { if (column.typeConverter case AppliedTypeConverter c) {
@ -151,7 +150,17 @@ class TypeMapping {
} }
if (type.hint<IsGeopolyPolygon>() != null) { 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)); return ColumnType.drift(_toDefaultType(type));

View File

@ -77,7 +77,7 @@ class DriftTableResolver extends DriftElementResolver<DiscoveredDriftTable> {
type.builtin == DriftSqlType.int type.builtin == DriftSqlType.int
? EnumType.intEnum ? EnumType.intEnum
: EnumType.textEnum, : EnumType.textEnum,
await resolver.driver.loadKnownTypes(), resolver.driver.knownTypes,
); );
} }
} }

View File

@ -27,7 +27,7 @@ class DriftViewResolver extends DriftElementResolver<DiscoveredDriftView> {
? null ? null
: await createTypeResolver( : await createTypeResolver(
allReferences, allReferences,
await resolver.driver.loadKnownTypes(), resolver.driver.knownTypes,
); );
final context = engine.analyzeNode( final context = engine.analyzeNode(

View File

@ -19,7 +19,7 @@ class FileAnalyzer {
Future<FileAnalysisResult> runAnalysisOn(FileState state) async { Future<FileAnalysisResult> runAnalysisOn(FileState state) async {
final result = FileAnalysisResult(); final result = FileAnalysisResult();
final knownTypes = await driver.loadKnownTypes(); final knownTypes = driver.knownTypes;
if (state.extension == '.dart') { if (state.extension == '.dart') {
for (final elementAnalysis in state.analysis.values) { for (final elementAnalysis in state.analysis.values) {

View File

@ -143,8 +143,6 @@ class AnnotatedDartCodeBuilder {
addTopLevel(dartTypeNames[hasType.sqlType.builtin]!); addTopLevel(dartTypeNames[hasType.sqlType.builtin]!);
case ColumnCustomType(:final custom): case ColumnCustomType(:final custom):
addDartType(custom.dartType); addDartType(custom.dartType);
case ColumnGeopolyPolygonType(:final dartType):
addTopLevel(dartType);
} }
if (hasType.nullable) addText('?'); if (hasType.nullable) addText('?');
} }

View File

@ -750,7 +750,7 @@ final class ScalarResultColumn extends ResultColumn
int get _columnTypeCompatibilityHash { int get _columnTypeCompatibilityHash {
final custom = switch (sqlType) { final custom = switch (sqlType) {
ColumnDriftType() || ColumnGeopolyPolygonType() => null, ColumnDriftType() => null,
ColumnCustomType(:final custom) => custom, ColumnCustomType(:final custom) => custom,
}; };

View File

@ -44,19 +44,11 @@ sealed class ColumnType {
/// all. /// all.
final DriftSqlType builtin; 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 ColumnType._(this.builtin);
const factory ColumnType.drift(DriftSqlType builtin) = ColumnDriftType; const factory ColumnType.drift(DriftSqlType builtin) = ColumnDriftType;
const factory ColumnType.custom(CustomColumnType custom) = ColumnCustomType; const factory ColumnType.custom(CustomColumnType custom) = ColumnCustomType;
const factory ColumnType.geopolyPolygon() = ColumnGeopolyPolygonType;
} }
final class ColumnDriftType extends ColumnType { final class ColumnDriftType extends ColumnType {
@ -69,13 +61,6 @@ final class ColumnCustomType extends ColumnType {
const ColumnCustomType(this.custom) : super._(DriftSqlType.any); 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 { extension OperationOnTypes on HasType {
bool get isUint8ListInDart { bool get isUint8ListInDart {
return sqlType.builtin == DriftSqlType.blob && typeConverter == null; return sqlType.builtin == DriftSqlType.blob && typeConverter == null;

View File

@ -200,20 +200,17 @@ class ElementSerializer {
} }
Map<String, Object?> _serializeColumnType(ColumnType type) { Map<String, Object?> _serializeColumnType(ColumnType type) {
switch (type) { return switch (type) {
case ColumnGeopolyPolygonType(): ColumnDriftType() => {
case ColumnDriftType():
return {
'builtin': type.builtin.name, 'builtin': type.builtin.name,
}; },
case ColumnCustomType(:final custom): ColumnCustomType(:final custom) => {
return {
'custom': { 'custom': {
'dart': _serializeType(custom.dartType), 'dart': _serializeType(custom.dartType),
'expression': custom.expression.toJson(), 'expression': custom.expression.toJson(),
} }
}; },
} };
} }
Map<String, Object?> _serializeColumn(DriftColumn column) { Map<String, Object?> _serializeColumn(DriftColumn column) {

View File

@ -46,11 +46,11 @@ class AnalysisContextBackend extends DriftBackend {
AnalysisContextBackend(this.context, this.provider); AnalysisContextBackend(this.context, this.provider);
static PhysicalDriftDriver createDriver({ static Future<PhysicalDriftDriver> createDriver({
DriftOptions options = const DriftOptions.defaults(), DriftOptions options = const DriftOptions.defaults(),
ResourceProvider? resourceProvider, ResourceProvider? resourceProvider,
required String projectDirectory, required String projectDirectory,
}) { }) async {
final underlyingProvider = final underlyingProvider =
resourceProvider ?? PhysicalResourceProvider.INSTANCE; resourceProvider ?? PhysicalResourceProvider.INSTANCE;
final provider = OverlayResourceProvider(underlyingProvider); final provider = OverlayResourceProvider(underlyingProvider);
@ -62,7 +62,7 @@ class AnalysisContextBackend extends DriftBackend {
final context = contextCollection.contextFor(projectDirectory); final context = contextCollection.contextFor(projectDirectory);
final backend = AnalysisContextBackend(context, provider); final backend = AnalysisContextBackend(context, provider);
final driver = DriftAnalysisDriver(backend, options); final driver = await DriftAnalysisDriver.init(backend, options);
return PhysicalDriftDriver(driver, backend); return PhysicalDriftDriver(driver, backend);
} }

View File

@ -31,7 +31,7 @@ class DriftDiscover extends Builder {
@override @override
Future<void> build(BuildStep buildStep) async { Future<void> build(BuildStep buildStep) async {
final backend = DriftBuildBackend(buildStep); 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 prepared = await driver.findLocalElements(buildStep.inputId.uri);
final discovery = prepared.discovery; final discovery = prepared.discovery;
@ -84,7 +84,7 @@ class DriftAnalyzer extends Builder {
@override @override
Future<void> build(BuildStep buildStep) async { Future<void> build(BuildStep buildStep) async {
final backend = DriftBuildBackend(buildStep); final backend = DriftBuildBackend(buildStep);
final driver = DriftAnalysisDriver(backend, options) final driver = await DriftAnalysisDriver.init(backend, options)
..cacheReader = ..cacheReader =
BuildCacheReader(buildStep, findsLocalElementsReliably: true); BuildCacheReader(buildStep, findsLocalElementsReliably: true);

View File

@ -1,5 +1,6 @@
import 'package:build/build.dart'; import 'package:build/build.dart';
import 'package:dart_style/dart_style.dart'; import 'package:dart_style/dart_style.dart';
import 'package:meta/meta.dart';
import 'package:pub_semver/pub_semver.dart'; import 'package:pub_semver/pub_semver.dart';
import '../../analysis/custom_result_class.dart'; import '../../analysis/custom_result_class.dart';
@ -102,7 +103,7 @@ class DriftBuilder extends Builder {
@override @override
Future<void> build(BuildStep buildStep) async { Future<void> build(BuildStep buildStep) async {
final run = _DriftBuildRun(options, generationMode, buildStep); final run = await _DriftBuildRun.init(options, generationMode, buildStep);
await run.run(); await run.run();
} }
} }
@ -133,18 +134,31 @@ class _DriftBuildRun {
Set<Uri> analyzedUris = {}; Set<Uri> analyzedUris = {};
bool _didPrintWarning = false; bool _didPrintWarning = false;
_DriftBuildRun(this.options, this.mode, this.buildStep) @visibleForTesting
: driver = DriftAnalysisDriver(DriftBuildBackend(buildStep), options) _DriftBuildRun(this.options, this.mode, this.buildStep, this.driver);
..cacheReader = BuildCacheReader(
buildStep, static Future<_DriftBuildRun> init(
// The discovery and analyzer builders will have emitted IR for DriftOptions options,
// every relevant file in a previous build step that this builder DriftGenerationMode mode,
// has a dependency on. BuildStep buildStep,
findsResolvedElementsReliably: ) async {
!mode.embeddedAnalyzer || options.hasDriftAnalyzer, return _DriftBuildRun(
findsLocalElementsReliably: options,
!mode.embeddedAnalyzer || options.hasDriftAnalyzer, 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 { Future<void> run() async {
await _warnAboutDeprecatedOptions(); await _warnAboutDeprecatedOptions();

View File

@ -21,7 +21,7 @@ Future<List<DriftElement>> extractDriftElementsFromDatabase(
final logger = Logger('extractDriftElementsFromDatabase'); final logger = Logger('extractDriftElementsFromDatabase');
final uri = Uri.parse('db.drift'); final uri = Uri.parse('db.drift');
final backend = _SingleFileNoAnalyzerBackend(logger, uri); final backend = _SingleFileNoAnalyzerBackend(logger, uri);
final driver = DriftAnalysisDriver( final driver = await DriftAnalysisDriver.init(
backend, backend,
DriftOptions.defaults( DriftOptions.defaults(
sqliteAnalysisOptions: SqliteAnalysisOptions( sqliteAnalysisOptions: SqliteAnalysisOptions(

View File

@ -209,7 +209,6 @@ class QueryWriter {
String code; String code;
switch (column.sqlType) { switch (column.sqlType) {
case ColumnGeopolyPolygonType():
case ColumnDriftType(): case ColumnDriftType():
final method = isNullable ? 'readNullable' : 'read'; final method = isNullable ? 'readNullable' : 'read';
code = 'row.$method<$rawDartType>($dartLiteral)'; code = 'row.$method<$rawDartType>($dartLiteral)';

View File

@ -345,7 +345,6 @@ class RowMappingWriter {
final String sqlType; final String sqlType;
switch (column.sqlType) { switch (column.sqlType) {
case ColumnDriftType(): case ColumnDriftType():
case ColumnGeopolyPolygonType():
sqlType = writer.drift(column.sqlType.builtin.toString()); sqlType = writer.drift(column.sqlType.builtin.toString());
case ColumnCustomType(:final custom): case ColumnCustomType(:final custom):
sqlType = writer.dartCode(custom.expression); sqlType = writer.dartCode(custom.expression);

View File

@ -213,7 +213,6 @@ abstract class TableOrViewWriter {
switch (column.sqlType) { switch (column.sqlType) {
case ColumnDriftType(): case ColumnDriftType():
case ColumnGeopolyPolygonType():
additionalParams['type'] = additionalParams['type'] =
emitter.drift(column.sqlType.builtin.toString()); emitter.drift(column.sqlType.builtin.toString());
case ColumnCustomType(:final custom): case ColumnCustomType(:final custom):

View File

@ -147,7 +147,6 @@ abstract class _NodeOrWriter {
switch (converter.sqlType) { switch (converter.sqlType) {
case ColumnDriftType(): case ColumnDriftType():
case ColumnGeopolyPolygonType():
sqlDartType = sqlDartType =
AnnotatedDartCode([dartTypeNames[converter.sqlType.builtin]!]); AnnotatedDartCode([dartTypeNames[converter.sqlType.builtin]!]);
case ColumnCustomType(:final custom): case ColumnCustomType(:final custom):
@ -209,8 +208,6 @@ abstract class _NodeOrWriter {
AnnotatedDartCode innerColumnType(ColumnType type, {bool nullable = false}) { AnnotatedDartCode innerColumnType(ColumnType type, {bool nullable = false}) {
return AnnotatedDartCode.build((b) { return AnnotatedDartCode.build((b) {
switch (type) { switch (type) {
case ColumnGeopolyPolygonType(:final dartType):
b.addTopLevel(dartType);
case ColumnDriftType(): case ColumnDriftType():
b.addTopLevel(dartTypeNames[type.builtin]!); b.addTopLevel(dartTypeNames[type.builtin]!);
case ColumnCustomType(:final custom): case ColumnCustomType(:final custom):
@ -247,7 +244,6 @@ abstract class _NodeOrWriter {
switch (column.sqlType) { switch (column.sqlType) {
case ColumnDriftType(): case ColumnDriftType():
case ColumnGeopolyPolygonType():
break; break;
case ColumnCustomType(:final custom): case ColumnCustomType(:final custom):
// Also specify the custom type since it can't be inferred from the // Also specify the custom type since it can't be inferred from the

View File

@ -8,7 +8,7 @@ import 'test_utils.dart';
void main() { void main() {
test('handles cyclic imports', () async { test('handles cyclic imports', () async {
final state = TestBackend.inTest({ final state = await TestBackend.inTest({
'a|lib/entry.dart': ''' 'a|lib/entry.dart': '''
import 'package:drift/drift.dart'; import 'package:drift/drift.dart';
@ -42,7 +42,7 @@ CREATE TABLE bars (
group("reports error when an import can't be found", () { group("reports error when an import can't be found", () {
for (final extension in const ['drift', 'moor']) { for (final extension in const ['drift', 'moor']) {
test('in $extension files', () async { test('in $extension files', () async {
final backend = TestBackend.inTest({ final backend = await TestBackend.inTest({
'a|lib/a.$extension': ''' 'a|lib/a.$extension': '''
import 'b.$extension'; import 'b.$extension';
''', ''',
@ -56,7 +56,7 @@ import 'b.$extension';
} }
test('in a dart file', () async { test('in a dart file', () async {
final backend = TestBackend.inTest({ final backend = await TestBackend.inTest({
'a|lib/a.dart': ''' 'a|lib/a.dart': '''
import 'package:drift/drift.dart'; import 'package:drift/drift.dart';
@ -74,7 +74,7 @@ class Database {
}); });
test('resolves tables and queries', () async { test('resolves tables and queries', () async {
final backend = TestBackend.inTest({ final backend = await TestBackend.inTest({
'a|lib/database.dart': r''' 'a|lib/database.dart': r'''
import 'package:drift/drift.dart'; import 'package:drift/drift.dart';
@ -178,7 +178,7 @@ class ProgrammingLanguages extends Table {
}); });
test('still supports .moor files', () async { test('still supports .moor files', () async {
final state = TestBackend.inTest({ final state = await TestBackend.inTest({
'a|lib/main.dart': ''' 'a|lib/main.dart': '''
import 'package:drift/drift.dart'; import 'package:drift/drift.dart';
@ -203,7 +203,7 @@ CREATE TABLE users (
}); });
test('supports multiple references between same entities', () async { test('supports multiple references between same entities', () async {
final state = TestBackend.inTest({ final state = await TestBackend.inTest({
'a|lib/a.dart': ''' 'a|lib/a.dart': '''
import 'package:drift/drift.dart'; import 'package:drift/drift.dart';
@ -231,7 +231,7 @@ class ThisTable extends Table {
}); });
test('supports references across files', () async { test('supports references across files', () async {
final state = TestBackend.inTest({ final state = await TestBackend.inTest({
'a|lib/this_table.dart': ''' 'a|lib/this_table.dart': '''
import 'package:drift/drift.dart'; import 'package:drift/drift.dart';
@ -272,7 +272,7 @@ class OtherTable extends Table {
}); });
test('reports sensible error for missing table', () async { test('reports sensible error for missing table', () async {
final state = TestBackend.inTest({ final state = await TestBackend.inTest({
'a|lib/a.drift': ''' 'a|lib/a.drift': '''
getCompanyCustomersCount: getCompanyCustomersCount:
SELECT COUNT(*) AS "count" SELECT COUNT(*) AS "count"

View File

@ -75,7 +75,7 @@ sqlite:
}); });
test('reports error about table when module is not imported', () async { 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;', 'a|lib/a.drift': 'CREATE VIRTUAL TABLE place_spellfix USING spellfix1;',
}); });

View File

@ -5,7 +5,7 @@ import 'test_utils.dart';
void main() { void main() {
test('finds dart expressions', () async { test('finds dart expressions', () async {
final backend = TestBackend.inTest({ final backend = await TestBackend.inTest({
'a|lib/main.drift': ''' 'a|lib/main.drift': '''
import 'foo.dart'; import 'foo.dart';
@ -26,7 +26,7 @@ var expr_0 = const MyConverter();
test('only includes direct imports if no Dart expressions are used', test('only includes direct imports if no Dart expressions are used',
() async { () async {
final backend = TestBackend.inTest({ final backend = await TestBackend.inTest({
'a|lib/main.drift': ''' 'a|lib/main.drift': '''
import 'foo.dart'; import 'foo.dart';
import '2.drift'; import '2.drift';
@ -48,7 +48,7 @@ import 'bar.dart';
}); });
test('finds nested dart imports', () async { test('finds nested dart imports', () async {
final backend = TestBackend.inTest({ final backend = await TestBackend.inTest({
'a|lib/a.drift': ''' 'a|lib/a.drift': '''
import 'b.drift'; import 'b.drift';
@ -72,7 +72,7 @@ import 'import.dart';
}); });
test('does not throw for invalid import', () async { test('does not throw for invalid import', () async {
final backend = TestBackend.inTest({ final backend = await TestBackend.inTest({
'a|lib/a.drift': ''' 'a|lib/a.drift': '''
import 'b.drift'; import 'b.drift';
import 'does_not_exist.drift'; import 'does_not_exist.drift';
@ -96,8 +96,8 @@ import 'c.drift';
expect(result.temporaryDartFile, isNot(contains('import'))); expect(result.temporaryDartFile, isNot(contains('import')));
}); });
test('throws if entrypoint does not exist', () { test('throws if entrypoint does not exist', () async {
final backend = TestBackend.inTest({}); final backend = await TestBackend.inTest({});
expect( expect(
() => () =>
@ -106,8 +106,8 @@ import 'c.drift';
); );
}); });
test('throws if entrypoint is invalid', () { test('throws if entrypoint is invalid', () async {
final backend = TestBackend.inTest({ final backend = await TestBackend.inTest({
'a|lib/main.drift': '! this not a valid drift file !', 'a|lib/main.drift': '! this not a valid drift file !',
}); });

View File

@ -6,7 +6,7 @@ import 'test_utils.dart';
void main() { void main() {
test('analyzes views referencing Dart tables', () async { test('analyzes views referencing Dart tables', () async {
final state = TestBackend.inTest({ final state = await TestBackend.inTest({
'a|lib/db.dart': ''' 'a|lib/db.dart': '''
import 'package:drift/drift.dart'; import 'package:drift/drift.dart';
import 'dart:io'; import 'dart:io';

View File

@ -5,7 +5,7 @@ import 'test_utils.dart';
void main() { void main() {
test('gracefully handles daos with invalid types', () async { test('gracefully handles daos with invalid types', () async {
final state = TestBackend.inTest({ final state = await TestBackend.inTest({
'a|lib/bar.dart': ''' 'a|lib/bar.dart': '''
import 'package:drift/drift.dart'; import 'package:drift/drift.dart';

View File

@ -8,7 +8,7 @@ import '../../test_utils.dart';
void main() { void main() {
group('reports a warning', () { group('reports a warning', () {
test('when the table is not a class type', () async { test('when the table is not a class type', () async {
final state = TestBackend.inTest( final state = await TestBackend.inTest(
{ {
'a|lib/main.dart': ''' 'a|lib/main.dart': '''
import 'package:drift/drift.dart'; import 'package:drift/drift.dart';
@ -26,7 +26,7 @@ class Foo extends Table {
}); });
test('when the column is not a symbol literal', () async { test('when the column is not a symbol literal', () async {
final state = TestBackend.inTest( final state = await TestBackend.inTest(
{ {
'a|lib/main.dart': ''' 'a|lib/main.dart': '''
import 'package:drift/drift.dart'; import 'package:drift/drift.dart';
@ -48,7 +48,7 @@ class Foo extends Table {
}); });
test('includes referenced table in database', () async { test('includes referenced table in database', () async {
final state = TestBackend.inTest( final state = await TestBackend.inTest(
{ {
'a|lib/main.dart': ''' 'a|lib/main.dart': '''
import 'package:drift/drift.dart'; import 'package:drift/drift.dart';
@ -78,7 +78,7 @@ class Database {}
}); });
test('when the referenced column does not exist', () async { test('when the referenced column does not exist', () async {
final state = TestBackend.inTest( final state = await TestBackend.inTest(
{ {
'a|lib/main.dart': ''' 'a|lib/main.dart': '''
import 'package:drift/drift.dart'; import 'package:drift/drift.dart';
@ -106,7 +106,7 @@ class Database {}
}); });
test('resolves reference', () async { test('resolves reference', () async {
final state = TestBackend.inTest( final state = await TestBackend.inTest(
{ {
'a|lib/main.dart': ''' 'a|lib/main.dart': '''
import 'package:drift/drift.dart'; import 'package:drift/drift.dart';
@ -149,7 +149,7 @@ class Database {}
}); });
test('resolves self-references', () async { test('resolves self-references', () async {
final state = TestBackend.inTest( final state = await TestBackend.inTest(
{ {
'a|lib/main.dart': ''' 'a|lib/main.dart': '''
import 'package:drift/drift.dart'; import 'package:drift/drift.dart';

View File

@ -9,7 +9,7 @@ void main() {
test( test(
'It should rename the table and column name to its snake case version by default', 'It should rename the table and column name to its snake case version by default',
() async { () async {
final state = TestBackend.inTest( final state = await TestBackend.inTest(
{ {
'a|lib/main.dart': ''' 'a|lib/main.dart': '''
import 'package:drift/drift.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', test('It should rename the table and column name to its snake case version',
() async { () async {
final state = TestBackend.inTest( final state = await TestBackend.inTest(
{ {
'a|lib/main.dart': ''' 'a|lib/main.dart': '''
import 'package:drift/drift.dart'; import 'package:drift/drift.dart';
@ -64,7 +64,7 @@ class Database {}
}); });
test('It should not rename the table and column name', () async { test('It should not rename the table and column name', () async {
final state = TestBackend.inTest( final state = await TestBackend.inTest(
{ {
'a|lib/main.dart': ''' 'a|lib/main.dart': '''
import 'package:drift/drift.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', test('It should rename the table and column name to its camel case version',
() async { () async {
final state = TestBackend.inTest( final state = await TestBackend.inTest(
{ {
'a|lib/main.dart': ''' 'a|lib/main.dart': '''
import 'package:drift/drift.dart'; import 'package:drift/drift.dart';
@ -122,7 +122,7 @@ class Database {}
test( test(
'It should rename the table and column name to its constant case version', 'It should rename the table and column name to its constant case version',
() async { () async {
final state = TestBackend.inTest( final state = await TestBackend.inTest(
{ {
'a|lib/main.dart': ''' 'a|lib/main.dart': '''
import 'package:drift/drift.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', test('It should rename the table and column name to its pascal case version',
() async { () async {
final state = TestBackend.inTest( final state = await TestBackend.inTest(
{ {
'a|lib/main.dart': ''' 'a|lib/main.dart': '''
import 'package:drift/drift.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', test('It should rename the table and column name to its lower case version',
() async { () async {
final state = TestBackend.inTest( final state = await TestBackend.inTest(
{ {
'a|lib/main.dart': ''' 'a|lib/main.dart': '''
import 'package:drift/drift.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', test('It should rename the table and column name to its upper case version',
() async { () async {
final state = TestBackend.inTest( final state = await TestBackend.inTest(
{ {
'a|lib/main.dart': ''' 'a|lib/main.dart': '''
import 'package:drift/drift.dart'; import 'package:drift/drift.dart';
@ -235,7 +235,7 @@ class Database {}
}); });
test('recognizes custom column types', () async { test('recognizes custom column types', () async {
final state = TestBackend.inTest({ final state = await TestBackend.inTest({
'a|lib/main.dart': ''' 'a|lib/main.dart': '''
import 'package:drift/drift.dart'; import 'package:drift/drift.dart';
@ -256,7 +256,6 @@ class TestTable extends Table {
expect(column.sqlType.builtin, DriftSqlType.any); expect(column.sqlType.builtin, DriftSqlType.any);
switch (column.sqlType) { switch (column.sqlType) {
case ColumnDriftType(): case ColumnDriftType():
case ColumnGeopolyPolygonType():
break; break;
case ColumnCustomType(:final custom): case ColumnCustomType(:final custom):
expect(custom.dartType.toString(), 'List<String>'); expect(custom.dartType.toString(), 'List<String>');
@ -266,7 +265,7 @@ class TestTable extends Table {
group('customConstraint analysis', () { group('customConstraint analysis', () {
test('reports errors', () async { test('reports errors', () async {
final state = TestBackend.inTest({ final state = await TestBackend.inTest({
'a|lib/a.dart': ''' 'a|lib/a.dart': '''
import 'package:drift/drift.dart'; import 'package:drift/drift.dart';
@ -285,7 +284,7 @@ class TestTable extends Table {
}); });
test('resolves foreign key references', () async { test('resolves foreign key references', () async {
final state = TestBackend.inTest({ final state = await TestBackend.inTest({
'a|lib/a.dart': ''' 'a|lib/a.dart': '''
import 'package:drift/drift.dart'; import 'package:drift/drift.dart';
@ -326,7 +325,7 @@ class TestTable extends Table {
}); });
test('warns about missing `NOT NULL`', () async { test('warns about missing `NOT NULL`', () async {
final state = TestBackend.inTest({ final state = await TestBackend.inTest({
'a|lib/a.dart': ''' 'a|lib/a.dart': '''
import 'package:drift/drift.dart'; import 'package:drift/drift.dart';
@ -345,7 +344,7 @@ class TestTable extends Table {
}); });
test('applies constraints', () async { test('applies constraints', () async {
final state = TestBackend.inTest({ final state = await TestBackend.inTest({
'a|lib/a.dart': ''' 'a|lib/a.dart': '''
import 'package:drift/drift.dart'; import 'package:drift/drift.dart';

View File

@ -7,8 +7,8 @@ import '../../test_utils.dart';
void main() { void main() {
late TestBackend state; late TestBackend state;
setUpAll(() { setUpAll(() async {
state = TestBackend(const { state = await TestBackend.init(const {
'a|lib/invalid_no_unnamed_constructor.dart': ''' 'a|lib/invalid_no_unnamed_constructor.dart': '''
import 'package:drift/drift.dart'; import 'package:drift/drift.dart';
@ -408,7 +408,7 @@ class Companies extends Table {
}); });
test('handles `ANY` columns', () async { test('handles `ANY` columns', () async {
final backend = TestBackend.inTest({ final backend = await TestBackend.inTest({
'a|lib/a.drift': ''' 'a|lib/a.drift': '''
import 'row.dart'; import 'row.dart';
@ -528,7 +528,7 @@ class FooData {
group('records as row types', () { group('records as row types', () {
test('supported with explicit record', () async { test('supported with explicit record', () async {
final state = TestBackend.inTest( final state = await TestBackend.inTest(
{ {
'a|lib/a.dart': ''' 'a|lib/a.dart': '''
import 'package:drift/drift.dart'; import 'package:drift/drift.dart';
@ -562,7 +562,7 @@ class Users extends Table {
}); });
test('supported with implicit record', () async { test('supported with implicit record', () async {
final state = TestBackend.inTest( final state = await TestBackend.inTest(
{ {
'a|lib/a.dart': ''' 'a|lib/a.dart': '''
import 'package:drift/drift.dart'; import 'package:drift/drift.dart';

View File

@ -7,7 +7,7 @@ void main() {
final mainUri = Uri.parse('package:a/main.dart'); final mainUri = Uri.parse('package:a/main.dart');
test('parses schema version getter', () async { test('parses schema version getter', () async {
final backend = TestBackend.inTest({ final backend = await TestBackend.inTest({
'a|lib/main.dart': r''' 'a|lib/main.dart': r'''
import 'package:drift/drift.dart'; import 'package:drift/drift.dart';
@ -27,7 +27,7 @@ class MyDatabase extends _$MyDatabase {
}); });
test('parses schema version field', () async { test('parses schema version field', () async {
final backend = TestBackend.inTest({ final backend = await TestBackend.inTest({
'a|lib/main.dart': r''' 'a|lib/main.dart': r'''
import 'package:drift/drift.dart'; import 'package:drift/drift.dart';
@ -47,7 +47,7 @@ class MyDatabase extends _$MyDatabase {
}); });
test('does not warn about missing tables parameter', () async { test('does not warn about missing tables parameter', () async {
final backend = TestBackend.inTest({ final backend = await TestBackend.inTest({
'a|lib/main.dart': r''' 'a|lib/main.dart': r'''
import 'package:drift/drift.dart'; import 'package:drift/drift.dart';
@ -69,7 +69,7 @@ class MyDatabase2 extends _$MyDatabase {
}); });
test('supports inheritance for daos', () async { test('supports inheritance for daos', () async {
final state = TestBackend.inTest({ final state = await TestBackend.inTest({
'a|lib/database.dart': r''' 'a|lib/database.dart': r'''
import 'package:drift/drift.dart'; import 'package:drift/drift.dart';
@ -115,7 +115,7 @@ class ProductsDao extends BaseProductsDao with _$ProductDaoMixin {
}); });
test('only includes duplicate elements once', () async { test('only includes duplicate elements once', () async {
final state = TestBackend.inTest({ final state = await TestBackend.inTest({
'a|lib/main.dart': ''' 'a|lib/main.dart': '''
import 'package:drift/drift.dart'; import 'package:drift/drift.dart';

View File

@ -9,7 +9,7 @@ void main() {
late TestBackend backend; late TestBackend backend;
setUpAll(() async { setUpAll(() async {
backend = TestBackend({ backend = await TestBackend.init({
'a|lib/main.dart': ''' 'a|lib/main.dart': '''
import 'package:drift/drift.dart'; import 'package:drift/drift.dart';

View File

@ -7,7 +7,7 @@ import '../../test_utils.dart';
void main() { void main() {
group('reports a warning', () { group('reports a warning', () {
test('when the table is not a class type', () async { test('when the table is not a class type', () async {
final backend = TestBackend.inTest({ final backend = await TestBackend.inTest({
'a|lib/main.dart': ''' 'a|lib/main.dart': '''
import 'package:drift/drift.dart'; import 'package:drift/drift.dart';
@ -29,7 +29,7 @@ class Foo extends Table {
}); });
test('when the table is not a symbol literal', () async { test('when the table is not a symbol literal', () async {
final backend = TestBackend.inTest({ final backend = await TestBackend.inTest({
'a|lib/main.dart': ''' 'a|lib/main.dart': '''
import 'package:drift/drift.dart'; import 'package:drift/drift.dart';
@ -54,7 +54,7 @@ class Foo extends Table {
}); });
test('when the referenced table does not exist', () async { test('when the referenced table does not exist', () async {
final backend = TestBackend.inTest({ final backend = await TestBackend.inTest({
'a|lib/main.dart': ''' 'a|lib/main.dart': '''
import 'package:drift/drift.dart'; import 'package:drift/drift.dart';
@ -83,7 +83,7 @@ class Foo extends Table {
}); });
test('resolves reference', () async { test('resolves reference', () async {
final backend = TestBackend.inTest({ final backend = await TestBackend.inTest({
'a|lib/main.dart': ''' 'a|lib/main.dart': '''
import 'package:drift/drift.dart'; import 'package:drift/drift.dart';
@ -116,7 +116,7 @@ class Foo extends Table {
}); });
test('resolves self-references', () async { test('resolves self-references', () async {
final backend = TestBackend.inTest({ final backend = await TestBackend.inTest({
'a|lib/main.dart': ''' 'a|lib/main.dart': '''
import 'package:drift/drift.dart'; import 'package:drift/drift.dart';

View File

@ -5,7 +5,7 @@ import '../../test_utils.dart';
void main() { void main() {
test('resolves index', () async { test('resolves index', () async {
final backend = TestBackend.inTest({ final backend = await TestBackend.inTest({
'a|lib/a.dart': ''' 'a|lib/a.dart': '''
import 'package:drift/drift.dart'; import 'package:drift/drift.dart';
@ -41,7 +41,7 @@ class MyTable extends Table {
}); });
test('warns about missing columns', () async { test('warns about missing columns', () async {
final backend = TestBackend.inTest({ final backend = await TestBackend.inTest({
'a|lib/a.dart': ''' 'a|lib/a.dart': '''
import 'package:drift/drift.dart'; import 'package:drift/drift.dart';

View File

@ -7,7 +7,7 @@ import '../../test_utils.dart';
void main() { void main() {
test('warns about invalid column', () async { test('warns about invalid column', () async {
final backend = TestBackend.inTest({ final backend = await TestBackend.inTest({
'a|lib/main.dart': ''' 'a|lib/main.dart': '''
import 'package:drift/drift.dart'; import 'package:drift/drift.dart';

View File

@ -4,7 +4,7 @@ import '../../test_utils.dart';
void main() { void main() {
test('can define abstract tables', () async { test('can define abstract tables', () async {
final test = TestBackend.inTest({ final test = await TestBackend.inTest({
'a|lib/main.dart': ''' 'a|lib/main.dart': '''
import 'package:drift/drift.dart'; import 'package:drift/drift.dart';

View File

@ -11,8 +11,8 @@ void main() {
late TestBackend backend; late TestBackend backend;
late FileState state; late FileState state;
setUpAll(() { setUpAll(() async {
backend = TestBackend({ backend = await TestBackend.init({
'a|lib/main.dart': r''' 'a|lib/main.dart': r'''
import 'package:drift/drift.dart'; import 'package:drift/drift.dart';

View File

@ -8,8 +8,8 @@ import '../../test_utils.dart';
void main() { void main() {
late TestBackend backend; late TestBackend backend;
setUpAll(() { setUpAll(() async {
backend = TestBackend({ backend = await TestBackend.init({
'a|lib/main.dart': ''' 'a|lib/main.dart': '''
import 'package:drift/drift.dart'; import 'package:drift/drift.dart';
@ -335,7 +335,7 @@ class Pianos extends Table {
}); });
test('reads custom constraints from table', () async { test('reads custom constraints from table', () async {
final backend = TestBackend.inTest({ final backend = await TestBackend.inTest({
'a|lib/a.dart': ''' 'a|lib/a.dart': '''
import 'package:drift/drift.dart'; import 'package:drift/drift.dart';
@ -377,7 +377,7 @@ class WithConstraints extends Table {
}); });
test('warns about foreign key references from customConstraints', () async { test('warns about foreign key references from customConstraints', () async {
final backend = TestBackend.inTest({ final backend = await TestBackend.inTest({
'a|lib/a.dart': ''' 'a|lib/a.dart': '''
import 'package:drift/drift.dart'; import 'package:drift/drift.dart';
@ -410,7 +410,7 @@ class WithConstraints extends Table {
}); });
test('can resolve references from import', () async { test('can resolve references from import', () async {
final backend = TestBackend.inTest({ final backend = await TestBackend.inTest({
'a|lib/topic.dart': ''' 'a|lib/topic.dart': '''
import 'package:drift/drift.dart'; import 'package:drift/drift.dart';
@ -452,7 +452,7 @@ class Videos extends Table {
}); });
test('supports autoIncrement on int64 columns', () async { test('supports autoIncrement on int64 columns', () async {
final backend = TestBackend.inTest({ final backend = await TestBackend.inTest({
'a|lib/a.dart': ''' 'a|lib/a.dart': '''
import 'package:drift/drift.dart'; import 'package:drift/drift.dart';

View File

@ -6,8 +6,8 @@ import '../../test_utils.dart';
void main() { void main() {
late TestBackend state; late TestBackend state;
setUp(() { setUp(() async {
state = TestBackend({ state = await TestBackend.init({
'a|lib/json.dart': ''' 'a|lib/json.dart': '''
import 'package:drift/drift.dart'; import 'package:drift/drift.dart';

View File

@ -7,7 +7,7 @@ void main() {
final mainUri = Uri.parse('package:a/main.dart'); final mainUri = Uri.parse('package:a/main.dart');
test('does not allow autoIncrement() to have a unique constraint', () async { test('does not allow autoIncrement() to have a unique constraint', () async {
final backend = TestBackend.inTest({ final backend = await TestBackend.inTest({
'a|lib/main.dart': ''' 'a|lib/main.dart': '''
import 'package:drift/drift.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 { 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': ''' 'a|lib/main.dart': '''
import 'package:drift/drift.dart'; import 'package:drift/drift.dart';
@ -55,7 +55,7 @@ class Test extends Table {
test( test(
'does not allow primary key to have a unique constraint through override', 'does not allow primary key to have a unique constraint through override',
() async { () async {
final backend = TestBackend.inTest({ final backend = await TestBackend.inTest({
'a|lib/main.dart': ''' 'a|lib/main.dart': '''
import 'package:drift/drift.dart'; import 'package:drift/drift.dart';
@ -84,7 +84,7 @@ class Test extends Table {
}); });
test('warns about duplicate unique declarations', () async { test('warns about duplicate unique declarations', () async {
final backend = TestBackend.inTest({ final backend = await TestBackend.inTest({
'a|lib/main.dart': ''' 'a|lib/main.dart': '''
import 'package:drift/drift.dart'; import 'package:drift/drift.dart';
@ -108,7 +108,7 @@ class Test extends Table {
}); });
test('parses unique key definitions', () async { test('parses unique key definitions', () async {
final backend = TestBackend.inTest({ final backend = await TestBackend.inTest({
'a|lib/main.dart': ''' 'a|lib/main.dart': '''
import 'package:drift/drift.dart'; import 'package:drift/drift.dart';

View File

@ -6,7 +6,7 @@ import '../../test_utils.dart';
void main() { void main() {
test('can analyze Dart view', () async { test('can analyze Dart view', () async {
final backend = TestBackend.inTest({ final backend = await TestBackend.inTest({
'a|lib/main.dart': ''' 'a|lib/main.dart': '''
import 'package:drift/drift.dart'; import 'package:drift/drift.dart';

View File

@ -8,7 +8,7 @@ import '../test_utils.dart';
void main() { void main() {
group('drift files', () { group('drift files', () {
test('finds local elements', () async { test('finds local elements', () async {
final backend = TestBackend.inTest({ final backend = await TestBackend.inTest({
'a|lib/main.drift': ''' 'a|lib/main.drift': '''
CREATE TABLE foo (bar INTEGER); CREATE TABLE foo (bar INTEGER);
@ -41,7 +41,7 @@ CREATE VIEW my_view AS SELECT whatever FROM unknown_table;
}); });
test('reports syntax errors', () async { test('reports syntax errors', () async {
final backend = TestBackend.inTest({ final backend = await TestBackend.inTest({
'a|lib/main.drift': ''' 'a|lib/main.drift': '''
CREATE TABLE valid_1 (bar INTEGER); CREATE TABLE valid_1 (bar INTEGER);
@ -64,7 +64,7 @@ CREATE TABLE valid_2 (bar INTEGER);
}); });
test('warns about duplicate elements', () async { test('warns about duplicate elements', () async {
final backend = TestBackend.inTest({ final backend = await TestBackend.inTest({
'a|lib/main.drift': ''' 'a|lib/main.drift': '''
CREATE TABLE a (id INTEGER); CREATE TABLE a (id INTEGER);
CREATE VIEW a AS VALUES(1,2,3); CREATE VIEW a AS VALUES(1,2,3);
@ -82,7 +82,7 @@ CREATE VIEW a AS VALUES(1,2,3);
group('imports', () { group('imports', () {
test('are resolved', () async { test('are resolved', () async {
final backend = TestBackend.inTest({ final backend = await TestBackend.inTest({
'a|lib/a.drift': "import 'b.drift';", 'a|lib/a.drift': "import 'b.drift';",
'a|lib/b.drift': "CREATE TABLE foo (bar INTEGER);", '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 { 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/a.drift': "import 'a.drift'; import 'b.drift';",
'a|lib/b.drift': "import 'a.drift';", 'a|lib/b.drift': "import 'a.drift';",
}); });
@ -119,7 +119,7 @@ CREATE VIEW a AS VALUES(1,2,3);
group('dart files', () { group('dart files', () {
test('fails for part files', () async { test('fails for part files', () async {
final backend = TestBackend.inTest({ final backend = await TestBackend.inTest({
'a|lib/a.dart': ''' 'a|lib/a.dart': '''
part of 'b.dart'; part of 'b.dart';
''', ''',
@ -136,7 +136,7 @@ part 'a.dart';
}); });
test('finds tables', () async { test('finds tables', () async {
final backend = TestBackend.inTest({ final backend = await TestBackend.inTest({
'a|lib/a.dart': ''' 'a|lib/a.dart': '''
import 'package:drift/drift.dart'; import 'package:drift/drift.dart';
@ -172,7 +172,7 @@ class Groups extends Table {
}); });
test('ignores abstract tables', () async { test('ignores abstract tables', () async {
final backend = TestBackend.inTest({ final backend = await TestBackend.inTest({
'a|lib/a.dart': ''' 'a|lib/a.dart': '''
import 'package:drift/drift.dart'; import 'package:drift/drift.dart';
@ -208,7 +208,7 @@ abstract class BaseRelationTable extends Table {
}); });
test('table name errors', () async { test('table name errors', () async {
final backend = TestBackend.inTest({ final backend = await TestBackend.inTest({
'a|lib/expr.dart': ''' 'a|lib/expr.dart': '''
import 'package:drift/drift.dart'; import 'package:drift/drift.dart';
@ -239,7 +239,7 @@ class InvalidGetter extends Table {
}); });
test('warns about duplicate elements', () async { test('warns about duplicate elements', () async {
final backend = TestBackend.inTest({ final backend = await TestBackend.inTest({
'a|lib/a.dart': ''' 'a|lib/a.dart': '''
import 'package:drift/drift.dart'; import 'package:drift/drift.dart';

View File

@ -8,7 +8,7 @@ import '../../test_utils.dart';
void main() { void main() {
test('view created', () async { test('view created', () async {
final state = TestBackend.inTest({ final state = await TestBackend.inTest({
'foo|lib/table.drift': ''' 'foo|lib/table.drift': '''
CREATE TABLE t (id INTEGER NOT NULL PRIMARY KEY, name TEXT NOT NULL); 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 { test('view created from another view', () async {
final state = TestBackend.inTest({ final state = await TestBackend.inTest({
'foo|lib/table.drift': ''' 'foo|lib/table.drift': '''
CREATE TABLE t (id INTEGER NOT NULL PRIMARY KEY, name TEXT NOT NULL); CREATE TABLE t (id INTEGER NOT NULL PRIMARY KEY, name TEXT NOT NULL);
''', ''',
@ -68,7 +68,7 @@ void main() {
}); });
test('view without table', () async { test('view without table', () async {
final state = TestBackend.inTest({ final state = await TestBackend.inTest({
'foo|lib/a.drift': ''' 'foo|lib/a.drift': '''
CREATE VIEW random_view AS CREATE VIEW random_view AS
SELECT name FROM t WHERE id % 2 = 0; SELECT name FROM t WHERE id % 2 = 0;
@ -82,7 +82,7 @@ void main() {
}); });
test('does not allow nested columns', () async { test('does not allow nested columns', () async {
final state = TestBackend.inTest({ final state = await TestBackend.inTest({
'foo|lib/a.drift': ''' 'foo|lib/a.drift': '''
CREATE TABLE foo (bar INTEGER NOT NULL PRIMARY KEY); CREATE TABLE foo (bar INTEGER NOT NULL PRIMARY KEY);
@ -102,7 +102,7 @@ void main() {
test('imported views are analyzed', () async { test('imported views are analyzed', () async {
// Regression test for https://github.com/simolus3/drift/issues/1639 // Regression test for https://github.com/simolus3/drift/issues/1639
final testState = TestBackend.inTest({ final testState = await TestBackend.inTest({
'a|lib/imported.drift': ''' 'a|lib/imported.drift': '''
CREATE TABLE a ( CREATE TABLE a (
b TEXT NOT NULL b TEXT NOT NULL
@ -124,7 +124,7 @@ query: SELECT * FROM my_view;
}); });
test('picks valid Dart names for columns', () async { test('picks valid Dart names for columns', () async {
final testState = TestBackend.inTest({ final testState = await TestBackend.inTest({
'a|lib/a.drift': ''' 'a|lib/a.drift': '''
CREATE VIEW IF NOT EXISTS repro AS CREATE VIEW IF NOT EXISTS repro AS
SELECT 1, SELECT 1,
@ -148,7 +148,7 @@ CREATE VIEW IF NOT EXISTS repro AS
}); });
test('copies type converter from table', () async { test('copies type converter from table', () async {
final backend = TestBackend.inTest({ final backend = await TestBackend.inTest({
'a|lib/a.drift': ''' 'a|lib/a.drift': '''
import 'converter.dart'; import 'converter.dart';
@ -185,7 +185,7 @@ TypeConverter<Object, int> createConverter() => throw UnimplementedError();
}); });
test('can declare type converter on view column', () async { test('can declare type converter on view column', () async {
final backend = TestBackend.inTest({ final backend = await TestBackend.inTest({
'a|lib/a.drift': ''' 'a|lib/a.drift': '''
import 'converter.dart'; import 'converter.dart';
@ -223,7 +223,7 @@ TypeConverter<Object, int> createConverter() => throw UnimplementedError();
}); });
test('supports enum columns', () async { test('supports enum columns', () async {
final backend = TestBackend.inTest({ final backend = await TestBackend.inTest({
'a|lib/a.drift': ''' 'a|lib/a.drift': '''
import 'enums.dart'; import 'enums.dart';
@ -280,7 +280,7 @@ enum MyEnum {
String expectedSql, String expectedSql,
DriftOptions options, DriftOptions options,
) async { ) async {
final backend = TestBackend.inTest( final backend = await TestBackend.inTest(
{'a|lib/a.drift': definition}, {'a|lib/a.drift': definition},
options: options, options: options,
); );

View File

@ -6,7 +6,7 @@ import '../../test_utils.dart';
void main() { void main() {
test('parse nested CTE', () async { test('parse nested CTE', () async {
final backend = TestBackend.inTest({ final backend = await TestBackend.inTest({
'a|lib/test.drift': ''' 'a|lib/test.drift': '''
test: test:
SELECT SELECT
@ -38,7 +38,7 @@ SELECT
}); });
test('recognizes CTE clause', () async { test('recognizes CTE clause', () async {
final backend = TestBackend.inTest({ final backend = await TestBackend.inTest({
'a|lib/test.drift': ''' 'a|lib/test.drift': '''
test: test:
WITH RECURSIVE WITH RECURSIVE
@ -70,7 +70,7 @@ WITH RECURSIVE
}); });
test('finds the underlying table when aliased through CTE', () async { test('finds the underlying table when aliased through CTE', () async {
final backend = TestBackend.inTest({ final backend = await TestBackend.inTest({
'a|lib/test.drift': ''' 'a|lib/test.drift': '''
CREATE TABLE foo ( CREATE TABLE foo (
id INT NOT NULL PRIMARY KEY AUTOINCREMENT, id INT NOT NULL PRIMARY KEY AUTOINCREMENT,

View File

@ -5,7 +5,7 @@ import '../../test_utils.dart';
void main() { void main() {
test('can use existing row classes in drift files', () async { test('can use existing row classes in drift files', () async {
final state = TestBackend.inTest({ final state = await TestBackend.inTest({
'a|lib/db.drift': ''' 'a|lib/db.drift': '''
import 'rows.dart'; import 'rows.dart';
@ -61,7 +61,7 @@ class ExistingForView {
}); });
test('can use generic row classes', () async { test('can use generic row classes', () async {
final state = TestBackend.inTest({ final state = await TestBackend.inTest({
'a|lib/generic.dart': ''' 'a|lib/generic.dart': '''
//@dart=2.13 //@dart=2.13
typedef StringRow = GenericRow<String>; typedef StringRow = GenericRow<String>;
@ -105,7 +105,7 @@ CREATE TABLE drift_ints (
group('can use records', () { group('can use records', () {
test('with explicit structure', () async { test('with explicit structure', () async {
final state = TestBackend.inTest({ final state = await TestBackend.inTest({
'a|lib/a.drift': ''' 'a|lib/a.drift': '''
import 'helper.dart'; import 'helper.dart';
@ -135,7 +135,7 @@ typedef MyRecord = ({String foo, int? bar});
}); });
test('implicitly', () async { test('implicitly', () async {
final state = TestBackend.inTest({ final state = await TestBackend.inTest({
'a|lib/a.drift': ''' 'a|lib/a.drift': '''
CREATE TABLE foo ( CREATE TABLE foo (
foo TEXT NOT NULL, foo TEXT NOT NULL,

View File

@ -5,7 +5,7 @@ import '../../test_utils.dart';
void main() { void main() {
test('reports an error when importing a part file into .drift', () async { 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': ''' 'a|lib/base.dart': '''
import 'package:drift/drift.dart'; import 'package:drift/drift.dart';

View File

@ -84,7 +84,7 @@ void main() {
test('integration tests with drift files and experimental inference', test('integration tests with drift files and experimental inference',
() async { () async {
final state = TestBackend.inTest( final state = await TestBackend.inTest(
const { const {
'foo|lib/a.drift': ''' 'foo|lib/a.drift': '''
CREATE TABLE numbers (foo REAL NOT NULL); CREATE TABLE numbers (foo REAL NOT NULL);

View File

@ -8,7 +8,7 @@ const _options = DriftOptions.defaults(modules: [SqlModule.fts5]);
void main() { void main() {
group('reports error', () { group('reports error', () {
test('for missing content table', () async { test('for missing content table', () async {
final state = TestBackend.inTest({ final state = await TestBackend.inTest({
'a|lib/main.drift': ''' 'a|lib/main.drift': '''
CREATE VIRTUAL TABLE fts USING fts5(a, c, content=tbl); 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 { test('for invalid rowid of content table', () async {
final state = TestBackend.inTest({ final state = await TestBackend.inTest({
'a|lib/main.drift': ''' 'a|lib/main.drift': '''
CREATE TABLE tbl (a, b, c, my_pk INTEGER PRIMARY KEY); 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 { test('when referencing an unknown column', () async {
final state = TestBackend.inTest({ final state = await TestBackend.inTest({
'a|lib/main.drift': ''' 'a|lib/main.drift': '''
CREATE TABLE tbl (a, b, c, d INTEGER PRIMARY KEY); 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 { test('finds referenced table', () async {
final state = TestBackend.inTest({ final state = await TestBackend.inTest({
'a|lib/main.drift': ''' 'a|lib/main.drift': '''
CREATE TABLE tbl (a, b, c, d INTEGER PRIMARY KEY); CREATE TABLE tbl (a, b, c, d INTEGER PRIMARY KEY);

View File

@ -5,7 +5,7 @@ import '../../test_utils.dart';
void main() { void main() {
test('drift files can import original dart source', () async { test('drift files can import original dart source', () async {
final state = TestBackend.inTest({ final state = await TestBackend.inTest({
'a|lib/base.dart': r''' 'a|lib/base.dart': r'''
import 'package:drift/drift.dart'; import 'package:drift/drift.dart';

View File

@ -8,7 +8,7 @@ import '../../test_utils.dart';
void main() { void main() {
// https://github.com/simolus3/drift/issues/2097#issuecomment-1273008383 // https://github.com/simolus3/drift/issues/2097#issuecomment-1273008383
test('virtual columns are not required for inserts', () async { test('virtual columns are not required for inserts', () async {
final state = TestBackend.inTest( final state = await TestBackend.inTest(
{ {
'foo|lib/a.drift': r''' 'foo|lib/a.drift': r'''
CREATE TABLE IF NOT EXISTS nodes ( CREATE TABLE IF NOT EXISTS nodes (

View File

@ -6,7 +6,7 @@ import '../../test_utils.dart';
void main() { void main() {
// Regression test for https://github.com/simolus3/drift/issues/754 // Regression test for https://github.com/simolus3/drift/issues/754
test('supports fts5 tables with external content', () async { test('supports fts5 tables with external content', () async {
final state = TestBackend.inTest({ final state = await TestBackend.inTest({
'foo|lib/a.drift': ''' 'foo|lib/a.drift': '''
CREATE TABLE tbl(a INTEGER PRIMARY KEY, b TEXT, c TEXT); 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'); CREATE VIRTUAL TABLE fts_idx USING fts5(b, c, content='tbl', content_rowid='a');

View File

@ -20,7 +20,7 @@ query: INSERT INTO foo VALUES (?, ?, ?)
void main() { void main() {
test('does not support newer sqlite features by default', () async { 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'); final file = await state.analyze('package:a/main.drift');
expect( expect(
@ -38,7 +38,7 @@ void main() {
}); });
test('supports newer sqlite features', () async { test('supports newer sqlite features', () async {
final state = TestBackend.inTest( final state = await TestBackend.inTest(
_content, _content,
options: const DriftOptions.defaults( options: const DriftOptions.defaults(
sqliteAnalysisOptions: SqliteAnalysisOptions( sqliteAnalysisOptions: SqliteAnalysisOptions(

View File

@ -14,7 +14,7 @@ enum Fruit {
void main() { void main() {
group('warns about invalid type converter value', () { group('warns about invalid type converter value', () {
test('in table definition', () async { test('in table definition', () async {
final backend = TestBackend.inTest({ final backend = await TestBackend.inTest({
'a|lib/a.drift': ''' 'a|lib/a.drift': '''
import 'enum.dart'; import 'enum.dart';
@ -38,7 +38,7 @@ CREATE TABLE a (
}); });
test('for query', () async { test('for query', () async {
final backend = TestBackend.inTest({ final backend = await TestBackend.inTest({
'a|lib/a.drift': ''' 'a|lib/a.drift': '''
import 'enum.dart'; import 'enum.dart';

View File

@ -8,7 +8,7 @@ import '../../test_utils.dart';
void main() { void main() {
test('reports foreign keys in drift model', () async { test('reports foreign keys in drift model', () async {
final backend = TestBackend.inTest({ final backend = await TestBackend.inTest({
'a|lib/a.drift': ''' 'a|lib/a.drift': '''
CREATE TABLE a ( CREATE TABLE a (
foo INTEGER PRIMARY KEY, foo INTEGER PRIMARY KEY,
@ -56,7 +56,7 @@ CREATE TABLE b (
}); });
test('recognizes aliases to rowid', () async { test('recognizes aliases to rowid', () async {
final state = TestBackend.inTest({ final state = await TestBackend.inTest({
'foo|lib/a.drift': ''' 'foo|lib/a.drift': '''
CREATE TABLE users ( CREATE TABLE users (
id INTEGER PRIMARY KEY, id INTEGER PRIMARY KEY,
@ -84,7 +84,7 @@ CREATE TABLE b (
}); });
test('parses enum columns', () async { test('parses enum columns', () async {
final state = TestBackend.inTest({ final state = await TestBackend.inTest({
'a|lib/a.drift': ''' 'a|lib/a.drift': '''
import 'enum.dart'; import 'enum.dart';
@ -168,7 +168,7 @@ CREATE TABLE b (
}); });
test('does not allow converters for enum columns', () async { test('does not allow converters for enum columns', () async {
final state = TestBackend.inTest({ final state = await TestBackend.inTest({
'a|lib/a.drift': ''' 'a|lib/a.drift': '''
import 'enum.dart'; import 'enum.dart';
@ -200,7 +200,7 @@ CREATE TABLE b (
}); });
test('does not allow enum types for non-enums', () async { test('does not allow enum types for non-enums', () async {
final state = TestBackend.inTest({ final state = await TestBackend.inTest({
'a|lib/a.drift': ''' 'a|lib/a.drift': '''
import 'enum.dart'; import 'enum.dart';
@ -223,7 +223,7 @@ CREATE TABLE b (
}); });
test('supports JSON KEY annotation', () async { test('supports JSON KEY annotation', () async {
final state = TestBackend.inTest({ final state = await TestBackend.inTest({
'a|lib/a.drift': ''' 'a|lib/a.drift': '''
CREATE TABLE waybills ( CREATE TABLE waybills (
parent INT JSON KEY parentDoc NULL, parent INT JSON KEY parentDoc NULL,
@ -244,7 +244,7 @@ CREATE TABLE waybills (
}); });
test('recognizes documentation comments', () async { test('recognizes documentation comments', () async {
final state = TestBackend.inTest({ final state = await TestBackend.inTest({
'a|lib/a.drift': ''' 'a|lib/a.drift': '''
CREATE TABLE IF NOT EXISTS currencies ( CREATE TABLE IF NOT EXISTS currencies (
-- The name of this currency -- The name of this currency
@ -266,7 +266,7 @@ CREATE TABLE IF NOT EXISTS currencies (
}); });
test('can use custom types', () async { test('can use custom types', () async {
final state = TestBackend.inTest({ final state = await TestBackend.inTest({
'a|lib/a.drift': ''' 'a|lib/a.drift': '''
import 'b.dart'; import 'b.dart';
@ -289,7 +289,6 @@ class MyType implements CustomSqlType<String> {}
switch (column.sqlType) { switch (column.sqlType) {
case ColumnDriftType(): case ColumnDriftType():
case ColumnGeopolyPolygonType():
fail('expect custom type'); fail('expect custom type');
case ColumnCustomType(:final custom): case ColumnCustomType(:final custom):
expect(custom.dartType.toString(), 'String'); expect(custom.dartType.toString(), 'String');

View File

@ -7,7 +7,7 @@ import '../../test_utils.dart';
void main() { void main() {
test('supports virtual tables across drift files', () async { test('supports virtual tables across drift files', () async {
final state = TestBackend.inTest( final state = await TestBackend.inTest(
{ {
'a|lib/table.drift': ''' 'a|lib/table.drift': '''
CREATE TABLE example_table ( CREATE TABLE example_table (
@ -43,7 +43,7 @@ exampleSearch: SELECT example_table.**, s.* FROM example_table
}); });
test('query virtual tables with unknown function', () async { test('query virtual tables with unknown function', () async {
final state = TestBackend.inTest( final state = await TestBackend.inTest(
{ {
'a|lib/table.drift': ''' 'a|lib/table.drift': '''
CREATE TABLE example_table ( CREATE TABLE example_table (
@ -72,7 +72,7 @@ SELECT rowid, highlight(example_table_search, 0, '[match]', '[match]') name,
}); });
test('supports spellfix1 tables', () async { test('supports spellfix1 tables', () async {
final state = TestBackend.inTest( final state = await TestBackend.inTest(
{'a|lib/a.drift': 'CREATE VIRTUAL TABLE demo USING spellfix1;'}, {'a|lib/a.drift': 'CREATE VIRTUAL TABLE demo USING spellfix1;'},
options: DriftOptions.defaults( options: DriftOptions.defaults(
dialect: DialectOptions( dialect: DialectOptions(

View File

@ -8,7 +8,7 @@ import '../../test_utils.dart';
void main() { void main() {
Future<Iterable<SqlQuery>> analyzeQueries(String driftFile) async { 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'); final result = await state.analyze('package:a/a.drift');
return result.fileAnalysis!.resolvedQueries.values; return result.fileAnalysis!.resolvedQueries.values;

View File

@ -8,7 +8,7 @@ import 'utils.dart';
void main() { void main() {
test('recognizes existing row classes', () async { test('recognizes existing row classes', () async {
final state = TestBackend.inTest({ final state = await TestBackend.inTest({
'a|lib/a.drift': ''' 'a|lib/a.drift': '''
import 'a.dart'; import 'a.dart';
@ -35,7 +35,7 @@ class MyRow {
}); });
test('can use named constructors', () async { test('can use named constructors', () async {
final state = TestBackend.inTest({ final state = await TestBackend.inTest({
'a|lib/a.drift': ''' 'a|lib/a.drift': '''
import 'a.dart'; import 'a.dart';
@ -75,7 +75,7 @@ class MyRow {
}); });
test("warns if existing row classes don't exist", () async { test("warns if existing row classes don't exist", () async {
final state = TestBackend.inTest({ final state = await TestBackend.inTest({
'a|lib/a.drift': ''' 'a|lib/a.drift': '''
import 'a.dart'; import 'a.dart';
@ -91,7 +91,7 @@ foo WITH MyRow: SELECT 'hello world', 2;
}); });
test('resolves existing row class', () async { test('resolves existing row class', () async {
final state = TestBackend.inTest({ final state = await TestBackend.inTest({
'a|lib/a.drift': ''' 'a|lib/a.drift': '''
import 'a.dart'; import 'a.dart';
@ -122,7 +122,7 @@ class MyRow {
group('matches', () { group('matches', () {
test('single column type', () async { test('single column type', () async {
final state = TestBackend.inTest({ final state = await TestBackend.inTest({
'a|lib/a.drift': ''' 'a|lib/a.drift': '''
foo WITH int: SELECT 1 AS r; foo WITH int: SELECT 1 AS r;
''', ''',
@ -139,7 +139,7 @@ foo WITH int: SELECT 1 AS r;
}); });
test('single table', () async { test('single table', () async {
final state = TestBackend.inTest({ final state = await TestBackend.inTest({
'a|lib/a.drift': ''' 'a|lib/a.drift': '''
import 'a.dart'; import 'a.dart';
@ -166,7 +166,7 @@ typedef MyRow = TblData;
}); });
test('single table with custom row class', () async { test('single table with custom row class', () async {
final state = TestBackend.inTest({ final state = await TestBackend.inTest({
'a|lib/a.drift': ''' 'a|lib/a.drift': '''
import 'a.dart'; import 'a.dart';
@ -195,7 +195,7 @@ class MyTableRow {
}); });
test('alternative to table class', () async { test('alternative to table class', () async {
final state = TestBackend.inTest({ final state = await TestBackend.inTest({
'a|lib/a.drift': ''' 'a|lib/a.drift': '''
import 'a.dart'; import 'a.dart';
@ -229,7 +229,7 @@ class MyQueryRow {
group('nested column', () { group('nested column', () {
test('single column into field', () async { test('single column into field', () async {
final state = TestBackend.inTest({ final state = await TestBackend.inTest({
'a|lib/a.drift': ''' 'a|lib/a.drift': '''
import 'a.dart'; import 'a.dart';
@ -263,7 +263,7 @@ class MyQueryRow {
}); });
test('single column into single-element record', () async { test('single column into single-element record', () async {
final state = TestBackend.inTest({ final state = await TestBackend.inTest({
'a|lib/a.drift': ''' 'a|lib/a.drift': '''
import 'a.dart'; import 'a.dart';
@ -298,7 +298,7 @@ class MyQueryRow {
}); });
test('custom result set', () async { test('custom result set', () async {
final state = TestBackend.inTest( final state = await TestBackend.inTest(
{ {
'a|lib/a.drift': ''' 'a|lib/a.drift': '''
import 'a.dart'; import 'a.dart';
@ -344,7 +344,7 @@ class JsonStructure {
}); });
test('table', () async { test('table', () async {
final state = TestBackend.inTest({ final state = await TestBackend.inTest({
'a|lib/a.drift': ''' 'a|lib/a.drift': '''
import 'a.dart'; import 'a.dart';
@ -382,7 +382,7 @@ class MyRow {
}); });
test('table as alternative to row class', () async { test('table as alternative to row class', () async {
final state = TestBackend.inTest( final state = await TestBackend.inTest(
{ {
'a|lib/a.drift': ''' 'a|lib/a.drift': '''
import 'a.dart'; import 'a.dart';
@ -425,7 +425,7 @@ class MyRow {
group('nested LIST query', () { group('nested LIST query', () {
test('single column type', () async { test('single column type', () async {
final state = TestBackend.inTest({ final state = await TestBackend.inTest({
'a|lib/a.drift': ''' 'a|lib/a.drift': '''
import 'a.dart'; import 'a.dart';
@ -461,7 +461,7 @@ class MyQueryRow {
}); });
test('custom result set with class', () async { test('custom result set with class', () async {
final state = TestBackend.inTest({ final state = await TestBackend.inTest({
'a|lib/a.drift': ''' 'a|lib/a.drift': '''
import 'a.dart'; import 'a.dart';
@ -503,7 +503,7 @@ class MyNestedTable {
}); });
test('custom result set with record', () async { test('custom result set with record', () async {
final state = TestBackend.inTest( final state = await TestBackend.inTest(
{ {
'a|lib/a.drift': ''' 'a|lib/a.drift': '''
import 'a.dart'; import 'a.dart';
@ -545,7 +545,7 @@ class MyRow {
}); });
test('into record', () async { test('into record', () async {
final state = TestBackend.inTest( final state = await TestBackend.inTest(
{ {
'a|lib/a.drift': ''' 'a|lib/a.drift': '''
import 'a.dart'; import 'a.dart';
@ -586,7 +586,7 @@ typedef MyRow = (int, List<TblData>);
test( test(
'default record', 'default record',
() async { () async {
final state = TestBackend.inTest( final state = await TestBackend.inTest(
{ {
'a|lib/a.drift': ''' 'a|lib/a.drift': '''
import 'a.dart'; 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 { test('mix', () async {
final state = TestBackend.inTest({ final state = await TestBackend.inTest({
'a|lib/a.drift': ''' 'a|lib/a.drift': '''
import 'a.dart'; import 'a.dart';
@ -685,7 +685,7 @@ class MyRow {
group('error', () { group('error', () {
test('when the specified class has no default constructor', () async { test('when the specified class has no default constructor', () async {
final state = TestBackend.inTest({ final state = await TestBackend.inTest({
'a|lib/a.drift': ''' 'a|lib/a.drift': '''
import 'a.dart'; import 'a.dart';
@ -705,7 +705,7 @@ class MyRow {
}); });
test('when the desired constructor does not exist', () async { test('when the desired constructor does not exist', () async {
final state = TestBackend.inTest({ final state = await TestBackend.inTest({
'a|lib/a.drift': ''' 'a|lib/a.drift': '''
import 'a.dart'; import 'a.dart';
@ -725,7 +725,7 @@ class MyRow {
}); });
test('when there is a parameter with no matching column', () async { test('when there is a parameter with no matching column', () async {
final state = TestBackend.inTest({ final state = await TestBackend.inTest({
'a|lib/a.drift': ''' 'a|lib/a.drift': '''
import 'a.dart'; import 'a.dart';
@ -745,7 +745,7 @@ class MyRow {
}); });
test('when a record has too many positional fields', () async { test('when a record has too many positional fields', () async {
final state = TestBackend.inTest( final state = await TestBackend.inTest(
{ {
'a|lib/a.drift': ''' 'a|lib/a.drift': '''
import 'a.dart'; import 'a.dart';
@ -767,7 +767,7 @@ typedef MyRow = (int, String, DateTime);
}); });
test('when a record has an unmatched named field', () async { test('when a record has an unmatched named field', () async {
final state = TestBackend.inTest( final state = await TestBackend.inTest(
{ {
'a|lib/a.drift': ''' 'a|lib/a.drift': '''
import 'a.dart'; import 'a.dart';
@ -788,7 +788,7 @@ typedef MyRow = (int, {String d});
}); });
test('when there is a type mismatch on a scalar column', () async { 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': ''' 'a|lib/a.drift': '''
import 'a.dart'; import 'a.dart';
@ -808,7 +808,7 @@ class MyRow {
}); });
test('when a list column is not a list', () async { test('when a list column is not a list', () async {
final state = TestBackend.inTest({ final state = await TestBackend.inTest({
'a|lib/a.drift': ''' 'a|lib/a.drift': '''
import 'a.dart'; import 'a.dart';
@ -832,7 +832,7 @@ class MyRow {
test( test(
'when there is a type mismatch on a nested scalar column', 'when there is a type mismatch on a nested scalar column',
() async { () async {
final state = TestBackend.inTest({ final state = await TestBackend.inTest({
'a|lib/a.drift': ''' 'a|lib/a.drift': '''
import 'a.dart'; import 'a.dart';

View File

@ -6,7 +6,7 @@ import '../../test_utils.dart';
void main() { void main() {
test('experimental inference - integration test', () async { test('experimental inference - integration test', () async {
final state = TestBackend.inTest({ final state = await TestBackend.inTest({
'foo|lib/a.drift': ''' 'foo|lib/a.drift': '''
CREATE TABLE artists ( CREATE TABLE artists (
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,

View File

@ -76,7 +76,7 @@ q: SELECT * FROM t WHERE i IN ?1;
}); });
test('warns about default values outside of expressions', () async { test('warns about default values outside of expressions', () async {
final state = TestBackend.inTest({ final state = await TestBackend.inTest({
'foo|lib/a.drift': r''' 'foo|lib/a.drift': r'''
CREATE TABLE foo ( CREATE TABLE foo (
id INT NOT NULL PRIMARY KEY, 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 { 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''' 'foo|lib/a.drift': r'''
CREATE TABLE foo ( CREATE TABLE foo (
id INT NOT NULL PRIMARY KEY, id INT NOT NULL PRIMARY KEY,
@ -118,7 +118,7 @@ in: INSERT INTO foo (id) $placeholder;
test( test(
'warns when nested results appear in compound statements', 'warns when nested results appear in compound statements',
() async { () async {
final state = TestBackend.inTest({ final state = await TestBackend.inTest({
'foo|lib/a.drift': ''' 'foo|lib/a.drift': '''
CREATE TABLE foo ( CREATE TABLE foo (
id INT NOT NULL PRIMARY KEY, id INT NOT NULL PRIMARY KEY,
@ -142,7 +142,7 @@ all: SELECT foo.** FROM foo UNION ALL SELECT foo.** FROM foo;
test( test(
'warns when nested query appear in nested query', 'warns when nested query appear in nested query',
() async { () async {
final state = TestBackend.inTest({ final state = await TestBackend.inTest({
'foo|lib/a.drift': ''' 'foo|lib/a.drift': '''
CREATE TABLE foo ( CREATE TABLE foo (
id INT NOT NULL PRIMARY KEY, 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 { test('in top-level queries', () async {
state = TestBackend.inTest({ state = await TestBackend.inTest({
'foo|lib/a.drift': ''' 'foo|lib/a.drift': '''
CREATE TABLE foo ( CREATE TABLE foo (
id INT NOT NULL PRIMARY KEY AUTOINCREMENT, id INT NOT NULL PRIMARY KEY AUTOINCREMENT,
@ -189,7 +189,7 @@ test: INSERT INTO foo VALUES (?)
}); });
test('in CREATE TRIGGER statements', () async { test('in CREATE TRIGGER statements', () async {
state = TestBackend.inTest({ state = await TestBackend.inTest({
'foo|lib/a.drift': ''' 'foo|lib/a.drift': '''
CREATE TABLE foo ( CREATE TABLE foo (
id INT NOT NULL PRIMARY KEY AUTOINCREMENT, id INT NOT NULL PRIMARY KEY AUTOINCREMENT,
@ -205,7 +205,7 @@ END;
}); });
test('in @create statements', () async { test('in @create statements', () async {
state = TestBackend.inTest({ state = await TestBackend.inTest({
'foo|lib/a.drift': ''' 'foo|lib/a.drift': '''
CREATE TABLE foo ( CREATE TABLE foo (
id INT NOT NULL PRIMARY KEY AUTOINCREMENT, id INT NOT NULL PRIMARY KEY AUTOINCREMENT,

View File

@ -5,7 +5,7 @@ import '../../test_utils.dart';
void main() { void main() {
test('select from view', () async { test('select from view', () async {
final backend = TestBackend.inTest({ final backend = await TestBackend.inTest({
'foo|lib/a.drift': ''' 'foo|lib/a.drift': '''
CREATE TABLE artists ( CREATE TABLE artists (
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,

View File

@ -9,7 +9,7 @@ import 'utils.dart';
void main() { void main() {
test('respects explicit type arguments', () async { test('respects explicit type arguments', () async {
final state = TestBackend.inTest({ final state = await TestBackend.inTest({
'foo|lib/main.drift': ''' 'foo|lib/main.drift': '''
bar(?1 AS TEXT, :foo AS BOOLEAN): SELECT ?, :foo; 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 { test('can read from builtin tables', () async {
final state = TestBackend.inTest({ final state = await TestBackend.inTest({
'a|lib/main.drift': ''' 'a|lib/main.drift': '''
testQuery: SELECT * FROM sqlite_schema; testQuery: SELECT * FROM sqlite_schema;
''', ''',
@ -43,7 +43,7 @@ testQuery: SELECT * FROM sqlite_schema;
}); });
test('reads REQUIRED syntax', () async { test('reads REQUIRED syntax', () async {
final state = TestBackend.inTest({ final state = await TestBackend.inTest({
'foo|lib/main.drift': ''' 'foo|lib/main.drift': '''
bar(REQUIRED ?1 AS TEXT OR NULL, REQUIRED :foo AS BOOLEAN): SELECT ?, :foo; 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 { test('infers result set for views', () async {
final state = TestBackend.inTest({ final state = await TestBackend.inTest({
'foo|lib/main.drift': r''' 'foo|lib/main.drift': r'''
CREATE VIEW my_view AS SELECT 'foo', 2; 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 { test('infers nested result set for views', () async {
final state = TestBackend.inTest({ final state = await TestBackend.inTest({
'foo|lib/main.drift': r''' 'foo|lib/main.drift': r'''
CREATE VIEW my_view AS SELECT 'foo', 2; 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 { test('infers nested result sets for custom result sets', () async {
final state = TestBackend.inTest({ final state = await TestBackend.inTest({
'foo|lib/main.drift': r''' 'foo|lib/main.drift': r'''
query: SELECT 1 AS a, b.** FROM (SELECT 2 AS b, 3 AS c) AS b; 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]) { for (final dateTimeAsText in [false, true]) {
test('analyzing date times (stored as text: $dateTimeAsText)', () async { test('analyzing date times (stored as text: $dateTimeAsText)', () async {
final state = TestBackend.inTest( final state = await TestBackend.inTest(
{ {
'foo|lib/foo.drift': r''' 'foo|lib/foo.drift': r'''
CREATE TABLE foo ( CREATE TABLE foo (
@ -202,7 +202,7 @@ q3: SELECT datetime('now');
} }
test('resolves nested result sets', () async { test('resolves nested result sets', () async {
final state = TestBackend.inTest({ final state = await TestBackend.inTest({
'foo|lib/main.drift': r''' 'foo|lib/main.drift': r'''
CREATE TABLE points ( CREATE TABLE points (
id INTEGER NOT NULL PRIMARY KEY, id INTEGER NOT NULL PRIMARY KEY,
@ -243,7 +243,7 @@ FROM routes
}); });
test('resolves nullability of aliases in nested result sets', () async { test('resolves nullability of aliases in nested result sets', () async {
final state = TestBackend.inTest({ final state = await TestBackend.inTest({
'foo|lib/main.drift': r''' 'foo|lib/main.drift': r'''
CREATE TABLE tableA1 (id INTEGER); CREATE TABLE tableA1 (id INTEGER);
CREATE TABLE tableB1 (id INTEGER); CREATE TABLE tableB1 (id INTEGER);
@ -285,7 +285,7 @@ LEFT JOIN tableB1 AS tableB2 -- nullable
test('supports custom functions', () async { test('supports custom functions', () async {
final withoutOptions = 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'); var result = await withoutOptions.analyze('package:a/a.drift');
expect(result.allErrors, [ expect(result.allErrors, [
isDriftError('Function my_function could not be found') isDriftError('Function my_function could not be found')
@ -294,14 +294,13 @@ LEFT JOIN tableB1 AS tableB2 -- nullable
.withSpan('my_function()'), .withSpan('my_function()'),
]); ]);
final withOptions = final withOptions = await TestBackend.inTest(
TestBackend.inTest({'a|lib/a.drift': 'a: SELECT my_function(?, ?);'}, {'a|lib/a.drift': 'a: SELECT my_function(?, ?);'},
options: DriftOptions.defaults( options: DriftOptions.defaults(
sqliteAnalysisOptions: SqliteAnalysisOptions(knownFunctions: { sqliteAnalysisOptions: SqliteAnalysisOptions(knownFunctions: {
'my_function': 'my_function': KnownSqliteFunction.fromJson('boolean (int, text)')
KnownSqliteFunction.fromJson('boolean (int, text)') }),
}), ));
));
result = await withOptions.analyze('package:a/a.drift'); result = await withOptions.analyze('package:a/a.drift');
withOptions.expectNoErrors(); withOptions.expectNoErrors();
@ -318,7 +317,7 @@ LEFT JOIN tableB1 AS tableB2 -- nullable
}); });
test('can cast to DATETIME and BOOLEAN', () async { test('can cast to DATETIME and BOOLEAN', () async {
final backend = TestBackend.inTest({ final backend = await TestBackend.inTest({
'a|lib/a.drift': ''' 'a|lib/a.drift': '''
a: SELECT CAST(1 AS BOOLEAN) AS a, CAST(2 AS DATETIME) as b; 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 { test('can cast to enum type', () async {
final backend = TestBackend.inTest({ final backend = await TestBackend.inTest({
'a|lib/a.drift': ''' 'a|lib/a.drift': '''
import 'enum.dart'; import 'enum.dart';

View File

@ -7,7 +7,7 @@ import '../test_utils.dart';
void main() { void main() {
group('from clean state', () { group('from clean state', () {
test('resolves simple tables', () async { test('resolves simple tables', () async {
final backend = TestBackend.inTest({ final backend = await TestBackend.inTest({
'a|lib/a.drift': ''' 'a|lib/a.drift': '''
CREATE TABLE a ( CREATE TABLE a (
foo INTEGER PRIMARY KEY, foo INTEGER PRIMARY KEY,
@ -42,7 +42,7 @@ CREATE TABLE b (
group('references', () { group('references', () {
test('self', () async { test('self', () async {
final backend = TestBackend.inTest({ final backend = await TestBackend.inTest({
'a|lib/a.drift': ''' 'a|lib/a.drift': '''
CREATE TABLE a ( CREATE TABLE a (
foo INTEGER PRIMARY KEY, foo INTEGER PRIMARY KEY,
@ -61,7 +61,7 @@ CREATE TABLE a (
}); });
test('across files', () async { test('across files', () async {
final backend = TestBackend.inTest({ final backend = await TestBackend.inTest({
'a|lib/a.drift': ''' 'a|lib/a.drift': '''
import 'b.drift'; import 'b.drift';
@ -93,7 +93,7 @@ CREATE TABLE b (
}); });
test('for triggers', () async { test('for triggers', () async {
final backend = TestBackend.inTest({ final backend = await TestBackend.inTest({
'a|lib/a.drift': ''' 'a|lib/a.drift': '''
import 'b.drift'; import 'b.drift';
@ -133,7 +133,7 @@ CREATE TABLE deleted_b (
group('non-existing', () { group('non-existing', () {
test('from table', () async { test('from table', () async {
final backend = TestBackend.inTest({ final backend = await TestBackend.inTest({
'a|lib/a.drift': ''' 'a|lib/a.drift': '''
CREATE TABLE a ( CREATE TABLE a (
foo INTEGER PRIMARY KEY, foo INTEGER PRIMARY KEY,
@ -151,7 +151,7 @@ CREATE TABLE a (
[isDriftError('`b` could not be found in any import.')]); [isDriftError('`b` could not be found in any import.')]);
}); });
test('in a trigger', () async { test('in a trigger', () async {
final backend = TestBackend.inTest(const { final backend = await TestBackend.inTest(const {
'foo|lib/a.drift': ''' 'foo|lib/a.drift': '''
CREATE TRIGGER IF NOT EXISTS foo BEFORE DELETE ON bar BEGIN CREATE TRIGGER IF NOT EXISTS foo BEFORE DELETE ON bar BEGIN
END; END;
@ -172,7 +172,7 @@ END;
}); });
test('emits warning on invalid import', () async { test('emits warning on invalid import', () async {
final backend = TestBackend.inTest({ final backend = await TestBackend.inTest({
'a|lib/a.drift': "import 'b.drift';", 'a|lib/a.drift': "import 'b.drift';",
}); });

View File

@ -8,7 +8,7 @@ import '../test_utils.dart';
void main() { void main() {
late TestBackend tester; late TestBackend tester;
setUpAll(() => tester = TestBackend({})); setUpAll(() async => tester = await TestBackend.init({}));
tearDownAll(() => tester.dispose()); tearDownAll(() => tester.dispose());
group('from AST', () { group('from AST', () {

View File

@ -37,24 +37,43 @@ class TestBackend extends DriftBackend {
AnalysisContext? _dartContext; AnalysisContext? _dartContext;
OverlayResourceProvider? _resourceProvider; OverlayResourceProvider? _resourceProvider;
TestBackend( TestBackend._(
Map<String, String> sourceContents, { Map<String, String> sourceContents, {
DriftOptions options = const DriftOptions.defaults(), DriftOptions options = const DriftOptions.defaults(),
this.analyzerExperiments = const Iterable.empty(), this.analyzerExperiments = const Iterable.empty(),
}) : sourceContents = { }) : sourceContents = {
for (final entry in sourceContents.entries) for (final entry in sourceContents.entries)
AssetId.parse(entry.key).uri.toString(): entry.value, 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, { Map<String, String> sourceContents, {
DriftOptions options = const DriftOptions.defaults(), DriftOptions options = const DriftOptions.defaults(),
Iterable<String> analyzerExperiments = const Iterable.empty(), Iterable<String> analyzerExperiments = const Iterable.empty(),
}) { }) async {
final backend = TestBackend(sourceContents, final backend = TestBackend._(
options: options, analyzerExperiments: analyzerExperiments); 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); addTearDown(backend.dispose);
return backend; return backend;
@ -62,9 +81,10 @@ class TestBackend extends DriftBackend {
static Future<FileState> analyzeSingle(String content, static Future<FileState> analyzeSingle(String content,
{String asset = 'a|lib/a.drift', {String asset = 'a|lib/a.drift',
DriftOptions options = const DriftOptions.defaults()}) { DriftOptions options = const DriftOptions.defaults()}) async {
final assetId = AssetId.parse(asset); 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); return backend.driver.fullyAnalyze(assetId.uri);
} }

View File

@ -7,7 +7,7 @@ import '../analysis/test_utils.dart';
void main() { void main() {
test('finds update rules for triggers', () async { test('finds update rules for triggers', () async {
final state = TestBackend.inTest({ final state = await TestBackend.inTest({
'a|lib/a.drift': ''' 'a|lib/a.drift': '''
CREATE TABLE users ( CREATE TABLE users (
id INTEGER NOT NULL PRIMARY KEY, id INTEGER NOT NULL PRIMARY KEY,
@ -51,7 +51,7 @@ class MyDatabase {}
}); });
test('finds update rules for foreign key constraint', () async { test('finds update rules for foreign key constraint', () async {
final state = TestBackend.inTest({ final state = await TestBackend.inTest({
'a|lib/a.drift': ''' 'a|lib/a.drift': '''
CREATE TABLE a ( CREATE TABLE a (
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,

View File

@ -95,7 +95,7 @@ CREATE VIEW user_ids AS SELECT id FROM users;
} }
Future<List<DriftElement>> _analyzeAndSerialize(String source) async { 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 file = await state.analyze('package:a/a.drift');
final writer = SchemaWriter(file.analyzedElements.toList()); final writer = SchemaWriter(file.analyzedElements.toList());

View File

@ -14,7 +14,7 @@ import '../../analysis/test_utils.dart';
void main() { void main() {
test('writer integration test', () async { test('writer integration test', () async {
final state = TestBackend.inTest({ final state = await TestBackend.inTest({
'a|lib/a.drift': ''' 'a|lib/a.drift': '''
import 'main.dart'; import 'main.dart';

View File

@ -15,8 +15,8 @@ void main() {
{DriftOptions options = const DriftOptions.defaults( {DriftOptions options = const DriftOptions.defaults(
generateNamedParameters: true, generateNamedParameters: true,
)}) async { )}) async {
final state = final state = await TestBackend.inTest({'a|lib/main.drift': driftFile},
TestBackend.inTest({'a|lib/main.drift': driftFile}, options: options); options: options);
final file = await state.analyze('package:a/main.drift'); final file = await state.analyze('package:a/main.drift');
state.expectNoErrors(); state.expectNoErrors();