From 388b31e9ea9f9d5c9372889b15e93ff5731d1fd0 Mon Sep 17 00:00:00 2001 From: Simon Binder Date: Sun, 3 Jul 2022 22:20:24 +0200 Subject: [PATCH] Remove some moor references in drift_dev --- drift/example/main.g.dart | 2 +- drift/test/generated/custom_tables.g.dart | 2 +- drift/test/generated/todos.g.dart | 2 +- drift_dev/build.yaml | 20 ++++----- drift_dev/lib/api/migrations.dart | 6 +-- drift_dev/lib/integrations/build.dart | 12 +++--- drift_dev/lib/integrations/plugin.dart | 2 +- .../lib/src/analyzer/dart/column_parser.dart | 6 +-- ...parser.dart => drift_database_parser.dart} | 6 +-- drift_dev/lib/src/analyzer/dart/parser.dart | 12 +++--- .../lib/src/analyzer/dart/table_parser.dart | 26 ++++++------ .../lib/src/analyzer/dart/view_parser.dart | 16 +++---- drift_dev/lib/src/analyzer/dart_types.dart | 6 +-- drift_dev/lib/src/analyzer/data_class.dart | 2 +- .../{moor => drift}/create_table_reader.dart | 30 ++++++------- .../{moor => drift}/entity_handler.dart | 30 ++++++------- .../{moor => drift}/find_dart_class.dart | 0 .../{moor => drift}/moor_ffi_extension.dart | 0 .../src/analyzer/{moor => drift}/parser.dart | 12 +++--- drift_dev/lib/src/analyzer/errors.dart | 20 ++++----- drift_dev/lib/src/analyzer/options.dart | 8 ++-- drift_dev/lib/src/analyzer/options.g.dart | 6 +-- .../lib/src/analyzer/runner/file_graph.dart | 5 ++- drift_dev/lib/src/analyzer/runner/inputs.dart | 8 ++-- .../lib/src/analyzer/runner/results.dart | 18 ++++---- drift_dev/lib/src/analyzer/runner/steps.dart | 14 +++---- .../analyzer/runner/steps/analyze_dart.dart | 13 +++--- .../analyzer/runner/steps/analyze_moor.dart | 6 +-- .../src/analyzer/runner/steps/parse_dart.dart | 26 ++++++------ .../src/analyzer/runner/steps/parse_moor.dart | 2 +- drift_dev/lib/src/analyzer/runner/task.dart | 23 +++++----- drift_dev/lib/src/analyzer/session.dart | 12 +++--- .../sql_queries/custom_result_class.dart | 2 +- .../analyzer/sql_queries/lints/linter.dart | 4 +- .../analyzer/sql_queries/query_analyzer.dart | 16 +++---- .../analyzer/sql_queries/query_handler.dart | 4 +- .../analyzer/sql_queries/type_mapping.dart | 16 +++---- .../lib/src/analyzer/view/view_analyzer.dart | 14 +++---- .../lib/src/backends/build/build_backend.dart | 6 +-- .../{moor_builder.dart => drift_builder.dart} | 38 ++++++++--------- .../build/generators/dao_generator.dart | 6 +-- ...generator.dart => database_generator.dart} | 6 +-- .../backends/build/preprocess_builder.dart | 24 +++++------ drift_dev/lib/src/backends/common/driver.dart | 6 +-- drift_dev/lib/src/backends/plugin/logger.dart | 2 +- drift_dev/lib/src/backends/plugin/plugin.dart | 10 ++--- .../src/backends/plugin/services/errors.dart | 6 +-- .../backends/plugin/services/navigation.dart | 4 +- .../backends/plugin/services/requests.dart | 6 +-- .../plugin/utils/ast_to_location.dart | 2 +- .../cli/commands/schema/generate_utils.dart | 6 +-- drift_dev/lib/src/cli/project.dart | 2 +- drift_dev/lib/src/model/base_entity.dart | 10 ++--- drift_dev/lib/src/model/column.dart | 12 +++--- drift_dev/lib/src/model/database.dart | 18 ++++---- .../lib/src/model/declarations/columns.dart | 9 ++-- .../src/model/declarations/declaration.dart | 12 +++--- .../lib/src/model/declarations/index.dart | 4 +- .../model/declarations/special_queries.dart | 6 +-- .../lib/src/model/declarations/tables.dart | 10 ++--- .../lib/src/model/declarations/trigger.dart | 5 ++- .../lib/src/model/declarations/views.dart | 12 +++--- drift_dev/lib/src/model/index.dart | 10 ++--- drift_dev/lib/src/model/special_queries.dart | 10 ++--- drift_dev/lib/src/model/sql_query.dart | 20 ++++----- drift_dev/lib/src/model/table.dart | 20 ++++----- drift_dev/lib/src/model/trigger.dart | 12 +++--- .../lib/src/model/used_type_converter.dart | 2 +- drift_dev/lib/src/model/view.dart | 20 ++++----- .../services/find_stream_update_rules.dart | 8 ++-- drift_dev/lib/src/services/ide/utils.dart | 4 +- .../src/services/schema/find_differences.dart | 2 +- .../lib/src/services/schema/schema_files.dart | 42 +++++++++---------- .../src/utils/entity_reference_sorter.dart | 26 ++++++------ drift_dev/lib/src/utils/options_reader.dart | 8 ++-- drift_dev/lib/src/writer/database_writer.dart | 4 +- .../lib/src/writer/queries/query_writer.dart | 6 +-- .../lib/src/writer/queries/sql_writer.dart | 4 +- .../src/writer/tables/data_class_writer.dart | 20 ++++----- .../lib/src/writer/tables/table_writer.dart | 22 +++++----- .../tables/update_companion_writer.dart | 6 +-- .../lib/src/writer/tables/view_writer.dart | 4 +- .../src/writer/utils/column_constraints.dart | 2 +- drift_dev/lib/src/writer/writer.dart | 8 ++-- .../analyzer/dart/column_references_test.dart | 2 +- drift_dev/test/analyzer/dart/dart_test.dart | 2 +- .../test/analyzer/dart/enum_columns_test.dart | 2 +- .../test/analyzer/dart/table_parser_test.dart | 8 ++-- .../analyzer/dart/type_converter_test.dart | 2 +- .../analyzer/{moor => drift}/cfe_test.dart | 4 +- .../create_table_reader_test.dart | 6 +-- .../{moor => drift}/create_view_test.dart | 6 +-- .../custom_row_classes_test.dart | 8 ++-- .../{moor => drift}/entity_handler_test.dart | 8 ++-- ...errors_when_importing_part_files_test.dart | 2 +- .../moor_ffi_extension_test.dart | 8 ++-- .../{moor => drift}/moor_parser_test.dart | 2 +- .../{moor => drift}/regression_1138_test.dart | 0 .../{moor => drift}/regression_754_test.dart | 2 +- .../{moor => drift}/sqlite_version_test.dart | 4 +- .../{moor => drift}/virtual_table_test.dart | 4 +- drift_dev/test/analyzer/options_test.dart | 6 +-- drift_dev/test/analyzer/runner/task_test.dart | 2 +- .../sql_queries/custom_result_class_test.dart | 4 +- .../analyzer/sql_queries/inference_test.dart | 4 +- .../analyzer/sql_queries/linter_test.dart | 10 ++--- .../sql_queries/queries_from_views.dart | 4 +- .../sql_queries/query_analyzer_test.dart | 4 +- .../sql_queries/query_handler_test.dart | 12 +++--- drift_dev/test/analyzer/utils.dart | 2 +- .../build/generators/moor_generator_test.dart | 6 +-- .../build/preprocess_builder_tests.dart | 4 +- .../test/model/specified_table_test.dart | 6 +-- .../test/services/schema/writer_test.dart | 4 +- .../utils/entity_reference_sorter_test.dart | 26 ++++++------ .../mutable_classes_integration_test.dart | 4 +- .../writer/queries/query_writer_test.dart | 26 ++++++------ .../test/writer/queries/sql_writer_test.dart | 2 +- drift_dev/tool/debug_plugin.dart | 2 +- moor_generator/build.yaml | 6 +-- moor_generator/lib/integrations/build.dart | 6 +-- 121 files changed, 553 insertions(+), 548 deletions(-) rename drift_dev/lib/src/analyzer/dart/{use_moor_parser.dart => drift_database_parser.dart} (96%) rename drift_dev/lib/src/analyzer/{moor => drift}/create_table_reader.dart (92%) rename drift_dev/lib/src/analyzer/{moor => drift}/entity_handler.dart (85%) rename drift_dev/lib/src/analyzer/{moor => drift}/find_dart_class.dart (100%) rename drift_dev/lib/src/analyzer/{moor => drift}/moor_ffi_extension.dart (100%) rename drift_dev/lib/src/analyzer/{moor => drift}/parser.dart (91%) rename drift_dev/lib/src/backends/build/{moor_builder.dart => drift_builder.dart} (75%) rename drift_dev/lib/src/backends/build/generators/{moor_generator.dart => database_generator.dart} (88%) rename drift_dev/test/analyzer/{moor => drift}/cfe_test.dart (95%) rename drift_dev/test/analyzer/{moor => drift}/create_table_reader_test.dart (96%) rename drift_dev/test/analyzer/{moor => drift}/create_view_test.dart (95%) rename drift_dev/test/analyzer/{moor => drift}/custom_row_classes_test.dart (92%) rename drift_dev/test/analyzer/{moor => drift}/entity_handler_test.dart (95%) rename drift_dev/test/analyzer/{moor => drift}/errors_when_importing_part_files_test.dart (97%) rename drift_dev/test/analyzer/{moor => drift}/moor_ffi_extension_test.dart (93%) rename drift_dev/test/analyzer/{moor => drift}/moor_parser_test.dart (97%) rename drift_dev/test/analyzer/{moor => drift}/regression_1138_test.dart (100%) rename drift_dev/test/analyzer/{moor => drift}/regression_754_test.dart (94%) rename drift_dev/test/analyzer/{moor => drift}/sqlite_version_test.dart (94%) rename drift_dev/test/analyzer/{moor => drift}/virtual_table_test.dart (93%) diff --git a/drift/example/main.g.dart b/drift/example/main.g.dart index 2d67b603..a688f7d1 100644 --- a/drift/example/main.g.dart +++ b/drift/example/main.g.dart @@ -3,7 +3,7 @@ part of 'main.dart'; // ************************************************************************** -// MoorGenerator +// DriftDatabaseGenerator // ************************************************************************** // ignore_for_file: type=lint diff --git a/drift/test/generated/custom_tables.g.dart b/drift/test/generated/custom_tables.g.dart index 994c74bc..3dba1fe4 100644 --- a/drift/test/generated/custom_tables.g.dart +++ b/drift/test/generated/custom_tables.g.dart @@ -3,7 +3,7 @@ part of 'custom_tables.dart'; // ************************************************************************** -// MoorGenerator +// DriftDatabaseGenerator // ************************************************************************** // ignore_for_file: type=lint diff --git a/drift/test/generated/todos.g.dart b/drift/test/generated/todos.g.dart index a7161a47..7e44007c 100644 --- a/drift/test/generated/todos.g.dart +++ b/drift/test/generated/todos.g.dart @@ -3,7 +3,7 @@ part of 'todos.dart'; // ************************************************************************** -// MoorGenerator +// DriftDatabaseGenerator // ************************************************************************** // ignore_for_file: type=lint diff --git a/drift_dev/build.yaml b/drift_dev/build.yaml index 7b8712c4..6da4d682 100644 --- a/drift_dev/build.yaml +++ b/drift_dev/build.yaml @@ -14,31 +14,31 @@ builders: preparing_builder: import: "package:drift_dev/integrations/build.dart" builder_factories: ["preparingBuilder"] - build_extensions: - ".moor": [".temp.dart", ".dart_in_moor"] - ".drift": [".temp.dart", ".dart_in_moor"] + build_extensions: + ".moor": [".temp.dart", ".dart_in_drift"] + ".drift": [".temp.dart", ".dart_in_drift"] build_to: cache auto_apply: dependents - applies_builders: ["drift_dev|cleanup"] + applies_builders: ["drift_dev:cleanup"] drift_dev: import: "package:drift_dev/integrations/build.dart" - builder_factories: ["moorBuilder"] + builder_factories: ["driftBuilder"] build_extensions: {".dart": [".moor.g.part"]} auto_apply: dependents build_to: cache - required_inputs: [".dart_in_moor"] - applies_builders: ["source_gen|combining_builder"] + required_inputs: [".dart_in_drift"] + applies_builders: ["source_gen:combining_builder"] not_shared: import: "package:drift_dev/integrations/build.dart" - builder_factories: ["moorBuilderNotShared"] + builder_factories: ["driftBuilderNotShared"] build_extensions: {".dart": [".drift.dart"]} build_to: source auto_apply: none - required_inputs: [".dart_in_moor"] + required_inputs: [".dart_in_drift"] post_process_builders: cleanup: import: "package:drift_dev/integrations/build.dart" - builder_factory: "moorCleanup" \ No newline at end of file + builder_factory: "driftCleanup" diff --git a/drift_dev/lib/api/migrations.dart b/drift_dev/lib/api/migrations.dart index 27e2d601..15cee1ab 100644 --- a/drift_dev/lib/api/migrations.dart +++ b/drift_dev/lib/api/migrations.dart @@ -114,7 +114,7 @@ class _GenerateFromScratch extends GeneratedDatabase { int get schemaVersion => 1; } -/// The implementation of this class is generated through the `moor_generator` +/// The implementation of this class is generated through the `drift_dev` /// CLI tool. abstract class SchemaInstantiationHelper { GeneratedDatabase databaseForVersion(QueryExecutor db, int version); @@ -180,14 +180,14 @@ class InitializedSchema { /// /// All connections returned by this method point to the [rawDatabase]. /// However, each call to [newConnection] returns an independent connection - /// that is considered closed from moor's point of view. This means that the + /// that is considered closed from drift's point of view. This means that the /// [rawDatabase] can be used by multiple generated database classes that /// can independently be opened and closed, albeit not simultaneously. /// /// ## Example /// /// When generating the schema helpers with the `--data-classes` and the - /// `--companions` command-line flags, this method can be used to create moor + /// `--companions` command-line flags, this method can be used to create drift /// databases inserting data at specific versions: /// /// ```dart diff --git a/drift_dev/lib/integrations/build.dart b/drift_dev/lib/integrations/build.dart index 80961904..a33aa6cc 100644 --- a/drift_dev/lib/integrations/build.dart +++ b/drift_dev/lib/integrations/build.dart @@ -1,16 +1,16 @@ import 'package:build/build.dart'; -import 'package:drift_dev/src/backends/build/moor_builder.dart'; +import 'package:drift_dev/src/backends/build/drift_builder.dart'; import 'package:drift_dev/src/backends/build/preprocess_builder.dart'; -Builder moorBuilder(BuilderOptions options) => - MoorSharedPartBuilder(options, isForNewDriftPackage: true); +Builder driftBuilder(BuilderOptions options) => + DriftSharedPartBuilder(options, isForNewDriftPackage: true); -Builder moorBuilderNotShared(BuilderOptions options) => - MoorPartBuilder(options, isForNewDriftPackage: true); +Builder driftBuilderNotShared(BuilderOptions options) => + DriftPartBuilder(options, isForNewDriftPackage: true); Builder preparingBuilder(BuilderOptions options) => PreprocessBuilder(isForNewDriftPackage: true); -PostProcessBuilder moorCleanup(BuilderOptions options) { +PostProcessBuilder driftCleanup(BuilderOptions options) { return const FileDeletingBuilder(['.temp.dart']); } diff --git a/drift_dev/lib/integrations/plugin.dart b/drift_dev/lib/integrations/plugin.dart index 1ff7d992..fd5a1615 100644 --- a/drift_dev/lib/integrations/plugin.dart +++ b/drift_dev/lib/integrations/plugin.dart @@ -4,5 +4,5 @@ import 'package:analyzer_plugin/starter.dart'; import 'package:drift_dev/src/backends/plugin/plugin.dart'; void start(List args, SendPort sendPort) { - ServerPluginStarter(MoorPlugin.forProduction()).start(sendPort); + ServerPluginStarter(DriftPlugin.forProduction()).start(sendPort); } diff --git a/drift_dev/lib/src/analyzer/dart/column_parser.dart b/drift_dev/lib/src/analyzer/dart/column_parser.dart index 0c490e86..2301dc13 100644 --- a/drift_dev/lib/src/analyzer/dart/column_parser.dart +++ b/drift_dev/lib/src/analyzer/dart/column_parser.dart @@ -58,11 +58,11 @@ const String _errorMessage = 'This getter does not create a valid column that ' /// the invocations on our way, we can extract the constraint for the column /// (e.g. its name, whether it has auto increment, is a primary key and so on). class ColumnParser { - final MoorDartParser base; + final DriftDartParser base; ColumnParser(this.base); - MoorColumn? parse(MethodDeclaration getter, Element element) { + DriftColumn? parse(MethodDeclaration getter, Element element) { final expr = base.returnExpressionOfMethod(getter); if (expr is! FunctionExpressionInvocation) { @@ -422,7 +422,7 @@ class ColumnParser { final docString = getter.documentationComment?.tokens.map((t) => t.toString()).join('\n'); - return MoorColumn( + return DriftColumn( type: columnType, dartGetterName: getter.name.name, name: name, diff --git a/drift_dev/lib/src/analyzer/dart/use_moor_parser.dart b/drift_dev/lib/src/analyzer/dart/drift_database_parser.dart similarity index 96% rename from drift_dev/lib/src/analyzer/dart/use_moor_parser.dart rename to drift_dev/lib/src/analyzer/dart/drift_database_parser.dart index bec9bcaa..df930e4a 100644 --- a/drift_dev/lib/src/analyzer/dart/use_moor_parser.dart +++ b/drift_dev/lib/src/analyzer/dart/drift_database_parser.dart @@ -1,9 +1,9 @@ part of 'parser.dart'; -class UseMoorParser { +class DriftDatabaseParser { final ParseDartStep step; - UseMoorParser(this.step); + DriftDatabaseParser(this.step); /// If [element] has a `@UseMoor` annotation, parses the database model /// declared by that class and the referenced tables. @@ -69,7 +69,7 @@ class UseMoorParser { final element = dbClass.thisType.getGetter('schemaVersion')?.variable; if (element == null) return null; - final helper = MoorDartParser(step); + final helper = DriftDartParser(step); if (element.isSynthetic) { // Getter, read from `=>` body if possible. diff --git a/drift_dev/lib/src/analyzer/dart/parser.dart b/drift_dev/lib/src/analyzer/dart/parser.dart index e639a422..c813710b 100644 --- a/drift_dev/lib/src/analyzer/dart/parser.dart +++ b/drift_dev/lib/src/analyzer/dart/parser.dart @@ -21,28 +21,28 @@ import '../dart_types.dart'; part 'column_parser.dart'; part 'table_parser.dart'; part 'use_dao_parser.dart'; -part 'use_moor_parser.dart'; +part 'drift_database_parser.dart'; part 'view_parser.dart'; -class MoorDartParser { +class DriftDartParser { final ParseDartStep step; late ColumnParser _columnParser; late TableParser _tableParser; late ViewParser _viewParser; - MoorDartParser(this.step) { + DriftDartParser(this.step) { _columnParser = ColumnParser(this); _tableParser = TableParser(this); _viewParser = ViewParser(this); } - Future parseTable(ClassElement classElement) { + Future parseTable(ClassElement classElement) { return _tableParser.parseTable(classElement); } Future parseView( - ClassElement classElement, List tables) { + ClassElement classElement, List tables) { return _viewParser.parseView(classElement, tables); } @@ -50,7 +50,7 @@ class MoorDartParser { /// /// When the column is invalid, an error will be logged and `null` is /// returned. - Future parseColumn( + Future parseColumn( MethodDeclaration declaration, Element element) { return Future.value(_columnParser.parse(declaration, element)); } diff --git a/drift_dev/lib/src/analyzer/dart/table_parser.dart b/drift_dev/lib/src/analyzer/dart/table_parser.dart index b21cf81d..726584d3 100644 --- a/drift_dev/lib/src/analyzer/dart/table_parser.dart +++ b/drift_dev/lib/src/analyzer/dart/table_parser.dart @@ -1,12 +1,12 @@ part of 'parser.dart'; -/// Parses a [MoorTable] from a Dart class. +/// Parses a [DriftTable] from a Dart class. class TableParser { - final MoorDartParser base; + final DriftDartParser base; TableParser(this.base); - Future parseTable(ClassElement element) async { + Future parseTable(ClassElement element) async { final sqlName = await _parseTableName(element); if (sqlName == null) return null; @@ -16,7 +16,7 @@ class TableParser { final dataClassInfo = _readDataClassInformation(columns, element); - final table = MoorTable( + final table = DriftTable( fromClass: element, columns: columns, sqlName: sqlName, @@ -79,7 +79,7 @@ class TableParser { } _DataClassInformation _readDataClassInformation( - List columns, ClassElement element) { + List columns, ClassElement element) { DartObject? dataClassName; DartObject? useRowClass; @@ -170,8 +170,8 @@ class TableParser { return tableName; } - Future?> _readPrimaryKey( - ClassElement element, List columns) async { + Future?> _readPrimaryKey( + ClassElement element, List columns) async { final primaryKeyGetter = element.lookUpGetter('primaryKey', element.library); @@ -191,7 +191,7 @@ class TableParser { return null; } final expression = body.expression; - final parsedPrimaryKey = {}; + final parsedPrimaryKey = {}; if (expression is SetOrMapLiteral) { for (final entry in expression.elements) { @@ -222,8 +222,8 @@ class TableParser { return parsedPrimaryKey; } - Future>?> _readUniqueKeys( - ClassElement element, List columns) async { + Future>?> _readUniqueKeys( + ClassElement element, List columns) async { final uniqueKeyGetter = element.lookUpGetter('uniqueKeys', element.library); if (uniqueKeyGetter == null || uniqueKeyGetter.isFromDefaultTable) { @@ -243,12 +243,12 @@ class TableParser { return null; } final expression = body.expression; - final parsedUniqueKeys = >[]; + final parsedUniqueKeys = >[]; if (expression is ListLiteral) { for (final keySet in expression.elements) { if (keySet is SetOrMapLiteral) { - final uniqueKey = {}; + final uniqueKey = {}; for (final entry in keySet.elements) { if (entry is Identifier) { final column = columns.singleWhereOrNull( @@ -307,7 +307,7 @@ class TableParser { return null; } - Future> _parseColumns(ClassElement element) async { + Future> _parseColumns(ClassElement element) async { final columnNames = element.allSupertypes .map((t) => t.element) .followedBy([element]) diff --git a/drift_dev/lib/src/analyzer/dart/view_parser.dart b/drift_dev/lib/src/analyzer/dart/view_parser.dart index e8283ef2..3c4a4686 100644 --- a/drift_dev/lib/src/analyzer/dart/view_parser.dart +++ b/drift_dev/lib/src/analyzer/dart/view_parser.dart @@ -2,12 +2,12 @@ part of 'parser.dart'; /// Parses a [MoorView] from a Dart class. class ViewParser { - final MoorDartParser base; + final DriftDartParser base; ViewParser(this.base); Future parseView( - ClassElement element, List tables) async { + ClassElement element, List tables) async { final name = await _parseViewName(element); final columns = (await _parseColumns(element)).toList(); final staticReferences = await _parseStaticReferences(element, tables); @@ -34,7 +34,7 @@ class ViewParser { } _DataClassInformation _readDataClassInformation( - List columns, ClassElement element) { + List columns, ClassElement element) { DartObject? useRowClass; DartObject? driftView; String? customParentClass; @@ -114,7 +114,7 @@ class ViewParser { return ReCase(element.name).snakeCase; } - Future> _parseColumns(ClassElement element) async { + Future> _parseColumns(ClassElement element) async { final columnNames = element.allSupertypes .map((t) => t.element) .followedBy([element]) @@ -154,7 +154,7 @@ class ViewParser { await base.loadElementDeclaration(field.getter!) as MethodDeclaration; final expression = (node.body as ExpressionFunctionBody).expression; - return MoorColumn( + return DriftColumn( type: sqlType, dartGetterName: field.name, name: ColumnName.implicitly(ReCase(field.name).snakeCase), @@ -179,7 +179,7 @@ class ViewParser { } Future> _parseStaticReferences( - ClassElement element, List tables) async { + ClassElement element, List tables) async { return await Stream.fromIterable(element.allSupertypes .map((t) => t.element) .followedBy([element]).expand((e) => e.fields)) @@ -190,7 +190,7 @@ class ViewParser { } Future _getStaticReference( - FieldElement field, List tables) async { + FieldElement field, List tables) async { if (field.getter != null) { try { final node = await base.loadElementDeclaration(field.getter!); @@ -210,7 +210,7 @@ class ViewParser { Future _parseQuery( ClassElement element, List references, - List columns) async { + List columns) async { final as = element.methods.where((method) => method.name == 'as').firstOrNull; diff --git a/drift_dev/lib/src/analyzer/dart_types.dart b/drift_dev/lib/src/analyzer/dart_types.dart index d4273921..77e07615 100644 --- a/drift_dev/lib/src/analyzer/dart_types.dart +++ b/drift_dev/lib/src/analyzer/dart_types.dart @@ -21,7 +21,7 @@ class FoundDartClass { } ExistingRowClass? validateExistingClass( - Iterable columns, + Iterable columns, FoundDartClass dartClass, String constructor, bool generateInsertable, @@ -61,7 +61,7 @@ ExistingRowClass? validateExistingClass( for (final column in columns) column.dartGetterName: column }; - final columnsToParameter = {}; + final columnsToParameter = {}; for (final parameter in ctor.parameters) { final column = unmatchedColumnsByName.remove(parameter.name); @@ -170,7 +170,7 @@ UsedTypeConverter? readTypeConverter( } void _checkParameterType( - ParameterElement element, MoorColumn column, Step step) { + ParameterElement element, DriftColumn column, Step step) { final type = element.type; final library = element.library!; final typesystem = library.typeSystem; diff --git a/drift_dev/lib/src/analyzer/data_class.dart b/drift_dev/lib/src/analyzer/data_class.dart index f04644e6..28174939 100644 --- a/drift_dev/lib/src/analyzer/data_class.dart +++ b/drift_dev/lib/src/analyzer/data_class.dart @@ -23,7 +23,7 @@ String dataClassNameForClassName(String tableName) { } String? parseCustomParentClass(String dartTypeName, DartObject dataClassName, - ClassElement element, MoorDartParser base) { + ClassElement element, DriftDartParser base) { final extending = dataClassName.getField('extending'); if (extending != null && !extending.isNull) { final extendingType = extending.toTypeValue(); diff --git a/drift_dev/lib/src/analyzer/moor/create_table_reader.dart b/drift_dev/lib/src/analyzer/drift/create_table_reader.dart similarity index 92% rename from drift_dev/lib/src/analyzer/moor/create_table_reader.dart rename to drift_dev/lib/src/analyzer/drift/create_table_reader.dart index 3b10770e..4f92285e 100644 --- a/drift_dev/lib/src/analyzer/moor/create_table_reader.dart +++ b/drift_dev/lib/src/analyzer/drift/create_table_reader.dart @@ -30,13 +30,13 @@ class CreateTableReader { CreateTableReader(this.stmt, this.step, this.helper, [this.imports = const []]); - Future extractTable(TypeMapper mapper) async { + Future extractTable(TypeMapper mapper) async { Table table; try { table = _schemaReader.read(stmt); } catch (e, s) { print(s); - step.reportError(ErrorInMoorFile( + step.reportError(ErrorInDriftFile( span: stmt.tableNameToken!.span, message: 'Could not extract schema information for this table: $e', )); @@ -44,8 +44,8 @@ class CreateTableReader { return null; } - final foundColumns = {}; - Set? primaryKeyFromTableConstraint; + final foundColumns = {}; + Set? primaryKeyFromTableConstraint; for (final column in table.resultColumns) { final features = []; @@ -68,7 +68,7 @@ class CreateTableReader { final dartType = await _readDartType(dartTypeName); if (dartType == null) { - step.reportError(ErrorInMoorFile( + step.reportError(ErrorInDriftFile( message: 'Type $dartTypeName could not be found. Are you missing ' 'an import?', severity: Severity.error, @@ -82,7 +82,7 @@ class CreateTableReader { helper.helperLibrary.typeProvider, ); } on InvalidTypeForEnumConverterException catch (e) { - step.reportError(ErrorInMoorFile( + step.reportError(ErrorInDriftFile( message: e.errorDescription, severity: Severity.error, span: column.definition!.typeNames!.span, @@ -112,7 +112,7 @@ class CreateTableReader { if (constraint is MappedBy) { if (converter != null) { // Already has a converter from an ENUM type - step.reportError(ErrorInMoorFile( + step.reportError(ErrorInDriftFile( message: 'This column has an ENUM type, which implicitly creates ' "a type converter. You can't apply another converter to such " 'column. ', @@ -148,13 +148,13 @@ class CreateTableReader { // if the column definition isn't set - which can happen for CREATE // VIRTUAL TABLE statements - use the entire statement as declaration. final declaration = - MoorColumnDeclaration(column.definition ?? stmt, step.file); + DriftColumnDeclaration(column.definition ?? stmt, step.file); if (converter != null) { column.applyTypeHint(TypeConverterHint(converter)); } - final parsed = MoorColumn( + final parsed = DriftColumn( type: moorType, nullable: column.type.nullable != false, dartGetterName: overriddenDartName ?? dartName, @@ -182,7 +182,7 @@ class CreateTableReader { if (moorTableInfo.useExistingDartClass) { final clazz = await findDartClass(step, imports, overriddenNames); if (clazz == null) { - step.reportError(ErrorInMoorFile( + step.reportError(ErrorInDriftFile( span: stmt.tableNameToken!.span, message: 'Existing Dart class $overriddenNames was not found, are ' 'you missing an import?', @@ -221,7 +221,7 @@ class CreateTableReader { } } - final moorTable = MoorTable( + final moorTable = DriftTable( fromClass: null, columns: foundColumns.values.toList(), sqlName: table.name, @@ -232,14 +232,14 @@ class CreateTableReader { overrideTableConstraints: constraints.isNotEmpty ? constraints : null, // we take care of writing the primary key ourselves overrideDontWriteConstraints: true, - declaration: MoorTableDeclaration(stmt, step.file), + declaration: DriftTableDeclaration(stmt, step.file), existingRowClass: existingRowClass, isStrict: table.isStrict, )..parserTable = table; // Having a mapping from parser table to moor tables helps with IDE features // like "go to definition" - table.setMeta(moorTable); + table.setMeta(moorTable); return moorTable; } @@ -255,7 +255,7 @@ class CreateTableReader { code, imports.map((e) => e.importedFile).where((e) => e.endsWith('.dart'))); } on CannotReadExpressionException catch (e) { - step.reportError(ErrorInMoorFile(span: mapper.span!, message: e.msg)); + step.reportError(ErrorInDriftFile(span: mapper.span!, message: e.msg)); return null; } @@ -265,7 +265,7 @@ class CreateTableReader { sqlType, nullable, (errorMsg) => step - .reportError(ErrorInMoorFile(span: mapper.span!, message: errorMsg)), + .reportError(ErrorInDriftFile(span: mapper.span!, message: errorMsg)), helper, ); } diff --git a/drift_dev/lib/src/analyzer/moor/entity_handler.dart b/drift_dev/lib/src/analyzer/drift/entity_handler.dart similarity index 85% rename from drift_dev/lib/src/analyzer/moor/entity_handler.dart rename to drift_dev/lib/src/analyzer/drift/entity_handler.dart index 824812cb..eebd833f 100644 --- a/drift_dev/lib/src/analyzer/moor/entity_handler.dart +++ b/drift_dev/lib/src/analyzer/drift/entity_handler.dart @@ -9,16 +9,16 @@ import 'package:sqlparser/utils/find_referenced_tables.dart'; /// Handles `REFERENCES` clauses in tables by resolving their columns and /// reporting errors if they don't exist. Further, sets the -/// [MoorTable.references] field for tables declared in moor. +/// [DriftTable.references] field for tables declared in moor. class EntityHandler extends BaseAnalyzer { - final ParsedMoorFile file; + final ParsedDriftFile file; AnalyzeMoorStep get moorStep => step as AnalyzeMoorStep; EntityHandler( AnalyzeMoorStep step, this.file, - List availableTables, + List availableTables, ) : // we'll analyze views later, so pass an empty list for now. Otherwise // the incomplete views would be added to the engine. @@ -27,17 +27,17 @@ class EntityHandler extends BaseAnalyzer { } final Map _triggers = {}; - final Map _tables = {}; + final Map _tables = {}; final Map _indexes = {}; late _ReferenceResolvingVisitor _referenceResolver; void handle() { for (final entity in file.declaredEntities) { - if (entity is MoorTable) { + if (entity is DriftTable) { entity.references.clear(); final node = - _handleMoorDeclaration(entity, _tables); + _handleMoorDeclaration(entity, _tables); _lint(node, entity.sqlName); } else if (entity is MoorTrigger) { entity.clearResolvedReferences(); @@ -55,9 +55,9 @@ class EntityHandler extends BaseAnalyzer { } else if (entity is MoorIndex) { entity.table = null; - _handleMoorDeclaration(entity, _indexes); + _handleMoorDeclaration(entity, _indexes); } else if (entity is SpecialQuery) { - final node = (entity.declaration as MoorSpecialQueryDeclaration).node; + final node = (entity.declaration as DriftSpecialQueryDeclaration).node; _lint(node, 'special @create table'); entity.references.addAll(_findTables(node.statement)); @@ -73,7 +73,7 @@ class EntityHandler extends BaseAnalyzer { lintContext(context, displayName); } - Iterable _findTables(AstNode node) { + Iterable _findTables(AstNode node) { return findReferences(node, includeViews: false).cast(); } @@ -83,7 +83,7 @@ class EntityHandler extends BaseAnalyzer { return finder.writtenTables.map(mapper.writtenToMoor); } - AstNode _handleMoorDeclaration( + AstNode _handleMoorDeclaration( HasDeclaration e, Map map, ) { @@ -94,7 +94,7 @@ class EntityHandler extends BaseAnalyzer { return declaration.node; } - MoorTable? _inducedTable(TableInducingStatement stmt) { + DriftTable? _inducedTable(TableInducingStatement stmt) { return _tables[stmt]; } @@ -112,7 +112,7 @@ class _ReferenceResolvingVisitor extends RecursiveVisitor { _ReferenceResolvingVisitor(this.handler); - MoorTable? _resolveTable(TableReference reference) { + DriftTable? _resolveTable(TableReference reference) { return handler.tables .firstWhereOrNull((t) => t.sqlName == reference.tableName); } @@ -121,7 +121,7 @@ class _ReferenceResolvingVisitor extends RecursiveVisitor { void visitCreateTriggerStatement(CreateTriggerStatement e, void arg) { final table = _resolveTable(e.onTable); if (table == null) { - handler.step.reportError(ErrorInMoorFile( + handler.step.reportError(ErrorInDriftFile( severity: Severity.error, span: e.onTable.span!, message: 'Target table ${e.onTable.tableName} could not be found.', @@ -136,7 +136,7 @@ class _ReferenceResolvingVisitor extends RecursiveVisitor { void visitCreateIndexStatement(CreateIndexStatement e, void arg) { final table = _resolveTable(e.on); if (table == null) { - handler.step.reportError(ErrorInMoorFile( + handler.step.reportError(ErrorInDriftFile( severity: Severity.error, span: e.on.span!, message: 'Target table ${e.on.tableName} could not be found.', @@ -153,7 +153,7 @@ class _ReferenceResolvingVisitor extends RecursiveVisitor { final referencedTable = _resolveTable(clause.foreignTable); if (referencedTable == null) { - handler.step.reportError(ErrorInMoorFile( + handler.step.reportError(ErrorInDriftFile( severity: Severity.error, span: clause.span!, message: diff --git a/drift_dev/lib/src/analyzer/moor/find_dart_class.dart b/drift_dev/lib/src/analyzer/drift/find_dart_class.dart similarity index 100% rename from drift_dev/lib/src/analyzer/moor/find_dart_class.dart rename to drift_dev/lib/src/analyzer/drift/find_dart_class.dart diff --git a/drift_dev/lib/src/analyzer/moor/moor_ffi_extension.dart b/drift_dev/lib/src/analyzer/drift/moor_ffi_extension.dart similarity index 100% rename from drift_dev/lib/src/analyzer/moor/moor_ffi_extension.dart rename to drift_dev/lib/src/analyzer/drift/moor_ffi_extension.dart diff --git a/drift_dev/lib/src/analyzer/moor/parser.dart b/drift_dev/lib/src/analyzer/drift/parser.dart similarity index 91% rename from drift_dev/lib/src/analyzer/moor/parser.dart rename to drift_dev/lib/src/analyzer/drift/parser.dart index 9e35c114..fb54c812 100644 --- a/drift_dev/lib/src/analyzer/moor/parser.dart +++ b/drift_dev/lib/src/analyzer/drift/parser.dart @@ -1,6 +1,6 @@ import 'package:drift_dev/moor_generator.dart'; +import 'package:drift_dev/src/analyzer/drift/create_table_reader.dart'; import 'package:drift_dev/src/analyzer/errors.dart'; -import 'package:drift_dev/src/analyzer/moor/create_table_reader.dart'; import 'package:drift_dev/src/analyzer/runner/results.dart'; import 'package:drift_dev/src/analyzer/runner/steps.dart'; import 'package:sqlparser/sqlparser.dart'; @@ -13,7 +13,7 @@ class MoorParser { MoorParser(this.step, this.helper); - Future parseAndAnalyze() async { + Future parseAndAnalyze() async { final engine = step.task.session.spawnEngine(); final result = engine.parseDriftFile(step.content); final parsedFile = result.rootNode as DriftFile; @@ -22,7 +22,7 @@ class MoorParser { final queryDeclarations = []; final importStatements = []; - final createdEntities = []; + final createdEntities = []; for (final parsedStmt in parsedFile.statements) { if (parsedStmt is ImportStatement) { @@ -48,7 +48,7 @@ class MoorParser { parsedStmt.identifier as SpecialStatementIdentifier; if (identifier.specialName != 'create') { step.reportError( - ErrorInMoorFile( + ErrorInDriftFile( span: identifier.nameToken!.span, message: 'Only @create is supported at the moment.', ), @@ -61,7 +61,7 @@ class MoorParser { } for (final error in result.errors) { - step.reportError(ErrorInMoorFile( + step.reportError(ErrorInDriftFile( severity: Severity.error, span: error.token.span, message: error.message, @@ -75,7 +75,7 @@ class MoorParser { } } - final analyzedFile = ParsedMoorFile( + final analyzedFile = ParsedDriftFile( result, declaredEntities: createdEntities, queries: queryDeclarations, diff --git a/drift_dev/lib/src/analyzer/errors.dart b/drift_dev/lib/src/analyzer/errors.dart index c5e3e3c1..968c7fc7 100644 --- a/drift_dev/lib/src/analyzer/errors.dart +++ b/drift_dev/lib/src/analyzer/errors.dart @@ -9,13 +9,13 @@ typedef LogFunction = void Function(dynamic message, [Object? error, StackTrace? stackTrace]); /// Base class for errors that can be presented to a user. -class MoorError { +class DriftError { final Severity severity; final String message; bool wasDuringParsing = true; - MoorError({required this.severity, required this.message}); + DriftError({required this.severity, required this.message}); bool get isError => severity == Severity.criticalError || severity == Severity.error; @@ -32,7 +32,7 @@ class MoorError { } } -class ErrorInDartCode extends MoorError { +class ErrorInDartCode extends DriftError { final Element? affectedElement; final dart.AstNode? affectedNode; @@ -77,16 +77,16 @@ class ErrorInDartCode extends MoorError { } } -class ErrorInMoorFile extends MoorError { +class ErrorInDriftFile extends DriftError { final FileSpan span; - ErrorInMoorFile( + ErrorInDriftFile( {required this.span, required String message, Severity severity = Severity.warning}) : super(message: message, severity: severity); - factory ErrorInMoorFile.fromSqlParser(AnalysisError error, + factory ErrorInDriftFile.fromSqlParser(AnalysisError error, {Severity? overrideSeverity}) { // Describe how to change the sqlite version for errors caused by a wrong // version @@ -99,7 +99,7 @@ class ErrorInMoorFile extends MoorError { final defaultSeverity = error.type == AnalysisErrorType.hint ? Severity.hint : Severity.error; - return ErrorInMoorFile( + return ErrorInDriftFile( span: error.span!, message: msg, severity: overrideSeverity ?? defaultSeverity, @@ -113,10 +113,10 @@ class ErrorInMoorFile extends MoorError { } class ErrorSink { - final List _errors = []; - UnmodifiableListView get errors => UnmodifiableListView(_errors); + final List _errors = []; + UnmodifiableListView get errors => UnmodifiableListView(_errors); - void report(MoorError error) { + void report(DriftError error) { _errors.add(error); } diff --git a/drift_dev/lib/src/analyzer/options.dart b/drift_dev/lib/src/analyzer/options.dart index 7d7d6420..6c350bc8 100644 --- a/drift_dev/lib/src/analyzer/options.dart +++ b/drift_dev/lib/src/analyzer/options.dart @@ -14,7 +14,7 @@ part 'options.g.dart'; fieldRename: FieldRename.snake, createToJson: false, ) -class MoorOptions { +class DriftOptions { static const _defaultSqliteVersion = SqliteVersion.v3(34); /// Whether moor should generate a `fromJsonString` factory for data classes. @@ -99,7 +99,7 @@ class MoorOptions { final bool scopedDartComponents; @internal - const MoorOptions.defaults({ + const DriftOptions.defaults({ this.generateFromJsonStringConstructor = false, this.overrideHashAndEqualsInResultSets = false, this.compactQueryMethods = false, @@ -121,7 +121,7 @@ class MoorOptions { this.dialect = const DialectOptions(SqlDialect.sqlite, null), }); - MoorOptions({ + DriftOptions({ required this.generateFromJsonStringConstructor, required this.overrideHashAndEqualsInResultSets, required this.compactQueryMethods, @@ -161,7 +161,7 @@ class MoorOptions { } } - factory MoorOptions.fromJson(Map json) => _$MoorOptionsFromJson(json); + factory DriftOptions.fromJson(Map json) => _$DriftOptionsFromJson(json); SqliteAnalysisOptions? get sqliteOptions { return dialect?.options ?? sqliteAnalysisOptions; diff --git a/drift_dev/lib/src/analyzer/options.g.dart b/drift_dev/lib/src/analyzer/options.g.dart index 13712e09..17406d59 100644 --- a/drift_dev/lib/src/analyzer/options.g.dart +++ b/drift_dev/lib/src/analyzer/options.g.dart @@ -6,8 +6,8 @@ part of 'options.dart'; // JsonSerializableGenerator // ************************************************************************** -MoorOptions _$MoorOptionsFromJson(Map json) => $checkedCreate( - 'MoorOptions', +DriftOptions _$DriftOptionsFromJson(Map json) => $checkedCreate( + 'DriftOptions', json, ($checkedConvert) { $checkKeys( @@ -34,7 +34,7 @@ MoorOptions _$MoorOptionsFromJson(Map json) => $checkedCreate( 'scoped_dart_components' ], ); - final val = MoorOptions( + final val = DriftOptions( generateFromJsonStringConstructor: $checkedConvert( 'write_from_json_string_constructor', (v) => v as bool? ?? false), overrideHashAndEqualsInResultSets: $checkedConvert( diff --git a/drift_dev/lib/src/analyzer/runner/file_graph.dart b/drift_dev/lib/src/analyzer/runner/file_graph.dart index 22eaf6b5..59210bc6 100644 --- a/drift_dev/lib/src/analyzer/runner/file_graph.dart +++ b/drift_dev/lib/src/analyzer/runner/file_graph.dart @@ -76,8 +76,9 @@ class FileGraph { } enum FileType { - /// A `.moor` file, containing `CREATE TABLE` statements and queries. - moor, + /// A `.drift` (or `.moor`) file, containing `CREATE TABLE` statements and + /// queries. + drift, /// A dart library. Note that, in particular, this doesn't include `part of` /// files, as those aren't libraries. diff --git a/drift_dev/lib/src/analyzer/runner/inputs.dart b/drift_dev/lib/src/analyzer/runner/inputs.dart index 6ef9bac7..881fa9b9 100644 --- a/drift_dev/lib/src/analyzer/runner/inputs.dart +++ b/drift_dev/lib/src/analyzer/runner/inputs.dart @@ -1,7 +1,7 @@ import 'package:analyzer/dart/element/element.dart'; /// Inputs coming from an external system (such as the analyzer, the build -/// package, etc.) that will be further analyzed by moor. +/// package, etc.) that will be further analyzed by drift_dev. abstract class Input { final String path; @@ -15,9 +15,9 @@ class DartInput extends Input { DartInput(String path, this.library) : super(path); } -/// Input for a `.moor` file -class MoorInput extends Input { +/// Input for a `.drift` file +class DriftFileInput extends Input { final String content; - MoorInput(String path, this.content) : super(path); + DriftFileInput(String path, this.content) : super(path); } diff --git a/drift_dev/lib/src/analyzer/runner/results.dart b/drift_dev/lib/src/analyzer/runner/results.dart index 02979eae..47b23bb5 100644 --- a/drift_dev/lib/src/analyzer/runner/results.dart +++ b/drift_dev/lib/src/analyzer/runner/results.dart @@ -4,10 +4,10 @@ import 'package:drift_dev/src/analyzer/runner/file_graph.dart'; import 'package:sqlparser/sqlparser.dart'; abstract class FileResult { - final List declaredEntities; + final List declaredEntities; - Iterable get declaredTables => - declaredEntities.whereType(); + Iterable get declaredTables => + declaredEntities.whereType(); Iterable get declaredViews => declaredEntities.whereType(); @@ -20,18 +20,18 @@ class ParsedDartFile extends FileResult { final List declaredDaos; final List declaredDatabases; - Iterable get dbAccessors => - declaredDatabases.cast().followedBy(declaredDaos); + Iterable get dbAccessors => + declaredDatabases.cast().followedBy(declaredDaos); ParsedDartFile( {required this.library, - List declaredTables = const [], + List declaredTables = const [], this.declaredDaos = const [], this.declaredDatabases = const []}) : super(declaredTables); } -class ParsedMoorFile extends FileResult { +class ParsedDriftFile extends FileResult { final ParseResult parseResult; DriftFile get parsedFile => parseResult.rootNode as DriftFile; @@ -45,9 +45,9 @@ class ParsedMoorFile extends FileResult { List? resolvedQueries; Map? resolvedImports; - ParsedMoorFile( + ParsedDriftFile( this.parseResult, { - List declaredEntities = const [], + List declaredEntities = const [], this.queries = const [], this.imports = const [], this.otherComponents = const [], diff --git a/drift_dev/lib/src/analyzer/runner/steps.dart b/drift_dev/lib/src/analyzer/runner/steps.dart index 9c4807b4..ce530381 100644 --- a/drift_dev/lib/src/analyzer/runner/steps.dart +++ b/drift_dev/lib/src/analyzer/runner/steps.dart @@ -5,9 +5,9 @@ import 'package:collection/collection.dart'; import 'package:drift/drift.dart'; import 'package:drift_dev/moor_generator.dart'; import 'package:drift_dev/src/analyzer/dart/parser.dart'; +import 'package:drift_dev/src/analyzer/drift/entity_handler.dart'; +import 'package:drift_dev/src/analyzer/drift/parser.dart'; import 'package:drift_dev/src/analyzer/errors.dart'; -import 'package:drift_dev/src/analyzer/moor/entity_handler.dart'; -import 'package:drift_dev/src/analyzer/moor/parser.dart'; import 'package:drift_dev/src/analyzer/runner/file_graph.dart'; import 'package:drift_dev/src/analyzer/runner/results.dart'; import 'package:drift_dev/src/analyzer/runner/task.dart'; @@ -37,7 +37,7 @@ abstract class Step { Step(this.task, this.file); - void reportError(MoorError error) => + void reportError(DriftError error) => errors.report(error..wasDuringParsing = isParsing); } @@ -47,13 +47,13 @@ abstract class AnalyzingStep extends Step { @override final bool isParsing = false; - Iterable _availableEntities(Iterable imports) { - return imports.expand((file) => + Iterable _availableEntities(Iterable imports) { + return imports.expand((file) => file.currentResult?.declaredEntities ?? const Iterable.empty()); } - Iterable _availableTables(Iterable imports) { - return _availableEntities(imports).whereType(); + Iterable _availableTables(Iterable imports) { + return _availableEntities(imports).whereType(); } Iterable _availableViews(Iterable imports) { diff --git a/drift_dev/lib/src/analyzer/runner/steps/analyze_dart.dart b/drift_dev/lib/src/analyzer/runner/steps/analyze_dart.dart index 02380219..8f9a48c8 100644 --- a/drift_dev/lib/src/analyzer/runner/steps/analyze_dart.dart +++ b/drift_dev/lib/src/analyzer/runner/steps/analyze_dart.dart @@ -62,7 +62,7 @@ class AnalyzeDartStep extends AnalyzingStep { } } - List? availableEntities; + List? availableEntities; try { availableEntities = sortEntitiesTopologically(unsortedEntities); @@ -98,10 +98,11 @@ class AnalyzeDartStep extends AnalyzingStep { final availableQueries = transitiveImports .map((f) => f.currentResult) - .whereType() + .whereType() .expand((f) => f.resolvedQueries ?? const []); - final availableTables = availableEntities.whereType().toList(); + final availableTables = + availableEntities.whereType().toList(); final availableViews = availableEntities.whereType().toList(); final parser = SqlAnalyzer( this, availableTables, availableViews, accessor.declaredQueries); @@ -118,9 +119,9 @@ class AnalyzeDartStep extends AnalyzingStep { /// Resolves a `.reference` action declared on a Dart-defined column. void _resolveDartColumnReferences( - Map dartTables) { + Map dartTables) { dartTables.forEach((dartClass, moorEntity) { - if (moorEntity is! MoorTable) return; + if (moorEntity is! DriftTable) return; for (final column in moorEntity.columns) { for (var i = 0; i < column.features.length; i++) { @@ -129,7 +130,7 @@ class AnalyzeDartStep extends AnalyzingStep { if (feature is UnresolvedDartForeignKeyReference) { final table = dartTables[feature.otherTable]; - if (table is! MoorTable) { + if (table is! DriftTable) { reportError(ErrorInDartCode( message: 'This class has not been added as a table', affectedElement: feature.surroundingElementForErrors, diff --git a/drift_dev/lib/src/analyzer/runner/steps/analyze_moor.dart b/drift_dev/lib/src/analyzer/runner/steps/analyze_moor.dart index 368a8654..8ddcb17c 100644 --- a/drift_dev/lib/src/analyzer/runner/steps/analyze_moor.dart +++ b/drift_dev/lib/src/analyzer/runner/steps/analyze_moor.dart @@ -9,7 +9,7 @@ class AnalyzeViewsInDriftFileStep extends AnalyzingStep { return; } - final parseResult = file.currentResult as ParsedMoorFile; + final parseResult = file.currentResult as ParsedDriftFile; final availableTables = _availableTables(task.crawlImports(parseResult.resolvedImports!.values)) .followedBy(parseResult.declaredTables) @@ -30,7 +30,7 @@ class AnalyzeMoorStep extends AnalyzingStep { return; } - final parseResult = file.currentResult as ParsedMoorFile; + final parseResult = file.currentResult as ParsedDriftFile; final transitiveImports = task.crawlImports(parseResult.resolvedImports!.values).toList(); @@ -38,7 +38,7 @@ class AnalyzeMoorStep extends AnalyzingStep { // Check that all imports are valid parseResult.resolvedImports!.forEach((node, fileRef) { if (fileRef.type == FileType.other) { - reportError(ErrorInMoorFile( + reportError(ErrorInDriftFile( span: node.span!, message: "Invalid import (the file exists, but couldn't be parsed). " 'Is it a part file?', diff --git a/drift_dev/lib/src/analyzer/runner/steps/parse_dart.dart b/drift_dev/lib/src/analyzer/runner/steps/parse_dart.dart index 5e0365ee..1d9f38de 100644 --- a/drift_dev/lib/src/analyzer/runner/steps/parse_dart.dart +++ b/drift_dev/lib/src/analyzer/runner/steps/parse_dart.dart @@ -1,7 +1,7 @@ part of '../steps.dart'; /// Extracts the following information from a Dart file: -/// - [MoorTable]s, which are read from Dart classes extending `Table`. +/// - [DriftTable]s, which are read from Dart classes extending `Table`. /// - [Database]s, which are read from `@UseMoor`-annotated classes /// - [Dao]s, which are read from `@UseDao`-annotated classes. /// @@ -16,15 +16,15 @@ class ParseDartStep extends Step { final LibraryElement library; final HelperLibrary resolvedHelper; - late MoorDartParser _parser; - MoorDartParser get parser => _parser; + late DriftDartParser _parser; + DriftDartParser get parser => _parser; - final Map _tables = {}; + final Map _tables = {}; final Map _views = {}; ParseDartStep(Task task, FoundFile file, this.library, this.resolvedHelper) : super(task, file) { - _parser = MoorDartParser(this); + _parser = DriftDartParser(this); } Future parse() async { @@ -58,7 +58,7 @@ class ParseDartStep extends Step { ); } - Future _parseTable(ClassElement element) async { + Future _parseTable(ClassElement element) async { if (!_tables.containsKey(element)) { final table = await parser.parseTable(element); @@ -71,7 +71,7 @@ class ParseDartStep extends Step { } Future _parseView( - ClassElement element, List tables) async { + ClassElement element, List tables) async { if (!_views.containsKey(element)) { final view = await parser.parseView(element, tables); @@ -82,7 +82,7 @@ class ParseDartStep extends Step { return _views[element]; } - void _lintDartTable(MoorTable table, ClassElement from) { + void _lintDartTable(DriftTable table, ClassElement from) { if (table.primaryKey != null) { final hasAdditional = table.columns.any((c) { final isPk = c.features.any((f) => f is PrimaryKey); @@ -106,7 +106,7 @@ class ParseDartStep extends Step { /// annotation. Future parseDatabase( ClassElement element, ConstantReader annotation) { - return UseMoorParser(this).parseDatabase(element, annotation); + return DriftDatabaseParser(this).parseDatabase(element, annotation); } /// Parses a [Dao] from a class declaration that has a `UseDao` @@ -115,11 +115,11 @@ class ParseDartStep extends Step { return UseDaoParser(this).parseDao(element, annotation); } - /// Resolves a [MoorTable] for the class of each [DartType] in [types]. + /// Resolves a [DriftTable] for the class of each [DartType] in [types]. /// The [initializedBy] element should be the piece of code that caused the /// parsing (e.g. the database class that is annotated with `@DriftDatabase`). /// This will allow for more descriptive error messages. - Future> parseTables( + Future> parseTables( Iterable types, Element initializedBy) { return Future.wait(types.map((type) { if (!_tableTypeChecker.isAssignableFrom(type.element!)) { @@ -142,8 +142,8 @@ class ParseDartStep extends Step { /// The [initializedBy] element should be the piece of code that caused the /// parsing (e.g. the database class that is annotated with `@DriftDatabase`). /// This will allow for more descriptive error messages. - Future> parseViews( - Iterable types, Element initializedBy, List tables) { + Future> parseViews(Iterable types, + Element initializedBy, List tables) { return Future.wait(types.map((type) { if (!_viewTypeChecker.isAssignableFrom(type.element!)) { reportError(ErrorInDartCode( diff --git a/drift_dev/lib/src/analyzer/runner/steps/parse_moor.dart b/drift_dev/lib/src/analyzer/runner/steps/parse_moor.dart index 43d0d01f..528a3fee 100644 --- a/drift_dev/lib/src/analyzer/runner/steps/parse_moor.dart +++ b/drift_dev/lib/src/analyzer/runner/steps/parse_moor.dart @@ -6,7 +6,7 @@ class ParseMoorStep extends Step { ParseMoorStep(Task task, FoundFile file, this.content) : super(task, file); - Future parseFile() async { + Future parseFile() async { final parser = MoorParser(this, await task.helper); return parser.parseAndAnalyze(); } diff --git a/drift_dev/lib/src/analyzer/runner/task.dart b/drift_dev/lib/src/analyzer/runner/task.dart index 86c04702..4b107b96 100644 --- a/drift_dev/lib/src/analyzer/runner/task.dart +++ b/drift_dev/lib/src/analyzer/runner/task.dart @@ -61,8 +61,8 @@ class Task { // todo we force that moor files are analyzed first because they contain // resolved queries which are copied into database accessors. Can we find // a way to remove this special-handling? - final moorFiles = _analyzedFiles.where((f) => f.type == FileType.moor); - final otherFiles = _analyzedFiles.where((f) => f.type != FileType.moor); + final moorFiles = _analyzedFiles.where((f) => f.type == FileType.drift); + final otherFiles = _analyzedFiles.where((f) => f.type != FileType.drift); for (final moorFile in moorFiles) { moorFile.errors.clearNonParsingErrors(); @@ -95,15 +95,15 @@ class Task { final resolvedImports = {}; switch (file.type) { - case FileType.moor: + case FileType.drift: final content = await backend.readMoor(file.uri); final step = createdStep = ParseMoorStep(this, file, content); - ParsedMoorFile parsed; + ParsedDriftFile parsed; try { parsed = await step.parseFile(); } on Exception catch (e) { - file.errors.report(MoorError( + file.errors.report(DriftError( severity: Severity.error, message: 'Could not parse file: $e', )..wasDuringParsing = true); @@ -115,7 +115,7 @@ class Task { for (final import in parsed.imports) { final found = await _resolveOrReportError(file, import.importedFile, (errorMsg) { - step.reportError(ErrorInMoorFile( + step.reportError(ErrorInDriftFile( span: import.importString!.span, severity: Severity.error, message: errorMsg, @@ -143,7 +143,7 @@ class Task { file.currentResult = parsed; final daosAndDatabases = parsed.declaredDaos - .cast() + .cast() .followedBy(parsed.declaredDatabases); for (final accessor in daosAndDatabases) { @@ -212,9 +212,10 @@ class Task { yield available; var importsFromHere = const Iterable.empty(); - if (available.type == FileType.moor) { - importsFromHere = - (available.currentResult as ParsedMoorFile).resolvedImports!.values; + if (available.type == FileType.drift) { + importsFromHere = (available.currentResult as ParsedDriftFile) + .resolvedImports! + .values; } for (final next in importsFromHere) { @@ -235,7 +236,7 @@ class Task { case FileType.dartLibrary: step = AnalyzeDartStep(this, file)..analyze(); break; - case FileType.moor: + case FileType.drift: final analyzeMoor = step = AnalyzeMoorStep(this, file); await analyzeMoor.analyze(); break; diff --git a/drift_dev/lib/src/analyzer/session.dart b/drift_dev/lib/src/analyzer/session.dart index 7d604c8c..010baa14 100644 --- a/drift_dev/lib/src/analyzer/session.dart +++ b/drift_dev/lib/src/analyzer/session.dart @@ -1,7 +1,7 @@ import 'dart:async'; +import 'package:drift_dev/src/analyzer/drift/moor_ffi_extension.dart'; import 'package:drift_dev/src/analyzer/errors.dart'; -import 'package:drift_dev/src/analyzer/moor/moor_ffi_extension.dart'; import 'package:drift_dev/src/analyzer/runner/file_graph.dart'; import 'package:drift_dev/src/analyzer/runner/task.dart'; import 'package:drift_dev/src/backends/backend.dart'; @@ -11,8 +11,8 @@ import 'package:sqlparser/sqlparser.dart'; import 'options.dart'; const _fileEndings = { - '.moor': FileType.moor, - '.drift': FileType.moor, + '.moor': FileType.drift, + '.drift': FileType.drift, '.dart': FileType.dartLibrary, }; @@ -20,12 +20,12 @@ const _fileEndings = { class MoorSession { final FileGraph fileGraph = FileGraph(); final Backend backend; - MoorOptions options; + DriftOptions options; final _completedTasks = StreamController.broadcast(); final _changedFiles = StreamController>.broadcast(); - MoorSession(this.backend, {this.options = const MoorOptions.defaults()}); + MoorSession(this.backend, {this.options = const DriftOptions.defaults()}); /// Stream that emits a [Task] that has been completed. Stream get completedTasks => _completedTasks.stream; @@ -83,7 +83,7 @@ class MoorSession { } /// Finds all current errors in the [file] and transitive imports thereof. - Iterable errorsInFileAndImports(FoundFile file) { + Iterable errorsInFileAndImports(FoundFile file) { final targetFiles = [file, ...fileGraph.crawl(file)]; return targetFiles.fold(const Iterable.empty(), (errors, file) { diff --git a/drift_dev/lib/src/analyzer/sql_queries/custom_result_class.dart b/drift_dev/lib/src/analyzer/sql_queries/custom_result_class.dart index 0063db04..c0b550fc 100644 --- a/drift_dev/lib/src/analyzer/sql_queries/custom_result_class.dart +++ b/drift_dev/lib/src/analyzer/sql_queries/custom_result_class.dart @@ -18,7 +18,7 @@ import 'package:drift_dev/src/analyzer/errors.dart'; /// matching table. This restriction might be lifted in the future, but it makes /// the implementation easier. class CustomResultClassTransformer { - final BaseMoorAccessor accessor; + final BaseDriftAccessor accessor; CustomResultClassTransformer(this.accessor); diff --git a/drift_dev/lib/src/analyzer/sql_queries/lints/linter.dart b/drift_dev/lib/src/analyzer/sql_queries/lints/linter.dart index 04c9b92d..a3a44cbd 100644 --- a/drift_dev/lib/src/analyzer/sql_queries/lints/linter.dart +++ b/drift_dev/lib/src/analyzer/sql_queries/lints/linter.dart @@ -1,4 +1,4 @@ -import 'package:drift_dev/moor_generator.dart' show MoorColumn; +import 'package:drift_dev/moor_generator.dart' show DriftColumn; import 'package:sqlparser/sqlparser.dart'; import '../query_handler.dart'; @@ -173,7 +173,7 @@ class _LintingVisitor extends RecursiveVisitor { // second, check that no required columns are left out final resolved = e.table.resolved; - List required; + List required; if (resolved is Table) { final specifiedTable = linter.mapper.tableToMoor(e.table.resolved as Table)!; diff --git a/drift_dev/lib/src/analyzer/sql_queries/query_analyzer.dart b/drift_dev/lib/src/analyzer/sql_queries/query_analyzer.dart index e368a6c0..e98dc8ae 100644 --- a/drift_dev/lib/src/analyzer/sql_queries/query_analyzer.dart +++ b/drift_dev/lib/src/analyzer/sql_queries/query_analyzer.dart @@ -13,7 +13,7 @@ import 'package:sqlparser/utils/find_referenced_tables.dart'; import 'required_variables.dart'; abstract class BaseAnalyzer { - final List tables; + final List tables; final List views; final Step step; @@ -38,13 +38,13 @@ abstract class BaseAnalyzer { } @protected - Iterable findReferences(AstNode node, + Iterable findReferences(AstNode node, {bool includeViews = true}) { final finder = ReferencedTablesVisitor(); node.acceptWithoutArg(finder); var entities = - finder.foundTables.map(mapper.tableToMoor); + finder.foundTables.map(mapper.tableToMoor); if (includeViews) { entities = entities.followedBy(finder.foundViews.map(mapper.viewToMoor)); } @@ -65,11 +65,11 @@ abstract class BaseAnalyzer { @protected void report(AnalysisError error, {String Function()? msg, Severity? severity}) { - if (step.file.type == FileType.moor) { + if (step.file.type == FileType.drift) { step.reportError( - ErrorInMoorFile.fromSqlParser(error, overrideSeverity: severity)); + ErrorInDriftFile.fromSqlParser(error, overrideSeverity: severity)); } else { - step.reportError(MoorError( + step.reportError(DriftError( severity: severity!, message: msg!(), )); @@ -93,7 +93,7 @@ class SqlAnalyzer extends BaseAnalyzer { final List foundQueries = []; - SqlAnalyzer(Step step, List tables, List views, + SqlAnalyzer(Step step, List tables, List views, this.definedQueries) : super(tables, views, step); @@ -125,7 +125,7 @@ class SqlAnalyzer extends BaseAnalyzer { } } } catch (e, s) { - step.reportError(MoorError( + step.reportError(DriftError( severity: Severity.criticalError, message: 'Error while trying to parse $name: $e, $s')); continue; diff --git a/drift_dev/lib/src/analyzer/sql_queries/query_handler.dart b/drift_dev/lib/src/analyzer/sql_queries/query_handler.dart index 6373fb9d..e553fb53 100644 --- a/drift_dev/lib/src/analyzer/sql_queries/query_handler.dart +++ b/drift_dev/lib/src/analyzer/sql_queries/query_handler.dart @@ -147,7 +147,7 @@ class QueryHandler { _applyFoundTables(tableFinder); final moorTables = - _foundTables.map(mapper.tableToMoor).whereType().toList(); + _foundTables.map(mapper.tableToMoor).whereType().toList(); final moorViews = _foundViews.map(mapper.viewToMoor).whereType().toList(); @@ -212,7 +212,7 @@ class QueryHandler { } final resultEntryToColumn = {}; - final resultColumnNameToMoor = {}; + final resultColumnNameToMoor = {}; var matches = true; // go trough all columns of the table in question diff --git a/drift_dev/lib/src/analyzer/sql_queries/type_mapping.dart b/drift_dev/lib/src/analyzer/sql_queries/type_mapping.dart index 833d41d2..09b6c5f3 100644 --- a/drift_dev/lib/src/analyzer/sql_queries/type_mapping.dart +++ b/drift_dev/lib/src/analyzer/sql_queries/type_mapping.dart @@ -9,15 +9,15 @@ import 'required_variables.dart'; /// Converts tables and types between the moor_generator and the sqlparser /// library. class TypeMapper { - final Map _engineTablesToSpecified = {}; + final Map _engineTablesToSpecified = {}; final Map _engineViewsToSpecified = {}; final bool applyTypeConvertersToVariables; TypeMapper({this.applyTypeConvertersToVariables = false}); - /// Convert a [MoorTable] from moor into something that can be understood + /// Convert a [DriftTable] from moor into something that can be understood /// by the sqlparser library. - Table extractStructure(MoorTable table) { + Table extractStructure(DriftTable table) { if (table.parserTable != null) { final parserTbl = table.parserTable!; _engineTablesToSpecified[parserTbl] = table; @@ -34,7 +34,7 @@ class TypeMapper { final column = TableColumn(specified.name.name, type, isGenerated: specified.isGenerated); - column.setMeta(specified); + column.setMeta(specified); columns.add(column); } @@ -44,7 +44,7 @@ class TypeMapper { resolvedColumns: columns, isVirtual: table.isVirtualTable, ); - engineTable.setMeta(table); + engineTable.setMeta(table); _engineTablesToSpecified[engineTable] = table; return engineTable; } @@ -317,7 +317,7 @@ class TypeMapper { continue; } - MoorEntityWithResultSet moorEntity; + DriftEntityWithResultSet moorEntity; if (resultSet is Table) { moorEntity = tableToMoor(resultSet)!; @@ -337,7 +337,7 @@ class TypeMapper { ..astNode = placeholder; } - MoorTable? tableToMoor(Table table) { + DriftTable? tableToMoor(Table table) { return _engineTablesToSpecified[table]; } @@ -345,7 +345,7 @@ class TypeMapper { return _engineViewsToSpecified[view]; } - MoorEntityWithResultSet? viewOrTableToMoor(dynamic entity) { + DriftEntityWithResultSet? viewOrTableToMoor(dynamic entity) { if (entity is Table) { return tableToMoor(entity); } else if (entity is View) { diff --git a/drift_dev/lib/src/analyzer/view/view_analyzer.dart b/drift_dev/lib/src/analyzer/view/view_analyzer.dart index cef463a6..46a0f415 100644 --- a/drift_dev/lib/src/analyzer/view/view_analyzer.dart +++ b/drift_dev/lib/src/analyzer/view/view_analyzer.dart @@ -1,6 +1,6 @@ import 'package:drift_dev/moor_generator.dart'; +import 'package:drift_dev/src/analyzer/drift/find_dart_class.dart'; import 'package:drift_dev/src/analyzer/errors.dart'; -import 'package:drift_dev/src/analyzer/moor/find_dart_class.dart'; import 'package:drift_dev/src/analyzer/runner/steps.dart'; import 'package:drift_dev/src/analyzer/sql_queries/query_analyzer.dart'; import 'package:drift_dev/src/utils/type_converter_hint.dart'; @@ -11,15 +11,15 @@ import '../dart_types.dart'; class ViewAnalyzer extends BaseAnalyzer { final List imports; - ViewAnalyzer(Step step, List tables, this.imports) + ViewAnalyzer(Step step, List tables, this.imports) : super(tables, const [], step); /// Resolves all the views in topological order. Future resolve(Iterable viewsToAnalyze) async { // Going through the topologically sorted list and analyzing each view. for (final view in viewsToAnalyze) { - if (view.declaration is! MoorViewDeclaration) continue; - final viewDeclaration = view.declaration as MoorViewDeclaration; + if (view.declaration is! DriftViewDeclaration) continue; + final viewDeclaration = view.declaration as DriftViewDeclaration; final ctx = engine.analyzeNode(viewDeclaration.node, view.file!.parseResult.sql); @@ -30,7 +30,7 @@ class ViewAnalyzer extends BaseAnalyzer { const SchemaFromCreateTable(driftExtensions: true) .readView(ctx, declaration); - final columns = []; + final columns = []; final columnDartNames = {}; for (final column in parserView.resolvedColumns) { final type = column.type; @@ -39,7 +39,7 @@ class ViewAnalyzer extends BaseAnalyzer { converter = (type.hint as TypeConverterHint).converter; } - final moorColumn = MoorColumn( + final moorColumn = DriftColumn( type: mapper.resolvedToMoor(type), name: ColumnName.explicitly(column.name), nullable: type?.nullable == true, @@ -59,7 +59,7 @@ class ViewAnalyzer extends BaseAnalyzer { if (desiredNames.useExistingDartClass) { final clazz = await findDartClass(step, imports, dataClassName); if (clazz == null) { - step.reportError(ErrorInMoorFile( + step.reportError(ErrorInDriftFile( span: declaration.viewNameToken!.span, message: 'Existing Dart class $dataClassName was not found, are ' 'you missing an import?', diff --git a/drift_dev/lib/src/backends/build/build_backend.dart b/drift_dev/lib/src/backends/build/build_backend.dart index 5faa8405..6c24ccc3 100644 --- a/drift_dev/lib/src/backends/build/build_backend.dart +++ b/drift_dev/lib/src/backends/build/build_backend.dart @@ -9,9 +9,9 @@ import 'package:drift_dev/src/backends/backend.dart'; import 'package:logging/logging.dart'; class BuildBackend extends Backend { - final MoorOptions options; + final DriftOptions options; - BuildBackend([this.options = const MoorOptions.defaults()]); + BuildBackend([this.options = const DriftOptions.defaults()]); BuildBackendTask createTask(BuildStep step) { return BuildBackendTask(step, this); @@ -71,7 +71,7 @@ class BuildBackendTask extends BackendTask { // we try to detect all calls of resolveTypeOf in an earlier builder and // prepare the result. See PreprocessBuilder for details final preparedHelperFile = - _resolve(context).changeExtension('.dart_in_moor'); + _resolve(context).changeExtension('.dart_in_drift'); final temporaryFile = _resolve(context).changeExtension('.temp.dart'); if (!await step.canRead(preparedHelperFile)) { diff --git a/drift_dev/lib/src/backends/build/moor_builder.dart b/drift_dev/lib/src/backends/build/drift_builder.dart similarity index 75% rename from drift_dev/lib/src/backends/build/moor_builder.dart rename to drift_dev/lib/src/backends/build/drift_builder.dart index 721efc9b..dbcdbd71 100644 --- a/drift_dev/lib/src/backends/build/moor_builder.dart +++ b/drift_dev/lib/src/backends/build/drift_builder.dart @@ -6,7 +6,7 @@ import 'package:drift_dev/src/analyzer/runner/task.dart'; import 'package:drift_dev/src/analyzer/session.dart'; import 'package:drift_dev/src/backends/build/build_backend.dart'; import 'package:drift_dev/src/backends/build/generators/dao_generator.dart'; -import 'package:drift_dev/src/backends/build/generators/moor_generator.dart'; +import 'package:drift_dev/src/backends/build/generators/database_generator.dart'; import 'package:drift_dev/writer.dart'; import 'package:source_gen/source_gen.dart'; @@ -16,8 +16,8 @@ class _BuilderFlags { final _flags = Resource(() => _BuilderFlags()); -mixin MoorBuilder on Builder { - MoorOptions get options; +mixin DriftBuilder on Builder { + DriftOptions get options; bool get isForNewDriftPackage; Writer createWriter() { @@ -48,14 +48,14 @@ mixin MoorBuilder on Builder { } } -T _createBuilder( +T _createBuilder( BuilderOptions options, - T Function(List generators, MoorOptions parsedOptions) creator, + T Function(List generators, DriftOptions parsedOptions) creator, ) { - final parsedOptions = MoorOptions.fromJson(options.config); + final parsedOptions = DriftOptions.fromJson(options.config); final generators = [ - MoorGenerator(), + DriftDatabaseGenerator(), DaoGenerator(), ]; @@ -68,21 +68,21 @@ T _createBuilder( return builder; } -class MoorSharedPartBuilder extends SharedPartBuilder with MoorBuilder { +class DriftSharedPartBuilder extends SharedPartBuilder with DriftBuilder { @override - final MoorOptions options; + final DriftOptions options; @override final bool isForNewDriftPackage; - MoorSharedPartBuilder._(List generators, String name, this.options, - this.isForNewDriftPackage) + DriftSharedPartBuilder._(List generators, String name, + this.options, this.isForNewDriftPackage) : super(generators, name); - factory MoorSharedPartBuilder(BuilderOptions options, + factory DriftSharedPartBuilder(BuilderOptions options, {bool isForNewDriftPackage = false}) { return _createBuilder(options, (generators, parsedOptions) { - return MoorSharedPartBuilder._( + return DriftSharedPartBuilder._( generators, 'moor', parsedOptions, isForNewDriftPackage); }); } @@ -102,21 +102,21 @@ class MoorSharedPartBuilder extends SharedPartBuilder with MoorBuilder { } } -class MoorPartBuilder extends PartBuilder with MoorBuilder { +class DriftPartBuilder extends PartBuilder with DriftBuilder { @override - final MoorOptions options; + final DriftOptions options; @override final bool isForNewDriftPackage; - MoorPartBuilder._(List generators, String extension, this.options, + DriftPartBuilder._(List generators, String extension, this.options, this.isForNewDriftPackage) : super(generators, extension); - factory MoorPartBuilder(BuilderOptions options, + factory DriftPartBuilder(BuilderOptions options, {bool isForNewDriftPackage = false}) { return _createBuilder(options, (generators, parsedOptions) { - return MoorPartBuilder._( + return DriftPartBuilder._( generators, isForNewDriftPackage ? '.drift.dart' : '.moor.dart', parsedOptions, @@ -126,5 +126,5 @@ class MoorPartBuilder extends PartBuilder with MoorBuilder { } abstract class BaseGenerator { - late MoorBuilder builder; + late DriftBuilder builder; } diff --git a/drift_dev/lib/src/backends/build/generators/dao_generator.dart b/drift_dev/lib/src/backends/build/generators/dao_generator.dart index eb624337..c719a10c 100644 --- a/drift_dev/lib/src/backends/build/generators/dao_generator.dart +++ b/drift_dev/lib/src/backends/build/generators/dao_generator.dart @@ -1,5 +1,5 @@ import 'package:build/build.dart'; -import 'package:drift_dev/src/backends/build/moor_builder.dart'; +import 'package:drift_dev/src/backends/build/drift_builder.dart'; import 'package:drift_dev/src/utils/type_utils.dart'; import 'package:drift_dev/writer.dart'; import 'package:source_gen/source_gen.dart'; @@ -8,7 +8,7 @@ import '../../../model/base_entity.dart'; class DaoGenerator extends Generator implements BaseGenerator { @override - late MoorBuilder builder; + late DriftBuilder builder; @override Future generate(LibraryReader library, BuildStep buildStep) async { @@ -25,7 +25,7 @@ class DaoGenerator extends Generator implements BaseGenerator { classScope.leaf().write('mixin _\$${daoName}Mixin on ' 'DatabaseAccessor<$dbTypeName> {\n'); - for (final entity in dao.entities.whereType()) { + for (final entity in dao.entities.whereType()) { final infoType = entity.entityInfoName; final getterName = entity.dbGetterName; classScope.leaf().write( diff --git a/drift_dev/lib/src/backends/build/generators/moor_generator.dart b/drift_dev/lib/src/backends/build/generators/database_generator.dart similarity index 88% rename from drift_dev/lib/src/backends/build/generators/moor_generator.dart rename to drift_dev/lib/src/backends/build/generators/database_generator.dart index c990db84..4a232a0b 100644 --- a/drift_dev/lib/src/backends/build/generators/moor_generator.dart +++ b/drift_dev/lib/src/backends/build/generators/database_generator.dart @@ -1,14 +1,14 @@ import 'package:build/build.dart'; -import 'package:drift_dev/src/backends/build/moor_builder.dart'; +import 'package:drift_dev/src/backends/build/drift_builder.dart'; import 'package:drift_dev/writer.dart'; import 'package:pub_semver/pub_semver.dart'; import 'package:source_gen/source_gen.dart'; final _minLanguageVersion = Version(2, 12, 0); -class MoorGenerator extends Generator implements BaseGenerator { +class DriftDatabaseGenerator extends Generator implements BaseGenerator { @override - late MoorBuilder builder; + late DriftBuilder builder; @override Future generate(LibraryReader library, BuildStep buildStep) async { diff --git a/drift_dev/lib/src/backends/build/preprocess_builder.dart b/drift_dev/lib/src/backends/build/preprocess_builder.dart index 799d9523..34c537bc 100644 --- a/drift_dev/lib/src/backends/build/preprocess_builder.dart +++ b/drift_dev/lib/src/backends/build/preprocess_builder.dart @@ -5,26 +5,26 @@ import 'package:build/build.dart'; import 'package:drift_dev/src/utils/string_escaper.dart'; import 'package:sqlparser/sqlparser.dart'; -/// A support builder that runs before the main moor_generator to parse and -/// resolve inline Dart resources in a moor file. +/// A support builder that runs before the main generator to parse and resolve +/// inline Dart resources in a moor file. /// -/// We use this builder to extract and analyze inline Dart expressions from moor -/// files, which are mainly used for type converters. For instance, let's say -/// we had a moor file like this: +/// We use this builder to extract and analyze inline Dart expressions from +/// drift files, which are mainly used for type converters. For instance, let's +/// say we had a drift file like this: /// ``` -/// -- called input.moor +/// -- called input.drift /// import 'package:my_package/converter.dart'; /// /// CREATE TABLE users ( /// preferences TEXT MAPPED BY `const PreferencesConverter()` /// ); /// ``` -/// For that file, the [PreprocessBuilder] would generate a `.dart_in_moor` file -/// which contains information about the static type of all expressions in the -/// moor file. The main generator can then read the `.dart_in_moor` file to -/// resolve those expressions. +/// For that file, the [PreprocessBuilder] would generate a `.dart_in_drift` +/// file which contains information about the static type of all expressions in +/// the drift file. The main generator can then read the `.dart_in_drift` file +/// to resolve those expressions. class PreprocessBuilder extends Builder { - static const _outputs = ['.temp.dart', '.dart_in_moor']; + static const _outputs = ['.temp.dart', '.dart_in_drift']; final bool isForNewDriftPackage; @@ -112,7 +112,7 @@ class PreprocessBuilder extends Builder { await buildStep.writeAsString(tempDartAsset, dartBuffer.toString()); // And the file mapping Dart expressions onto the variable names here - final outputAsset = input.changeExtension('.dart_in_moor'); + final outputAsset = input.changeExtension('.dart_in_drift'); await buildStep.writeAsString(outputAsset, json.encode(codeToField)); } diff --git a/drift_dev/lib/src/backends/common/driver.dart b/drift_dev/lib/src/backends/common/driver.dart index b0162f01..7aff3a82 100644 --- a/drift_dev/lib/src/backends/common/driver.dart +++ b/drift_dev/lib/src/backends/common/driver.dart @@ -28,7 +28,7 @@ class MoorDriver { MoorDriver(this._resourceProvider, {required String contextRoot, String? sdkPath, - MoorOptions options = const MoorOptions.defaults()}) { + DriftOptions options = const DriftOptions.defaults()}) { final overlayed = OverlayResourceProvider(_resourceProvider); final collection = AnalysisContextCollection( includedPaths: [contextRoot], @@ -44,7 +44,7 @@ class MoorDriver { MoorDriver.forContext(this._resourceProvider, this.context) { final overlayed = OverlayResourceProvider(_resourceProvider); backend = StandaloneBackend(context, overlayed); - session = MoorSession(backend, options: const MoorOptions.defaults()); + session = MoorSession(backend, options: const DriftOptions.defaults()); } bool _ownsFile(String path) => @@ -85,7 +85,7 @@ class MoorDriver { } } - /// Attempt to load the appropriate [MoorOptions] by reading the `build.yaml` + /// Attempt to load the appropriate [DriftOptions] by reading the `build.yaml` /// located in the context root. /// /// When something fails, the default options will be used an an error message diff --git a/drift_dev/lib/src/backends/plugin/logger.dart b/drift_dev/lib/src/backends/plugin/logger.dart index f1376303..cc4bc174 100644 --- a/drift_dev/lib/src/backends/plugin/logger.dart +++ b/drift_dev/lib/src/backends/plugin/logger.dart @@ -7,7 +7,7 @@ var _initialized = false; /// Configures the [Logger.root] logger to work with the plugin. Sadly, we don't /// really have a way to view [print] outputs from plugins, so we use the /// diagnostics notification for that. -void setupLogger(MoorPlugin plugin) { +void setupLogger(DriftPlugin plugin) { assert(!_initialized, 'Logger initialized multiple times'); Logger.root.level = Level.ALL; diff --git a/drift_dev/lib/src/backends/plugin/plugin.dart b/drift_dev/lib/src/backends/plugin/plugin.dart index 1ea95b8b..6dffdb77 100644 --- a/drift_dev/lib/src/backends/plugin/plugin.dart +++ b/drift_dev/lib/src/backends/plugin/plugin.dart @@ -25,18 +25,18 @@ import 'package:drift_dev/src/services/ide/moor_ide.dart'; import 'logger.dart'; -class MoorPlugin extends ServerPlugin +class DriftPlugin extends ServerPlugin with OutlineMixin, FoldingMixin, CompletionMixin, NavigationMixin { final Map drivers = {}; late final ErrorService errorService = ErrorService(this); - MoorPlugin(ResourceProvider provider) : super(resourceProvider: provider) { + DriftPlugin(ResourceProvider provider) : super(resourceProvider: provider) { setupLogger(this); } - factory MoorPlugin.forProduction() { - return MoorPlugin(PhysicalResourceProvider.INSTANCE); + factory DriftPlugin.forProduction() { + return DriftPlugin(PhysicalResourceProvider.INSTANCE); } @override @@ -136,7 +136,7 @@ class MoorPlugin extends ServerPlugin } void _checkIsMoorFile(FoundFile file) { - if (file.type != FileType.moor) { + if (file.type != FileType.drift) { throw RequestFailure( plugin.RequestError(plugin.RequestErrorCode.INVALID_PARAMETER, 'Not a moor file: ${file.uri}'), diff --git a/drift_dev/lib/src/backends/plugin/services/errors.dart b/drift_dev/lib/src/backends/plugin/services/errors.dart index 4d052caf..8e833200 100644 --- a/drift_dev/lib/src/backends/plugin/services/errors.dart +++ b/drift_dev/lib/src/backends/plugin/services/errors.dart @@ -9,7 +9,7 @@ const _genericError = 'moor.errorGeneric'; /// Sends information about errors, lints and warnings encountered in a `.moor` /// file to the analyzer. class ErrorService { - final MoorPlugin plugin; + final DriftPlugin plugin; ErrorService(this.plugin); @@ -39,8 +39,8 @@ class ErrorService { plugin.channel.sendNotification(params.toNotification()); } - Location _findLocationForError(MoorError error, String path) { - if (error is ErrorInMoorFile) { + Location _findLocationForError(DriftError error, String path) { + if (error is ErrorInDriftFile) { final span = error.span; final start = span.start; final end = span.end; diff --git a/drift_dev/lib/src/backends/plugin/services/navigation.dart b/drift_dev/lib/src/backends/plugin/services/navigation.dart index b86ec21e..ee0f34b0 100644 --- a/drift_dev/lib/src/backends/plugin/services/navigation.dart +++ b/drift_dev/lib/src/backends/plugin/services/navigation.dart @@ -83,7 +83,7 @@ class _NavigationVisitor extends RecursiveVisitor { } Iterable _locationOfColumn(Column column) sync* { - final declaration = column.meta()?.declaration; + final declaration = column.meta()?.declaration; if (declaration != null) { // the column was declared in a table and we happen to know where the // declaration is - point to that declaration. @@ -110,7 +110,7 @@ class _NavigationVisitor extends RecursiveVisitor { final resolved = e.resolved; if (resolved is Table) { - final declaration = resolved.meta()?.declaration; + final declaration = resolved.meta()?.declaration; if (declaration != null) { _reportForSpan( e.span, ElementKind.CLASS, locationOfDeclaration(declaration)!); diff --git a/drift_dev/lib/src/backends/plugin/services/requests.dart b/drift_dev/lib/src/backends/plugin/services/requests.dart index 6e8710f1..2092b3b6 100644 --- a/drift_dev/lib/src/backends/plugin/services/requests.dart +++ b/drift_dev/lib/src/backends/plugin/services/requests.dart @@ -12,15 +12,15 @@ import 'package:source_span/source_span.dart'; mixin _MoorBaseRequest { FoundFile get file; - bool get isMoor => file.type == FileType.moor; + bool get isMoor => file.type == FileType.drift; bool get isMoorAndParsed => isMoor && file.isParsed; bool get isMoorAndAnalyzed => isMoor && file.isAnalyzed; String get path => file.uri.path; - ParsedMoorFile get parsedMoor { + ParsedDriftFile get parsedMoor { assert(isMoorAndParsed); - return file.currentResult as ParsedMoorFile; + return file.currentResult as ParsedDriftFile; } } diff --git a/drift_dev/lib/src/backends/plugin/utils/ast_to_location.dart b/drift_dev/lib/src/backends/plugin/utils/ast_to_location.dart index b560943b..d0ba1d2d 100644 --- a/drift_dev/lib/src/backends/plugin/utils/ast_to_location.dart +++ b/drift_dev/lib/src/backends/plugin/utils/ast_to_location.dart @@ -33,7 +33,7 @@ Location? locationOfDeclaration(Declaration declaration) { final file = declaration.declaration.file; if (declaration is DartDeclaration) { return _locationForSpan(spanForElement(declaration.element), file); - } else if (declaration is MoorDeclaration) { + } else if (declaration is DriftFileDeclaration) { return locationOfNode(file, declaration.node); } diff --git a/drift_dev/lib/src/cli/commands/schema/generate_utils.dart b/drift_dev/lib/src/cli/commands/schema/generate_utils.dart index aa0b4e90..9ca448ab 100644 --- a/drift_dev/lib/src/cli/commands/schema/generate_utils.dart +++ b/drift_dev/lib/src/cli/commands/schema/generate_utils.dart @@ -78,9 +78,9 @@ class GenerateUtilsCommand extends Command { 'Wrote ${schema.length + 1} files into ${p.relative(outputDir.path)}'); } - Future>> _parseSchema( + Future>> _parseSchema( Directory directory) async { - final results = >{}; + final results = >{}; await for (final entity in directory.list()) { final basename = p.basename(entity.path); @@ -101,7 +101,7 @@ class GenerateUtilsCommand extends Command { Future _writeSchemaFile( Directory output, int version, - List entities, + List entities, bool dataClasses, bool companions, bool isForMoor, diff --git a/drift_dev/lib/src/cli/project.dart b/drift_dev/lib/src/cli/project.dart index 37e20958..5d11869b 100644 --- a/drift_dev/lib/src/cli/project.dart +++ b/drift_dev/lib/src/cli/project.dart @@ -11,7 +11,7 @@ import 'package:stream_transform/stream_transform.dart'; class MoorProject { /// The build configuration for this project. final BuildConfig buildConfig; - final MoorOptions moorOptions; + final DriftOptions moorOptions; final Directory directory; diff --git a/drift_dev/lib/src/model/base_entity.dart b/drift_dev/lib/src/model/base_entity.dart index df4337b1..8ef33210 100644 --- a/drift_dev/lib/src/model/base_entity.dart +++ b/drift_dev/lib/src/model/base_entity.dart @@ -7,7 +7,7 @@ import 'package:drift_dev/writer.dart'; /// Some schema entity found. /// /// Most commonly a table, but it can also be a trigger. -abstract class MoorSchemaEntity implements HasDeclaration { +abstract class DriftSchemaEntity implements HasDeclaration { /// All entities that have to be created before this entity can be created. /// /// For tables, this can be contents of a `REFERENCES` clause. For triggers, @@ -18,7 +18,7 @@ abstract class MoorSchemaEntity implements HasDeclaration { /// /// The generator will verify that the graph of entities and [references] /// is acyclic and sort them topologically. - Iterable get references; + Iterable get references; /// A human readable name of this entity, like the table name. String get displayName; @@ -29,9 +29,9 @@ abstract class MoorSchemaEntity implements HasDeclaration { String? get dbGetterName; } -abstract class MoorEntityWithResultSet extends MoorSchemaEntity { +abstract class DriftEntityWithResultSet extends DriftSchemaEntity { /// The columns declared in this table or view. - List get columns; + List get columns; /// The name of the Dart row class for this result set. @Deprecated('Use dartTypeCode instead') @@ -70,7 +70,7 @@ class ExistingRowClass { /// The Dart types that should be used to instantiate the [targetClass]. final List typeInstantiation; final ConstructorElement constructor; - final Map mapping; + final Map mapping; /// Generate toCompanion for data class final bool generateInsertable; diff --git a/drift_dev/lib/src/model/column.dart b/drift_dev/lib/src/model/column.dart index 5a329e5e..f47798c9 100644 --- a/drift_dev/lib/src/model/column.dart +++ b/drift_dev/lib/src/model/column.dart @@ -45,7 +45,7 @@ class ColumnName { } /// A column, as specified by a getter in a table. -class MoorColumn implements HasDeclaration, HasType { +class DriftColumn implements HasDeclaration, HasType { /// The getter name of this column in the table class. It will also be used /// as getter name in the TableInfo class (as it needs to override the field) /// and in the generated data class that will be generated for each table. @@ -68,7 +68,7 @@ class MoorColumn implements HasDeclaration, HasType { /// An (optional) name to use as a json key instead of the [dartGetterName]. final String? overriddenJsonName; - String getJsonKey([MoorOptions options = const MoorOptions.defaults()]) { + String getJsonKey([DriftOptions options = const DriftOptions.defaults()]) { if (overriddenJsonName != null) return overriddenJsonName!; final useColumnName = options.useColumnNameAsJsonKeyWhenDefinedInMoorFile && @@ -112,7 +112,7 @@ class MoorColumn implements HasDeclaration, HasType { bool get isGenerated => generatedAs != null; /// Parent table - MoorTable? table; + DriftTable? table; /// The column type from the dsl library. For instance, if a table has /// declared an `IntColumn`, the matching dsl column name would also be an @@ -186,7 +186,7 @@ class MoorColumn implements HasDeclaration, HasType { @override bool get isArray => false; - MoorColumn({ + DriftColumn({ required this.type, required this.dartGetterName, required this.name, @@ -273,8 +273,8 @@ class UnresolvedDartForeignKeyReference extends ColumnFeature { } class ResolvedDartForeignKeyReference extends ColumnFeature { - final MoorTable otherTable; - final MoorColumn otherColumn; + final DriftTable otherTable; + final DriftColumn otherColumn; final ReferenceAction? onUpdate; final ReferenceAction? onDelete; diff --git a/drift_dev/lib/src/model/database.dart b/drift_dev/lib/src/model/database.dart index 289baad2..85cde1a8 100644 --- a/drift_dev/lib/src/model/database.dart +++ b/drift_dev/lib/src/model/database.dart @@ -4,7 +4,7 @@ import 'package:drift_dev/moor_generator.dart'; import 'package:drift_dev/src/analyzer/runner/file_graph.dart'; /// Abstract class for database and dao elements. -abstract class BaseMoorAccessor implements HasDeclaration { +abstract class BaseDriftAccessor implements HasDeclaration { @override final DatabaseOrDaoDeclaration? declaration; @@ -16,7 +16,7 @@ abstract class BaseMoorAccessor implements HasDeclaration { /// This contains the `tables` field from a `UseMoor` or `UseDao` annotation, /// but not tables that are declared in imported moor files. Use [tables] for /// that. - final List declaredTables; + final List declaredTables; /// All views that have been declared on this accessor directly. /// @@ -33,11 +33,11 @@ abstract class BaseMoorAccessor implements HasDeclaration { /// All entities for this database accessor. This contains [declaredTables] /// and all tables, triggers and other entities available through includes. - List entities = []; + List entities = []; /// All tables for this database accessor. This contains the [declaredTables] /// and all tables that are reachable through includes. - Iterable get tables => entities.whereType(); + Iterable get tables => entities.whereType(); /// All views for this database accesssor. Iterable get views => entities.whereType(); @@ -51,12 +51,12 @@ abstract class BaseMoorAccessor implements HasDeclaration { /// Resolved imports from this file. List? imports = []; - BaseMoorAccessor._(this.declaration, this.declaredTables, this.declaredViews, + BaseDriftAccessor._(this.declaration, this.declaredTables, this.declaredViews, this.declaredIncludes, this.declaredQueries); } /// A database, declared via a `UseMoor` annotation on a Dart class. -class Database extends BaseMoorAccessor { +class Database extends BaseDriftAccessor { final List daos; /// If the source database class overrides `schemaVersion` and returns a @@ -70,7 +70,7 @@ class Database extends BaseMoorAccessor { this.daos = const [], this.schemaVersion, DatabaseOrDaoDeclaration? declaration, - List declaredTables = const [], + List declaredTables = const [], List declaredViews = const [], List declaredIncludes = const [], List declaredQueries = const [], @@ -79,14 +79,14 @@ class Database extends BaseMoorAccessor { } /// A dao, declared via an `UseDao` annotation on a Dart class. -class Dao extends BaseMoorAccessor { +class Dao extends BaseDriftAccessor { /// The database class this dao belongs to. final DartType dbClass; Dao({ required this.dbClass, DatabaseOrDaoDeclaration? declaration, - required List declaredTables, + required List declaredTables, List declaredViews = const [], required List declaredIncludes, required List declaredQueries, diff --git a/drift_dev/lib/src/model/declarations/columns.dart b/drift_dev/lib/src/model/declarations/columns.dart index f0fcf43a..a6c163a7 100644 --- a/drift_dev/lib/src/model/declarations/columns.dart +++ b/drift_dev/lib/src/model/declarations/columns.dart @@ -27,17 +27,18 @@ class DartColumnDeclaration implements DartDeclaration, ColumnDeclaration { bool get isDefinedInMoorFile => false; } -class MoorColumnDeclaration implements MoorDeclaration, ColumnDeclaration { +class DriftColumnDeclaration + implements DriftFileDeclaration, ColumnDeclaration { @override final SourceRange declaration; @override final AstNode node; - MoorColumnDeclaration._(this.declaration, this.node); + DriftColumnDeclaration._(this.declaration, this.node); - factory MoorColumnDeclaration(AstNode node, FoundFile file) { - return MoorColumnDeclaration._( + factory DriftColumnDeclaration(AstNode node, FoundFile file) { + return DriftColumnDeclaration._( SourceRange.fromNodeAndFile(node, file), node, ); diff --git a/drift_dev/lib/src/model/declarations/declaration.dart b/drift_dev/lib/src/model/declarations/declaration.dart index 775b3c28..f5e0d972 100644 --- a/drift_dev/lib/src/model/declarations/declaration.dart +++ b/drift_dev/lib/src/model/declarations/declaration.dart @@ -34,22 +34,22 @@ abstract class DartDeclaration extends Declaration { } /// Declaration for elements that are declared in a `.moor` file. -abstract class MoorDeclaration extends Declaration { +abstract class DriftFileDeclaration extends Declaration { /// The ast node from a moor file for this declaration. AstNode get node; } -extension ToSql on MoorDeclaration { - String exportSql(MoorOptions options) { +extension ToSql on DriftFileDeclaration { + String exportSql(DriftOptions options) { final writer = SqlWriter(options, escapeForDart: false); return writer.writeSql(node); } } extension ToSqlIfAvailable on Declaration { - String? formatSqlIfAvailable(MoorOptions options) { + String? formatSqlIfAvailable(DriftOptions options) { final $this = this; - if ($this is MoorDeclaration) { + if ($this is DriftFileDeclaration) { return $this.exportSql(options); } @@ -60,5 +60,5 @@ extension ToSqlIfAvailable on Declaration { extension DeclarationUtils on HasDeclaration { bool get isDeclaredInDart => declaration is DartDeclaration; - bool get isDeclaredInDriftFile => declaration is MoorDeclaration; + bool get isDeclaredInDriftFile => declaration is DriftFileDeclaration; } diff --git a/drift_dev/lib/src/model/declarations/index.dart b/drift_dev/lib/src/model/declarations/index.dart index da8ba770..4cc2b4b6 100644 --- a/drift_dev/lib/src/model/declarations/index.dart +++ b/drift_dev/lib/src/model/declarations/index.dart @@ -2,14 +2,14 @@ part of 'declaration.dart'; abstract class IndexDeclaration extends Declaration {} -class MoorIndexDeclaration implements MoorDeclaration, IndexDeclaration { +class DriftIndexDeclaration implements DriftFileDeclaration, IndexDeclaration { @override final SourceRange declaration; @override final CreateIndexStatement node; - MoorIndexDeclaration.fromNodeAndFile(this.node, FoundFile file) + DriftIndexDeclaration.fromNodeAndFile(this.node, FoundFile file) : declaration = SourceRange.fromNodeAndFile(node, file); } diff --git a/drift_dev/lib/src/model/declarations/special_queries.dart b/drift_dev/lib/src/model/declarations/special_queries.dart index 69f5b785..cfebaeeb 100644 --- a/drift_dev/lib/src/model/declarations/special_queries.dart +++ b/drift_dev/lib/src/model/declarations/special_queries.dart @@ -2,14 +2,14 @@ part of 'declaration.dart'; abstract class SpecialQueryDeclaration extends Declaration {} -class MoorSpecialQueryDeclaration - implements MoorDeclaration, SpecialQueryDeclaration { +class DriftSpecialQueryDeclaration + implements DriftFileDeclaration, SpecialQueryDeclaration { @override final SourceRange declaration; @override final DeclaredStatement node; - MoorSpecialQueryDeclaration.fromNodeAndFile(this.node, FoundFile file) + DriftSpecialQueryDeclaration.fromNodeAndFile(this.node, FoundFile file) : declaration = SourceRange.fromNodeAndFile(node, file); } diff --git a/drift_dev/lib/src/model/declarations/tables.dart b/drift_dev/lib/src/model/declarations/tables.dart index d8f5bf75..6b5625dd 100644 --- a/drift_dev/lib/src/model/declarations/tables.dart +++ b/drift_dev/lib/src/model/declarations/tables.dart @@ -33,18 +33,18 @@ class DartTableDeclaration implements TableDeclaration, DartDeclaration { } } -class MoorTableDeclaration - implements TableDeclaration, MoorDeclaration, TableDeclarationWithSql { +class DriftTableDeclaration + implements TableDeclaration, DriftFileDeclaration, TableDeclarationWithSql { @override final SourceRange declaration; @override final TableInducingStatement node; - MoorTableDeclaration._(this.declaration, this.node); + DriftTableDeclaration._(this.declaration, this.node); - factory MoorTableDeclaration(TableInducingStatement node, FoundFile file) { - return MoorTableDeclaration._( + factory DriftTableDeclaration(TableInducingStatement node, FoundFile file) { + return DriftTableDeclaration._( SourceRange.fromNodeAndFile(node, file), node, ); diff --git a/drift_dev/lib/src/model/declarations/trigger.dart b/drift_dev/lib/src/model/declarations/trigger.dart index ee7b5441..215c23fb 100644 --- a/drift_dev/lib/src/model/declarations/trigger.dart +++ b/drift_dev/lib/src/model/declarations/trigger.dart @@ -5,14 +5,15 @@ abstract class TriggerDeclaration extends Declaration { String get createSql; } -class MoorTriggerDeclaration implements MoorDeclaration, TriggerDeclaration { +class DriftTriggerDeclaration + implements DriftFileDeclaration, TriggerDeclaration { @override final SourceRange declaration; @override final CreateTriggerStatement node; - MoorTriggerDeclaration.fromNodeAndFile(this.node, FoundFile file) + DriftTriggerDeclaration.fromNodeAndFile(this.node, FoundFile file) : declaration = SourceRange.fromNodeAndFile(node, file); @override diff --git a/drift_dev/lib/src/model/declarations/views.dart b/drift_dev/lib/src/model/declarations/views.dart index 4c2f0958..df509fae 100644 --- a/drift_dev/lib/src/model/declarations/views.dart +++ b/drift_dev/lib/src/model/declarations/views.dart @@ -32,24 +32,24 @@ class DartViewDeclaration implements ViewDeclaration, DartDeclaration { } class TableReferenceInDartView { - final MoorTable table; + final DriftTable table; final String name; TableReferenceInDartView(this.table, this.name); } -class MoorViewDeclaration - implements ViewDeclaration, MoorDeclaration, ViewDeclarationWithSql { +class DriftViewDeclaration + implements ViewDeclaration, DriftFileDeclaration, ViewDeclarationWithSql { @override final SourceRange declaration; @override final CreateViewStatement node; - MoorViewDeclaration._(this.declaration, this.node); + DriftViewDeclaration._(this.declaration, this.node); - factory MoorViewDeclaration(CreateViewStatement node, FoundFile file) { - return MoorViewDeclaration._( + factory DriftViewDeclaration(CreateViewStatement node, FoundFile file) { + return DriftViewDeclaration._( SourceRange.fromNodeAndFile(node, file), node, ); diff --git a/drift_dev/lib/src/model/index.dart b/drift_dev/lib/src/model/index.dart index d27477ef..22604cc3 100644 --- a/drift_dev/lib/src/model/index.dart +++ b/drift_dev/lib/src/model/index.dart @@ -7,11 +7,11 @@ import 'model.dart'; /// An sql index. /// /// Indices can only be declared in moor files at the moment. -class MoorIndex extends MoorSchemaEntity { +class MoorIndex extends DriftSchemaEntity { /// The table on which this index is created. /// /// This field can be null in case the table wasn't resolved. - MoorTable? table; + DriftTable? table; final String name; /// The sql statement creating this index. @@ -25,7 +25,7 @@ class MoorIndex extends MoorSchemaEntity { factory MoorIndex.fromMoor(CreateIndexStatement stmt, FoundFile file) { return MoorIndex( stmt.indexName, - MoorIndexDeclaration.fromNodeAndFile(stmt, file), + DriftIndexDeclaration.fromNodeAndFile(stmt, file), stmt.span!.text, ); } @@ -40,12 +40,12 @@ class MoorIndex extends MoorSchemaEntity { /// /// Unlike [createStmt], this can be formatted to exclude comments and /// unnecessary whitespace depending on the [options]. - String createSql(MoorOptions options) { + String createSql(DriftOptions options) { return declaration.formatSqlIfAvailable(options) ?? createStmt; } @override - Iterable get references { + Iterable get references { if (table == null) { return const Iterable.empty(); } diff --git a/drift_dev/lib/src/model/special_queries.dart b/drift_dev/lib/src/model/special_queries.dart index bb7294b6..32e0eea3 100644 --- a/drift_dev/lib/src/model/special_queries.dart +++ b/drift_dev/lib/src/model/special_queries.dart @@ -12,7 +12,7 @@ enum SpecialQueryMode { /// A special query, such as the ones executes when the database was created. /// /// Those are generated from `@created:` queries in moor files. -class SpecialQuery implements MoorSchemaEntity { +class SpecialQuery implements DriftSchemaEntity { final String sql; final SpecialQueryMode mode; @override @@ -23,7 +23,7 @@ class SpecialQuery implements MoorSchemaEntity { factory SpecialQuery.fromMoor(DeclaredStatement stmt, FoundFile file) { return SpecialQuery(stmt.statement.span!.text, - MoorSpecialQueryDeclaration.fromNodeAndFile(stmt, file)); + DriftSpecialQueryDeclaration.fromNodeAndFile(stmt, file)); } @override @@ -34,11 +34,11 @@ class SpecialQuery implements MoorSchemaEntity { throw UnsupportedError("Special queries don't have a name"); @override - List references = []; + List references = []; - String formattedSql(MoorOptions options) { + String formattedSql(DriftOptions options) { final decl = declaration; - if (decl is MoorSpecialQueryDeclaration) { + if (decl is DriftSpecialQueryDeclaration) { final writer = SqlWriter(options, escapeForDart: false); return writer.writeSql(decl.node.statement); } diff --git a/drift_dev/lib/src/model/sql_query.dart b/drift_dev/lib/src/model/sql_query.dart index b5287905..1290bc59 100644 --- a/drift_dev/lib/src/model/sql_query.dart +++ b/drift_dev/lib/src/model/sql_query.dart @@ -35,7 +35,7 @@ class DeclaredDartQuery extends DeclaredQuery { /// available. class DeclaredMoorQuery extends DeclaredQuery { final DeclaredStatement astNode; - ParsedMoorFile? file; + ParsedDriftFile? file; DeclaredMoorQuery(String name, this.astNode) : super(name); @@ -176,7 +176,7 @@ abstract class SqlQuery { } class SqlSelectQuery extends SqlQuery { - final List readsFrom; + final List readsFrom; @override final InferredResultSet resultSet; @override @@ -205,10 +205,10 @@ class SqlSelectQuery extends SqlQuery { this.nestedContainer, ) : super(name, elements, hasMultipleTables: readsFrom.length > 1); - Set get readsFromTables { + Set get readsFromTables { return { for (final entity in readsFrom) - if (entity is MoorTable) + if (entity is DriftTable) entity else if (entity is MoorView) ...entity.transitiveTableReferences, @@ -435,8 +435,8 @@ class InferredResultSet { /// /// We still need to handle column aliases. class MatchingMoorTable { - final MoorEntityWithResultSet table; - final Map aliasToColumn; + final DriftEntityWithResultSet table; + final Map aliasToColumn; MatchingMoorTable(this.table, this.aliasToColumn); @@ -524,7 +524,7 @@ class NestedResultTable extends NestedResult { final bool isNullable; final NestedStarResultColumn from; final String name; - final MoorEntityWithResultSet table; + final DriftEntityWithResultSet table; NestedResultTable(this.from, this.name, this.table, {this.isNullable = true}); @@ -747,7 +747,7 @@ class ExpressionDartPlaceholderType extends DartPlaceholderType { } class InsertableDartPlaceholderType extends DartPlaceholderType { - final MoorTable? table; + final DriftTable? table; InsertableDartPlaceholderType(this.table); @@ -838,7 +838,7 @@ class FoundDartPlaceholder extends FoundElement { /// Whether we should write this parameter as a function having available /// result sets as parameters. - bool writeAsScopedFunction(MoorOptions options) { + bool writeAsScopedFunction(DriftOptions options) { return options.scopedDartComponents && availableResultSets.isNotEmpty && // Don't generate scoped functions for insertables, where the Dart type @@ -856,7 +856,7 @@ class AvailableMoorResultSet { final String name; /// The table or view that is available. - final MoorEntityWithResultSet entity; + final DriftEntityWithResultSet entity; final ResultSetAvailableInStatement? source; diff --git a/drift_dev/lib/src/model/table.dart b/drift_dev/lib/src/model/table.dart index 82939f80..8aaa8956 100644 --- a/drift_dev/lib/src/model/table.dart +++ b/drift_dev/lib/src/model/table.dart @@ -12,7 +12,7 @@ import 'declarations/declaration.dart'; /// A parsed table, declared in code by extending `Table` and referencing that /// table in `@UseMoor` or `@UseDao`. -class MoorTable extends MoorEntityWithResultSet { +class DriftTable extends DriftEntityWithResultSet { /// The [ClassElement] for the class that declares this table or null if /// the table was inferred from a `CREATE TABLE` statement. final ClassElement? fromClass; @@ -45,7 +45,7 @@ class MoorTable extends MoorEntityWithResultSet { /// The columns declared in this table. @override - final List columns; + final List columns; /// The (unescaped) name of this table when stored in the database final String sqlName; @@ -79,7 +79,7 @@ class MoorTable extends MoorEntityWithResultSet { return existingRowClass?.dartType(options) ?? dartTypeName; } - String getNameForCompanionClass(MoorOptions options) { + String getNameForCompanionClass(DriftOptions options) { final baseName = options.useDataClassNameForCompanions ? dartTypeName : _baseName; return '${baseName}Companion'; @@ -90,17 +90,17 @@ class MoorTable extends MoorEntityWithResultSet { /// not been defined that way. /// /// For the full primary key, see [fullPrimaryKey]. - final Set? primaryKey; + final Set? primaryKey; /// The set of unique keys if they have been explicitly defined by /// overriding `uniqueKeys` in the table class. - final List>? uniqueKeys; + final List>? uniqueKeys; /// The primary key for this table. /// /// Unlikely [primaryKey], this method is not limited to the `primaryKey` /// override in Dart table declarations. - Set get fullPrimaryKey { + Set get fullPrimaryKey { if (primaryKey != null) return primaryKey!; return columns.where((c) => c.features.any((f) => f is PrimaryKey)).toSet(); @@ -123,7 +123,7 @@ class MoorTable extends MoorEntityWithResultSet { final List? overrideTableConstraints; @override - final Set references = {}; + final Set references = {}; /// Returns whether this table was created from a `CREATE VIRTUAL TABLE` /// statement in a moor file @@ -144,7 +144,7 @@ class MoorTable extends MoorEntityWithResultSet { return (declaration as TableDeclarationWithSql).createSql; } - MoorTable({ + DriftTable({ this.fromClass, this.columns = const [], required this.sqlName, @@ -178,7 +178,7 @@ class MoorTable extends MoorEntityWithResultSet { /// Determines whether [column] would be required for inserts performed via /// companions. - bool isColumnRequiredForInsert(MoorColumn column) { + bool isColumnRequiredForInsert(DriftColumn column) { assert(columns.contains(column)); if (column.defaultArgument != null || @@ -217,7 +217,7 @@ class MoorTable extends MoorEntityWithResultSet { } class WrittenMoorTable { - final MoorTable table; + final DriftTable table; final UpdateKind kind; WrittenMoorTable(this.table, this.kind); diff --git a/drift_dev/lib/src/model/trigger.dart b/drift_dev/lib/src/model/trigger.dart index 42dbc4fc..480af6fe 100644 --- a/drift_dev/lib/src/model/trigger.dart +++ b/drift_dev/lib/src/model/trigger.dart @@ -4,7 +4,7 @@ import 'package:sqlparser/sqlparser.dart'; import 'model.dart'; -class MoorTrigger implements MoorSchemaEntity { +class MoorTrigger implements DriftSchemaEntity { @override final String displayName; @@ -14,16 +14,16 @@ class MoorTrigger implements MoorSchemaEntity { /// The table on which this trigger operates. /// /// This field can be null in case the table wasn't resolved. - MoorTable? on; + DriftTable? on; List bodyUpdates = []; - List bodyReferences = []; + List bodyReferences = []; MoorTrigger(this.displayName, this.declaration, this.on); factory MoorTrigger.fromMoor(CreateTriggerStatement stmt, FoundFile file) { return MoorTrigger( stmt.triggerName, - MoorTriggerDeclaration.fromNodeAndFile(stmt, file), + DriftTriggerDeclaration.fromNodeAndFile(stmt, file), null, // must be resolved later ); } @@ -35,11 +35,11 @@ class MoorTrigger implements MoorSchemaEntity { } @override - Iterable get references => + Iterable get references => {if (on != null) on!, ...bodyReferences}; /// The `CREATE TRIGGER` statement that can be used to create this trigger. - String createSql(MoorOptions options) { + String createSql(DriftOptions options) { return declaration.formatSqlIfAvailable(options) ?? declaration.createSql; } diff --git a/drift_dev/lib/src/model/used_type_converter.dart b/drift_dev/lib/src/model/used_type_converter.dart index 57cc833c..97a58005 100644 --- a/drift_dev/lib/src/model/used_type_converter.dart +++ b/drift_dev/lib/src/model/used_type_converter.dart @@ -13,7 +13,7 @@ class UsedTypeConverter { int? index; /// The table using this type converter. - MoorTable? table; + DriftTable? table; /// The expression that will construct the type converter at runtime. The /// type converter constructed will map a [dartType] to the [sqlType] and diff --git a/drift_dev/lib/src/model/view.dart b/drift_dev/lib/src/model/view.dart index 06086d3d..4beacc6f 100644 --- a/drift_dev/lib/src/model/view.dart +++ b/drift_dev/lib/src/model/view.dart @@ -9,7 +9,7 @@ import '../../writer.dart'; import 'model.dart'; /// A parsed view -class MoorView extends MoorEntityWithResultSet { +class MoorView extends DriftEntityWithResultSet { @override final ViewDeclaration? declaration; @@ -17,15 +17,15 @@ class MoorView extends MoorEntityWithResultSet { /// sql queries. Note that this field is set lazily. View? parserView; - ParsedMoorFile? file; + ParsedDriftFile? file; final String name; @override - List references = []; + List references = []; @override - late List columns; + late List columns; @override String dartTypeName; @@ -61,10 +61,10 @@ class MoorView extends MoorEntityWithResultSet { /// /// This includes all tables in [references]. If this view references other /// views, their [transitiveTableReferences] will be included as well. - Set get transitiveTableReferences { + Set get transitiveTableReferences { return { for (final reference in references) - if (reference is MoorTable) + if (reference is DriftTable) reference else if (reference is MoorView) ...reference.transitiveTableReferences, @@ -76,7 +76,7 @@ class MoorView extends MoorEntityWithResultSet { final dataClassName = dataClassNameForClassName(entityInfoName); return MoorView( - declaration: MoorViewDeclaration(stmt, file), + declaration: DriftViewDeclaration(stmt, file), name: stmt.viewName, dartTypeName: dataClassName, entityInfoName: entityInfoName, @@ -84,8 +84,8 @@ class MoorView extends MoorEntityWithResultSet { } /// The `CREATE VIEW` statement that can be used to create this view. - String createSql(MoorOptions options) { - final decl = declaration as MoorViewDeclaration?; + String createSql(DriftOptions options) { + final decl = declaration as DriftViewDeclaration?; if (decl == null) { throw StateError('Cannot show SQL for views without a declaration'); } @@ -103,7 +103,7 @@ class MoorView extends MoorEntityWithResultSet { class ViewQueryInformation { /// All columns from this Dart-defined view, in the order in which they were /// added to the `query` getter. - final List> columns; + final List> columns; final String from; final String query; diff --git a/drift_dev/lib/src/services/find_stream_update_rules.dart b/drift_dev/lib/src/services/find_stream_update_rules.dart index df83aa46..d16c1ad2 100644 --- a/drift_dev/lib/src/services/find_stream_update_rules.dart +++ b/drift_dev/lib/src/services/find_stream_update_rules.dart @@ -14,7 +14,7 @@ class FindStreamUpdateRules { for (final entity in db.entities) { if (entity is MoorTrigger) { _writeRulesForTrigger(entity, rules); - } else if (entity is MoorTable) { + } else if (entity is DriftTable) { _writeRulesForTable(entity, rules); } } @@ -22,11 +22,11 @@ class FindStreamUpdateRules { return StreamQueryUpdateRules(rules); } - void _writeRulesForTable(MoorTable table, List rules) { + void _writeRulesForTable(DriftTable table, List rules) { final declaration = table.declaration; // We only know about foreign key clauses from tables in moor files - if (declaration is! MoorTableDeclaration) return; + if (declaration is! DriftTableDeclaration) return; if (declaration.node is! CreateTableStatement) return; @@ -74,7 +74,7 @@ class FindStreamUpdateRules { void _writeRulesForTrigger(MoorTrigger trigger, List rules) { final declaration = trigger.declaration; - if (declaration is! MoorTriggerDeclaration) return; + if (declaration is! DriftTriggerDeclaration) return; final target = declaration.node.target; UpdateKind targetKind; diff --git a/drift_dev/lib/src/services/ide/utils.dart b/drift_dev/lib/src/services/ide/utils.dart index debd52c5..88406120 100644 --- a/drift_dev/lib/src/services/ide/utils.dart +++ b/drift_dev/lib/src/services/ide/utils.dart @@ -2,9 +2,9 @@ import 'package:drift_dev/src/analyzer/runner/file_graph.dart'; import 'package:drift_dev/src/analyzer/runner/results.dart'; extension CurrentResults on FoundFile { - ParsedMoorFile? get parsedMoorOrNull { + ParsedDriftFile? get parsedMoorOrNull { final result = currentResult; - if (result is ParsedMoorFile && isParsed) { + if (result is ParsedDriftFile && isParsed) { return result; } return null; diff --git a/drift_dev/lib/src/services/schema/find_differences.dart b/drift_dev/lib/src/services/schema/find_differences.dart index 59afa2da..92cd3c8e 100644 --- a/drift_dev/lib/src/services/schema/find_differences.dart +++ b/drift_dev/lib/src/services/schema/find_differences.dart @@ -1,4 +1,4 @@ -import 'package:drift_dev/src/analyzer/moor/moor_ffi_extension.dart'; +import 'package:drift_dev/src/analyzer/drift/moor_ffi_extension.dart'; import 'package:sqlparser/sqlparser.dart'; // ignore: implementation_imports import 'package:sqlparser/src/utils/ast_equality.dart'; diff --git a/drift_dev/lib/src/services/schema/schema_files.dart b/drift_dev/lib/src/services/schema/schema_files.dart index 92c1f196..547a8e30 100644 --- a/drift_dev/lib/src/services/schema/schema_files.dart +++ b/drift_dev/lib/src/services/schema/schema_files.dart @@ -9,17 +9,17 @@ const _infoVersion = '0.1.0-dev-preview'; /// Utilities to transform moor schema entities to json. class SchemaWriter { - static const _exportOptions = MoorOptions.defaults(); + static const _exportOptions = DriftOptions.defaults(); /// The parsed and resolved database for which the schema should be written. final Database db; - final Map _entityIds = {}; + final Map _entityIds = {}; int _maxId = 0; SchemaWriter(this.db); - int _idOf(MoorSchemaEntity entity) { + int _idOf(DriftSchemaEntity entity) { return _entityIds.putIfAbsent(entity, () => _maxId++); } @@ -36,11 +36,11 @@ class SchemaWriter { }; } - Map _entityToJson(MoorSchemaEntity entity) { + Map _entityToJson(DriftSchemaEntity entity) { String type; Map data; - if (entity is MoorTable) { + if (entity is DriftTable) { type = 'table'; data = _tableData(entity); } else if (entity is MoorTrigger) { @@ -61,7 +61,7 @@ class SchemaWriter { 'sql': entity.createStmt, }; } else if (entity is MoorView) { - if (entity.declaration is! MoorViewDeclaration) { + if (entity.declaration is! DriftViewDeclaration) { throw UnsupportedError( 'Exporting Dart-defined views into a schema is not ' 'currently supported'); @@ -70,7 +70,7 @@ class SchemaWriter { type = 'view'; data = { 'name': entity.name, - 'sql': entity.createSql(const MoorOptions.defaults()), + 'sql': entity.createSql(const DriftOptions.defaults()), 'dart_data_name': entity.dartTypeName, 'dart_info_name': entity.entityInfoName, 'columns': [for (final column in entity.columns) _columnData(column)], @@ -96,7 +96,7 @@ class SchemaWriter { }; } - Map _tableData(MoorTable table) { + Map _tableData(DriftTable table) { return { 'name': table.sqlName, 'was_declared_in_moor': table.isFromSql, @@ -112,7 +112,7 @@ class SchemaWriter { }; } - Map _columnData(MoorColumn column) { + Map _columnData(DriftColumn column) { final constraints = defaultConstraints(column); return { @@ -154,7 +154,7 @@ class SchemaWriter { /// Reads files generated by [SchemaWriter]. class SchemaReader { - final Map _entitiesById = {}; + final Map _entitiesById = {}; final Map> _rawById = {}; final Set _currentlyProcessing = {}; @@ -167,7 +167,7 @@ class SchemaReader { return SchemaReader._().._read(json); } - Iterable get entities => _entitiesById.values; + Iterable get entities => _entitiesById.values; void _read(Map json) { final entities = json['entities'] as List; @@ -182,7 +182,7 @@ class SchemaReader { _rawById.keys.forEach(_processById); } - T _existingEntity(dynamic id) { + T _existingEntity(dynamic id) { return _entitiesById[id as int] as T; } @@ -204,7 +204,7 @@ class SchemaReader { final content = rawData?['data'] as Map; final type = rawData?['type'] as String; - MoorSchemaEntity entity; + DriftSchemaEntity entity; switch (type) { case 'index': entity = _readIndex(content); @@ -230,7 +230,7 @@ class SchemaReader { } MoorIndex _readIndex(Map content) { - final on = _existingEntity(content['on']); + final on = _existingEntity(content['on']); final name = content['name'] as String; final sql = content['sql'] as String; @@ -238,7 +238,7 @@ class SchemaReader { } MoorTrigger _readTrigger(Map content) { - final on = _existingEntity(content['on']); + final on = _existingEntity(content['on']); final name = content['name'] as String; final sql = content['sql'] as String; @@ -249,7 +249,7 @@ class SchemaReader { return trigger; } - MoorTable _readTable(Map content) { + DriftTable _readTable(Map content) { final sqlName = content['name'] as String; final isVirtual = content['is_virtual'] as bool; final withoutRowId = content['without_rowid'] as bool?; @@ -259,7 +259,7 @@ class SchemaReader { final parsed = _engine.parse(create).rootNode as CreateVirtualTableStatement; - return MoorTable( + return DriftTable( sqlName: sqlName, dartTypeName: sqlName, overriddenName: sqlName, @@ -279,7 +279,7 @@ class SchemaReader { tableConstraints = (content['constraints'] as List).cast(); } - Set? explicitPk; + Set? explicitPk; if (content.containsKey('explicit_pk')) { explicitPk = { for (final columnName in content['explicit_pk'] as List) @@ -289,7 +289,7 @@ class SchemaReader { final pascalCase = ReCase(sqlName).pascalCase; - return MoorTable( + return DriftTable( sqlName: sqlName, overriddenName: pascalCase, columns: columns, @@ -314,7 +314,7 @@ class SchemaReader { ]; } - MoorColumn _readColumn(Map data) { + DriftColumn _readColumn(Map data) { final name = data['name'] as String; final moorType = ColumnType.values .firstWhere((type) => type.toString() == data['moor_type']); @@ -331,7 +331,7 @@ class SchemaReader { // Note: Not including client default code because that usually depends on // imports from the database. - return MoorColumn( + return DriftColumn( name: ColumnName.explicitly(name), dartGetterName: getterName ?? ReCase(name).camelCase, type: moorType, diff --git a/drift_dev/lib/src/utils/entity_reference_sorter.dart b/drift_dev/lib/src/utils/entity_reference_sorter.dart index 14d1211f..f6c5f2dd 100644 --- a/drift_dev/lib/src/utils/entity_reference_sorter.dart +++ b/drift_dev/lib/src/utils/entity_reference_sorter.dart @@ -1,15 +1,15 @@ import 'package:drift_dev/moor_generator.dart'; -/// Topologically sorts a list of [MoorSchemaEntity]s by their -/// [MoorSchemaEntity.references] relationship: Tables appearing first in the +/// Topologically sorts a list of [DriftSchemaEntity]s by their +/// [DriftSchemaEntity.references] relationship: Tables appearing first in the /// output have to be created first so the table creation script doesn't crash /// because of tables not existing. /// -/// If there is a circular reference between [MoorTable]s, an error will +/// If there is a circular reference between [DriftTable]s, an error will /// be added that contains the name of the tables in question. Self-references /// in tables are allowed. -List sortEntitiesTopologically( - Iterable tables) { +List sortEntitiesTopologically( + Iterable tables) { final run = _SortRun(); for (final entity in tables) { @@ -22,7 +22,7 @@ List sortEntitiesTopologically( return run.result; } -void _visit(MoorSchemaEntity entity, _SortRun run) { +void _visit(DriftSchemaEntity entity, _SortRun run) { for (final reference in entity.references) { if (run.result.contains(reference) || reference == entity) { // When the target entity has already been added there's nothing to do. @@ -48,19 +48,19 @@ class _SortRun { /// /// This means that, when an entity references another entity that is present /// in `previous.keys`, that's a circular reference. - final Map previous = {}; + final Map previous = {}; /// Entities that have already been fully handled, in topological order. /// /// If an entity is in [result], all of it's references are in [result] as /// well and it's safe to reference it. - final List result = []; + final List result = []; /// Throws a [CircularReferenceException] because the [last] table depends on /// [first], which (transitively) depends on [last] as well. The path in the /// thrown exception will go from [first] to [last]. - void throwCircularException(MoorSchemaEntity last, MoorSchemaEntity first) { - final constructedPath = []; + void throwCircularException(DriftSchemaEntity last, DriftSchemaEntity first) { + final constructedPath = []; for (var current = last; current != first; current = previous[current]!) { constructedPath.insert(0, current); } @@ -69,18 +69,18 @@ class _SortRun { throw CircularReferenceException._(constructedPath); } - bool didVisitAlready(MoorSchemaEntity table) { + bool didVisitAlready(DriftSchemaEntity table) { return previous[table] != null || result.contains(table); } } /// Thrown by [sortEntitiesTopologically] when the graph formed by -/// [MoorSchemaEntity.references] is not acyclic except for self-references. +/// [DriftSchemaEntity.references] is not acyclic except for self-references. class CircularReferenceException implements Exception { /// The list of entities forming a circular reference, so that the first /// entity in this list references the second one and so on. The last entity /// in this list references the first one, thus forming a cycle. - final List affected; + final List affected; CircularReferenceException._(this.affected); } diff --git a/drift_dev/lib/src/utils/options_reader.dart b/drift_dev/lib/src/utils/options_reader.dart index 6db5a7c2..db4b2782 100644 --- a/drift_dev/lib/src/utils/options_reader.dart +++ b/drift_dev/lib/src/utils/options_reader.dart @@ -1,20 +1,20 @@ import 'package:build_config/build_config.dart'; import 'package:drift_dev/src/analyzer/options.dart'; -Future fromRootDir(String path) async { +Future fromRootDir(String path) async { final options = await BuildConfig.fromPackageDir(path); return readOptionsFromConfig(options); } -MoorOptions readOptionsFromConfig(BuildConfig config) { +DriftOptions readOptionsFromConfig(BuildConfig config) { final options = config.buildTargets.values .map((t) { return t.builders['moor_generator:moor_generator']?.options ?? t.builders['drift_dev:drift_dev']?.options; }) .whereType() - .map((json) => MoorOptions.fromJson(json)); + .map((json) => DriftOptions.fromJson(json)); final iterator = options.iterator; - return iterator.moveNext() ? iterator.current : const MoorOptions.defaults(); + return iterator.moveNext() ? iterator.current : const DriftOptions.defaults(); } diff --git a/drift_dev/lib/src/writer/database_writer.dart b/drift_dev/lib/src/writer/database_writer.dart index 0dac62b3..5499bfbd 100644 --- a/drift_dev/lib/src/writer/database_writer.dart +++ b/drift_dev/lib/src/writer/database_writer.dart @@ -54,7 +54,7 @@ class DatabaseWriter { '$className.connect(DatabaseConnection c): super.connect(c); \n'); } - final entityGetters = {}; + final entityGetters = {}; for (final entity in db.entities) { final getterName = entity.dbGetterName; @@ -62,7 +62,7 @@ class DatabaseWriter { entityGetters[entity] = getterName; } - if (entity is MoorTable) { + if (entity is DriftTable) { final tableClassName = entity.entityInfoName; writeMemoizedGetter( diff --git a/drift_dev/lib/src/writer/queries/query_writer.dart b/drift_dev/lib/src/writer/queries/query_writer.dart index dc97e0dd..75670c17 100644 --- a/drift_dev/lib/src/writer/queries/query_writer.dart +++ b/drift_dev/lib/src/writer/queries/query_writer.dart @@ -19,7 +19,7 @@ class QueryWriter { late final ExplicitAliasTransformer _transformer; final StringBuffer _buffer; - MoorOptions get options => scope.writer.options; + DriftOptions get options => scope.writer.options; QueryWriter(this.scope) : _buffer = scope.leaf(); @@ -159,7 +159,7 @@ class QueryWriter { /// in the same scope, reads the [column] from that row and brings it into a /// suitable type. String readingCode(ResultColumn column, GenerationOptions generationOptions, - MoorOptions moorOptions) { + DriftOptions moorOptions) { var rawDartType = dartTypeNames[column.type]; if (column.nullable) { rawDartType = '$rawDartType?'; @@ -489,7 +489,7 @@ String _converter(UsedTypeConverter converter) { class _ExpandedDeclarationWriter { final SqlQuery query; - final MoorOptions options; + final DriftOptions options; final StringBuffer _buffer; bool indexCounterWasDeclared = false; diff --git a/drift_dev/lib/src/writer/queries/sql_writer.dart b/drift_dev/lib/src/writer/queries/sql_writer.dart index 880f9cfe..c4028a94 100644 --- a/drift_dev/lib/src/writer/queries/sql_writer.dart +++ b/drift_dev/lib/src/writer/queries/sql_writer.dart @@ -27,7 +27,7 @@ String placeholderContextName(FoundDartPlaceholder placeholder) { class SqlWriter extends NodeSqlBuilder { final StringBuffer _out; final SqlQuery? query; - final MoorOptions options; + final DriftOptions options; final Map _starColumnToResolved; bool get _isPostgres => options.effectiveDialect == SqlDialect.postgres; @@ -37,7 +37,7 @@ class SqlWriter extends NodeSqlBuilder { : _out = out, super(escapeForDart ? _DartEscapingSink(out) : out); - factory SqlWriter(MoorOptions options, + factory SqlWriter(DriftOptions options, {SqlQuery? query, bool escapeForDart = true}) { // Index nested results by their syntactic origin for faster lookups later var doubleStarColumnToResolvedTable = diff --git a/drift_dev/lib/src/writer/tables/data_class_writer.dart b/drift_dev/lib/src/writer/tables/data_class_writer.dart index e0e3b3e6..65571e78 100644 --- a/drift_dev/lib/src/writer/tables/data_class_writer.dart +++ b/drift_dev/lib/src/writer/tables/data_class_writer.dart @@ -5,11 +5,11 @@ import 'package:drift_dev/src/writer/utils/override_toString.dart'; import 'package:drift_dev/writer.dart'; class DataClassWriter { - final MoorEntityWithResultSet table; + final DriftEntityWithResultSet table; final Scope scope; - final columns = []; + final columns = []; - bool get isInsertable => table is MoorTable; + bool get isInsertable => table is DriftTable; late StringBuffer _buffer; @@ -102,7 +102,7 @@ class DataClassWriter { // The GeneratedDatabase db parameter is not actually used, but we need to // keep it on tables for backwards compatibility. final includeUnusedDbColumn = - scope.generationOptions.writeForMoorPackage && table is MoorTable; + scope.generationOptions.writeForMoorPackage && table is DriftTable; _buffer ..write('factory $dataClassName.fromData') @@ -296,7 +296,7 @@ class DataClassWriter { } void _writeToCompanion() { - final asTable = table as MoorTable; + final asTable = table as DriftTable; _buffer ..write(asTable.getNameForCompanionClass(scope.options)) @@ -353,17 +353,17 @@ class DataClassWriter { /// Generates code mapping a row (represented as a `Map`) to positional and /// named Dart arguments. class RowMappingWriter { - final List positional; - final Map named; - final MoorEntityWithResultSet table; + final List positional; + final Map named; + final DriftEntityWithResultSet table; final GenerationOptions options; - final MoorOptions moorOptions; + final DriftOptions moorOptions; RowMappingWriter( this.positional, this.named, this.table, this.options, this.moorOptions); void writeArguments(StringBuffer buffer) { - String readAndMap(MoorColumn column) { + String readAndMap(DriftColumn column) { final columnName = column.name.name; final rawData = "data['\${effectivePrefix}$columnName']"; final sqlType = 'const ${sqlTypes[column.type]}()'; diff --git a/drift_dev/lib/src/writer/tables/table_writer.dart b/drift_dev/lib/src/writer/tables/table_writer.dart index c66aeaa5..f00cc64b 100644 --- a/drift_dev/lib/src/writer/tables/table_writer.dart +++ b/drift_dev/lib/src/writer/tables/table_writer.dart @@ -9,11 +9,11 @@ import '../utils/column_constraints.dart'; /// /// Both classes need to generate column getters and a mapping function. abstract class TableOrViewWriter { - MoorEntityWithResultSet get tableOrView; + DriftEntityWithResultSet get tableOrView; StringBuffer get buffer; void writeColumnGetter( - MoorColumn column, GenerationOptions options, bool isOverride) { + DriftColumn column, GenerationOptions options, bool isOverride) { final isNullable = column.nullable; final additionalParams = {}; final expressionBuffer = StringBuffer(); @@ -41,8 +41,8 @@ abstract class TableOrViewWriter { additionalParams['type'] = 'const ${column.sqlType().runtimeType}()'; - if (tableOrView is MoorTable) { - additionalParams['requiredDuringInsert'] = (tableOrView as MoorTable) + if (tableOrView is DriftTable) { + additionalParams['requiredDuringInsert'] = (tableOrView as DriftTable) .isColumnRequiredForInsert(column) .toString(); } @@ -144,8 +144,8 @@ abstract class TableOrViewWriter { "tablePrefix != null ? '\$tablePrefix.' : '';"); final info = tableOrView.existingRowClass!; - final positionalToIndex = {}; - final named = {}; + final positionalToIndex = {}; + final named = {}; final parameters = info.constructor.parameters; info.mapping.forEach((column, parameter) { @@ -186,7 +186,7 @@ abstract class TableOrViewWriter { } else { // Use default .fromData constructor in the moor-generated data class final hasDbParameter = scope.generationOptions.writeForMoorPackage && - tableOrView is MoorTable; + tableOrView is DriftTable; if (hasDbParameter) { buffer.write('return $dataClassName.fromData(data, attachedDatabase, ' "prefix: tablePrefix != null ? '\$tablePrefix.' : null);\n"); @@ -213,14 +213,14 @@ abstract class TableOrViewWriter { } class TableWriter extends TableOrViewWriter { - final MoorTable table; + final DriftTable table; final Scope scope; @override late StringBuffer buffer; @override - MoorTable get tableOrView => table; + DriftTable get tableOrView => table; TableWriter(this.table, this.scope); @@ -340,7 +340,7 @@ class TableWriter extends TableOrViewWriter { } } - void _writeColumnVerificationMeta(MoorColumn column) { + void _writeColumnVerificationMeta(DriftColumn column) { if (!_skipVerification) { buffer ..write('final VerificationMeta ${_fieldNameForColumnMeta(column)} = ') @@ -392,7 +392,7 @@ class TableWriter extends TableOrViewWriter { buffer.write('return context;\n}\n'); } - String _fieldNameForColumnMeta(MoorColumn column) { + String _fieldNameForColumnMeta(DriftColumn column) { return '_${column.dartGetterName}Meta'; } diff --git a/drift_dev/lib/src/writer/tables/update_companion_writer.dart b/drift_dev/lib/src/writer/tables/update_companion_writer.dart index 211c0149..4d41870f 100644 --- a/drift_dev/lib/src/writer/tables/update_companion_writer.dart +++ b/drift_dev/lib/src/writer/tables/update_companion_writer.dart @@ -5,12 +5,12 @@ import 'package:drift_dev/src/writer/utils/override_toString.dart'; import 'package:drift_dev/writer.dart'; class UpdateCompanionWriter { - final MoorTable table; + final DriftTable table; final Scope scope; late StringBuffer _buffer; - late final List columns = [ + late final List columns = [ for (final column in table.columns) if (!column.isGenerated) column, ]; @@ -65,7 +65,7 @@ class UpdateCompanionWriter { /// absent during insert are marked `@required` here. Also, we don't need to /// use value wrappers here - `Value.absent` simply isn't an option. void _writeInsertConstructor() { - final requiredColumns = {}; + final requiredColumns = {}; // can't be constant because we use initializers (this.a = Value(a)). // for a parameter a which is only potentially constant. diff --git a/drift_dev/lib/src/writer/tables/view_writer.dart b/drift_dev/lib/src/writer/tables/view_writer.dart index 086d2fbf..3e8d13f5 100644 --- a/drift_dev/lib/src/writer/tables/view_writer.dart +++ b/drift_dev/lib/src/writer/tables/view_writer.dart @@ -77,7 +77,7 @@ class ViewWriter extends TableOrViewWriter { ..write('@override\n String get entityName=>' ' ${asDartLiteral(view.name)};\n'); - if (view.declaration is MoorViewDeclaration) { + if (view.declaration is DriftViewDeclaration) { buffer.write('@override\n String get createViewStmt =>' ' ${asDartLiteral(view.createSql(scope.options))};\n'); } else { @@ -96,7 +96,7 @@ class ViewWriter extends TableOrViewWriter { // Dart, but it wasn't defined by the user. Instead, the column is // implicitly generated from a entry in the `select()` query clause. // We can drop all information from it since only the name is relevant. - final shortColumn = MoorColumn( + final shortColumn = DriftColumn( type: column.type, dartGetterName: column.dartGetterName, name: column.name); diff --git a/drift_dev/lib/src/writer/utils/column_constraints.dart b/drift_dev/lib/src/writer/utils/column_constraints.dart index 5168a3ca..d922adda 100644 --- a/drift_dev/lib/src/writer/utils/column_constraints.dart +++ b/drift_dev/lib/src/writer/utils/column_constraints.dart @@ -3,7 +3,7 @@ import 'package:sqlparser/sqlparser.dart'; import '../../model/column.dart'; -String defaultConstraints(MoorColumn column) { +String defaultConstraints(DriftColumn column) { final defaultConstraints = []; var wrotePkConstraint = false; diff --git a/drift_dev/lib/src/writer/writer.dart b/drift_dev/lib/src/writer/writer.dart index b111e4ec..6d2321dd 100644 --- a/drift_dev/lib/src/writer/writer.dart +++ b/drift_dev/lib/src/writer/writer.dart @@ -11,7 +11,7 @@ import 'package:drift_dev/src/analyzer/options.dart'; /// passing a [Scope] we will always be able to write code in a parent scope. class Writer { late final Scope _root; - final MoorOptions options; + final DriftOptions options; final GenerationOptions generationOptions; Writer(this.options, {this.generationOptions = const GenerationOptions()}) { @@ -62,7 +62,7 @@ class Scope extends _Node { writer = writer ?? parent!.writer, super(parent); - MoorOptions get options => writer.options; + DriftOptions get options => writer.options; GenerationOptions get generationOptions => writer.generationOptions; @@ -160,11 +160,11 @@ class DartScope { } } -extension WriterUtilsForOptions on MoorOptions { +extension WriterUtilsForOptions on DriftOptions { String get fieldModifier => generateMutableClasses ? '' : 'final'; } -extension WriterUtilsForColumns on MoorColumn { +extension WriterUtilsForColumns on DriftColumn { /// Adds an `this.` prefix is the [dartGetterName] is in [locals]. String thisIfNeeded(Set locals) { if (locals.contains(dartGetterName)) { diff --git a/drift_dev/test/analyzer/dart/column_references_test.dart b/drift_dev/test/analyzer/dart/column_references_test.dart index d4c1c36d..6f4da611 100644 --- a/drift_dev/test/analyzer/dart/column_references_test.dart +++ b/drift_dev/test/analyzer/dart/column_references_test.dart @@ -130,7 +130,7 @@ class Database {} expect( foo.references, - contains(isA() + contains(isA() .having((tbl) => tbl.sqlName, 'sqlName', 'other_table'))); final column = foo.columns.single; diff --git a/drift_dev/test/analyzer/dart/dart_test.dart b/drift_dev/test/analyzer/dart/dart_test.dart index 4c4b8177..baf5faf7 100644 --- a/drift_dev/test/analyzer/dart/dart_test.dart +++ b/drift_dev/test/analyzer/dart/dart_test.dart @@ -30,7 +30,7 @@ void main() { final task = session.startTask(backendTask); final library = await backendTask.resolveDart(input); - final parser = MoorDartParser(ParseDartStep( + final parser = DriftDartParser(ParseDartStep( task, session.registerFile(input), library, await task.helper)); Future _loadDeclaration(Element element) async { diff --git a/drift_dev/test/analyzer/dart/enum_columns_test.dart b/drift_dev/test/analyzer/dart/enum_columns_test.dart index a144b465..84256f24 100644 --- a/drift_dev/test/analyzer/dart/enum_columns_test.dart +++ b/drift_dev/test/analyzer/dart/enum_columns_test.dart @@ -55,7 +55,7 @@ void main() { expect( errors, - contains(isA().having((e) => e.message, 'message', + contains(isA().having((e) => e.message, 'message', allOf(contains('Not an enum'), contains('NotAnEnum')))), ); }); diff --git a/drift_dev/test/analyzer/dart/table_parser_test.dart b/drift_dev/test/analyzer/dart/table_parser_test.dart index 00404ae1..af912166 100644 --- a/drift_dev/test/analyzer/dart/table_parser_test.dart +++ b/drift_dev/test/analyzer/dart/table_parser_test.dart @@ -15,7 +15,7 @@ import '../utils.dart'; void main() { late TestBackend backend; late ParseDartStep dartStep; - late MoorDartParser parser; + late DriftDartParser parser; setUpAll(() { backend = TestBackend({ @@ -142,10 +142,10 @@ void main() { dartStep = ParseDartStep( moorTask, file, await task.resolveDart(uri), await moorTask.helper); - parser = MoorDartParser(dartStep); + parser = DriftDartParser(dartStep); }); - Future parse(String name) async { + Future parse(String name) async { return parser.parseTable(dartStep.library.getType(name)!); } @@ -281,7 +281,7 @@ void main() { final c = table.columns.singleWhere((c) => c.name.name == 'c'); void expectType( - MoorColumn column, bool hasOverriddenSource, String toString) { + DriftColumn column, bool hasOverriddenSource, String toString) { expect( column.typeConverter, isA() diff --git a/drift_dev/test/analyzer/dart/type_converter_test.dart b/drift_dev/test/analyzer/dart/type_converter_test.dart index 2de79dbb..297568c5 100644 --- a/drift_dev/test/analyzer/dart/type_converter_test.dart +++ b/drift_dev/test/analyzer/dart/type_converter_test.dart @@ -47,7 +47,7 @@ CREATE TABLE users ( Future testWith(String fileName) async { final result = await state.analyze(fileName); - final table = result.currentResult!.declaredEntities.single as MoorTable; + final table = result.currentResult!.declaredEntities.single as DriftTable; final foo = table.columns[0]; final bar = table.columns[1]; diff --git a/drift_dev/test/analyzer/moor/cfe_test.dart b/drift_dev/test/analyzer/drift/cfe_test.dart similarity index 95% rename from drift_dev/test/analyzer/moor/cfe_test.dart rename to drift_dev/test/analyzer/drift/cfe_test.dart index c438ecba..6ab2cb9d 100644 --- a/drift_dev/test/analyzer/moor/cfe_test.dart +++ b/drift_dev/test/analyzer/drift/cfe_test.dart @@ -56,7 +56,7 @@ WITH alias("first", second) AS (SELECT * FROM foo) SELECT * FROM alias; expect(file.state, FileState.analyzed); expect(file.errors.errors, isEmpty); - final result = file.currentResult as ParsedMoorFile; + final result = file.currentResult as ParsedDriftFile; final query = result.resolvedQueries!.firstWhere((q) => q.name == 'test') as SqlSelectQuery; @@ -73,7 +73,7 @@ WITH alias("first", second) AS (SELECT * FROM foo) SELECT * FROM alias; test('finds the underlying table when aliased through CFE', () { final file = session.registerFile(Uri.parse('package:foo/test.moor')); - final result = file.currentResult as ParsedMoorFile; + final result = file.currentResult as ParsedDriftFile; final query = result.resolvedQueries!.firstWhere((q) => q.name == 'test2') as SqlSelectQuery; diff --git a/drift_dev/test/analyzer/moor/create_table_reader_test.dart b/drift_dev/test/analyzer/drift/create_table_reader_test.dart similarity index 96% rename from drift_dev/test/analyzer/moor/create_table_reader_test.dart rename to drift_dev/test/analyzer/drift/create_table_reader_test.dart index bcc73a56..9e60e895 100644 --- a/drift_dev/test/analyzer/moor/create_table_reader_test.dart +++ b/drift_dev/test/analyzer/drift/create_table_reader_test.dart @@ -48,7 +48,7 @@ void main() { expect( file.errors.errors, contains( - isA().having( + isA().having( (e) => e.message, 'message', contains('Type DoesNotExist could not be found'), @@ -83,7 +83,7 @@ void main() { expect( file.errors.errors, contains( - isA().having( + isA().having( (e) => e.message, 'message', contains("can't apply another converter"), @@ -112,7 +112,7 @@ void main() { expect( file.errors.errors, contains( - isA() + isA() .having( (e) => e.message, 'message', diff --git a/drift_dev/test/analyzer/moor/create_view_test.dart b/drift_dev/test/analyzer/drift/create_view_test.dart similarity index 95% rename from drift_dev/test/analyzer/moor/create_view_test.dart rename to drift_dev/test/analyzer/drift/create_view_test.dart index 3417790e..7fd9b51c 100644 --- a/drift_dev/test/analyzer/moor/create_view_test.dart +++ b/drift_dev/test/analyzer/drift/create_view_test.dart @@ -28,7 +28,7 @@ void main() { expect(column.type!.type, BasicType.text); expect(view.references, - contains(isA().having((t) => t.sqlName, 'sqlName', 't'))); + contains(isA().having((t) => t.sqlName, 'sqlName', 't'))); expect(file.errors.errors, isEmpty); }); @@ -82,7 +82,7 @@ void main() { expect( file.errors.errors, - contains(isA().having( + contains(isA().having( (e) => e.message, 'message', contains('Could not find t.'), @@ -104,7 +104,7 @@ void main() { expect( file.errors.errors, - contains(isA().having( + contains(isA().having( (e) => e.message, 'message', contains('Nested star columns may only appear in a top-level select ' diff --git a/drift_dev/test/analyzer/moor/custom_row_classes_test.dart b/drift_dev/test/analyzer/drift/custom_row_classes_test.dart similarity index 92% rename from drift_dev/test/analyzer/moor/custom_row_classes_test.dart rename to drift_dev/test/analyzer/drift/custom_row_classes_test.dart index 2a8bc924..d84d7fa2 100644 --- a/drift_dev/test/analyzer/moor/custom_row_classes_test.dart +++ b/drift_dev/test/analyzer/drift/custom_row_classes_test.dart @@ -39,11 +39,11 @@ class ExistingForView { final file = await state.analyze('package:a/db.moor'); expect(file.errors.errors, isEmpty); - final result = file.currentResult as ParsedMoorFile; + final result = file.currentResult as ParsedDriftFile; final customName = result.declaredEntities - .singleWhere((e) => e.displayName == 'custom_name') as MoorTable; + .singleWhere((e) => e.displayName == 'custom_name') as DriftTable; final existing = result.declaredEntities - .singleWhere((e) => e.displayName == 'existing') as MoorTable; + .singleWhere((e) => e.displayName == 'existing') as DriftTable; final existingView = result.declaredEntities .singleWhere((e) => e.displayName == 'existing_view') as MoorView; @@ -86,7 +86,7 @@ CREATE TABLE moor_ints ( final file = await state.analyze('package:a/generic.moor'); expect(file.errors.errors, isEmpty); - final tables = (file.currentResult as ParsedMoorFile).declaredTables; + final tables = (file.currentResult as ParsedDriftFile).declaredTables; final strings = tables.singleWhere((e) => e.sqlName == 'moor_strings'); final ints = tables.singleWhere((e) => e.sqlName == 'moor_ints'); diff --git a/drift_dev/test/analyzer/moor/entity_handler_test.dart b/drift_dev/test/analyzer/drift/entity_handler_test.dart similarity index 95% rename from drift_dev/test/analyzer/moor/entity_handler_test.dart rename to drift_dev/test/analyzer/drift/entity_handler_test.dart index f6dd8987..239b4625 100644 --- a/drift_dev/test/analyzer/moor/entity_handler_test.dart +++ b/drift_dev/test/analyzer/drift/entity_handler_test.dart @@ -41,7 +41,7 @@ CREATE TABLE friendships ( expect( table.references, [ - const TypeMatcher() + const TypeMatcher() .having((table) => table.displayName, 'displayName', 'users'), ], ); @@ -75,9 +75,9 @@ END; expect( trigger.references, { - const TypeMatcher().having( + const TypeMatcher().having( (table) => table.displayName, 'displayName', 'friendships'), - const TypeMatcher() + const TypeMatcher() .having((table) => table.displayName, 'displayName', 'users'), }, ); @@ -102,7 +102,7 @@ CREATE INDEX idx ON users (name); final trigger = file.currentResult!.declaredEntities.single as MoorIndex; expect(trigger.references, { - const TypeMatcher() + const TypeMatcher() .having((table) => table.displayName, 'displayName', 'users'), }); }); diff --git a/drift_dev/test/analyzer/moor/errors_when_importing_part_files_test.dart b/drift_dev/test/analyzer/drift/errors_when_importing_part_files_test.dart similarity index 97% rename from drift_dev/test/analyzer/moor/errors_when_importing_part_files_test.dart rename to drift_dev/test/analyzer/drift/errors_when_importing_part_files_test.dart index 3e197fe1..f5eaf9ba 100644 --- a/drift_dev/test/analyzer/moor/errors_when_importing_part_files_test.dart +++ b/drift_dev/test/analyzer/drift/errors_when_importing_part_files_test.dart @@ -37,7 +37,7 @@ void main() { expect(file.errors.errors, hasLength(1)); expect( file.errors.errors.single, - isA() + isA() .having( (e) => e.message, 'message', diff --git a/drift_dev/test/analyzer/moor/moor_ffi_extension_test.dart b/drift_dev/test/analyzer/drift/moor_ffi_extension_test.dart similarity index 93% rename from drift_dev/test/analyzer/moor/moor_ffi_extension_test.dart rename to drift_dev/test/analyzer/drift/moor_ffi_extension_test.dart index 88eef5e0..eab4572d 100644 --- a/drift_dev/test/analyzer/moor/moor_ffi_extension_test.dart +++ b/drift_dev/test/analyzer/drift/moor_ffi_extension_test.dart @@ -1,6 +1,6 @@ import 'package:drift_dev/moor_generator.dart'; +import 'package:drift_dev/src/analyzer/drift/moor_ffi_extension.dart'; import 'package:drift_dev/src/analyzer/errors.dart'; -import 'package:drift_dev/src/analyzer/moor/moor_ffi_extension.dart'; import 'package:drift_dev/src/analyzer/options.dart'; import 'package:drift_dev/src/analyzer/runner/results.dart'; import 'package:sqlparser/sqlparser.dart' hide ResultColumn; @@ -98,14 +98,14 @@ import 'a.moor'; wrongArgs: SELECT sin(oid, foo) FROM numbers; ''' }, - options: const MoorOptions.defaults(modules: [SqlModule.moor_ffi]), + options: const DriftOptions.defaults(modules: [SqlModule.moor_ffi]), ); addTearDown(state.close); final fileA = await state.analyze('package:foo/a.moor'); expect(fileA.errors.errors, isEmpty); - final resultA = fileA.currentResult as ParsedMoorFile; + final resultA = fileA.currentResult as ParsedDriftFile; final queryInA = resultA.resolvedQueries!.single as SqlSelectQuery; expect( @@ -116,7 +116,7 @@ wrongArgs: SELECT sin(oid, foo) FROM numbers; final fileB = await state.analyze('package:foo/b.moor'); expect(fileB.errors.errors, [ - const TypeMatcher() + const TypeMatcher() .having((e) => e.span.text, 'span.text', 'sin(oid, foo)') ]); }); diff --git a/drift_dev/test/analyzer/moor/moor_parser_test.dart b/drift_dev/test/analyzer/drift/moor_parser_test.dart similarity index 97% rename from drift_dev/test/analyzer/moor/moor_parser_test.dart rename to drift_dev/test/analyzer/drift/moor_parser_test.dart index 436a0ae9..c46e72b6 100644 --- a/drift_dev/test/analyzer/moor/moor_parser_test.dart +++ b/drift_dev/test/analyzer/drift/moor_parser_test.dart @@ -68,7 +68,7 @@ usersWithLongName: SELECT * FROM users WHERE LENGTH(name) > 25; final result = await state.analyze('package:foo/a.moor'); state.close(); - final file = result.currentResult as ParsedMoorFile; + final file = result.currentResult as ParsedDriftFile; final users1 = file.declaredTables.singleWhere((t) => t.sqlName == 'users'); final users2 = diff --git a/drift_dev/test/analyzer/moor/regression_1138_test.dart b/drift_dev/test/analyzer/drift/regression_1138_test.dart similarity index 100% rename from drift_dev/test/analyzer/moor/regression_1138_test.dart rename to drift_dev/test/analyzer/drift/regression_1138_test.dart diff --git a/drift_dev/test/analyzer/moor/regression_754_test.dart b/drift_dev/test/analyzer/drift/regression_754_test.dart similarity index 94% rename from drift_dev/test/analyzer/moor/regression_754_test.dart rename to drift_dev/test/analyzer/drift/regression_754_test.dart index 15aa8d13..94ddda25 100644 --- a/drift_dev/test/analyzer/moor/regression_754_test.dart +++ b/drift_dev/test/analyzer/drift/regression_754_test.dart @@ -25,7 +25,7 @@ CREATE TRIGGER tbl_au AFTER UPDATE ON tbl BEGIN INSERT INTO fts_idx(rowid, b, c) VALUES (new.a, new.b, new.c); END; ''', - }, options: const MoorOptions.defaults(modules: [SqlModule.fts5])); + }, options: const DriftOptions.defaults(modules: [SqlModule.fts5])); final result = await state.analyze('package:foo/a.moor'); diff --git a/drift_dev/test/analyzer/moor/sqlite_version_test.dart b/drift_dev/test/analyzer/drift/sqlite_version_test.dart similarity index 94% rename from drift_dev/test/analyzer/moor/sqlite_version_test.dart rename to drift_dev/test/analyzer/drift/sqlite_version_test.dart index 4ed36958..52ac358d 100644 --- a/drift_dev/test/analyzer/moor/sqlite_version_test.dart +++ b/drift_dev/test/analyzer/drift/sqlite_version_test.dart @@ -29,7 +29,7 @@ void main() { expect(file.errors.errors, hasLength(1)); expect( file.errors.errors.single, - isA().having( + isA().having( (e) => e.message, 'message', allOf( @@ -46,7 +46,7 @@ void main() { const { 'a|lib/main.moor': _moorFile, }, - options: const MoorOptions.defaults( + options: const DriftOptions.defaults( sqliteAnalysisOptions: SqliteAnalysisOptions( version: SqliteVersion.v3_35, ), diff --git a/drift_dev/test/analyzer/moor/virtual_table_test.dart b/drift_dev/test/analyzer/drift/virtual_table_test.dart similarity index 93% rename from drift_dev/test/analyzer/moor/virtual_table_test.dart rename to drift_dev/test/analyzer/drift/virtual_table_test.dart index 1482ed0f..f3cf35b7 100644 --- a/drift_dev/test/analyzer/moor/virtual_table_test.dart +++ b/drift_dev/test/analyzer/drift/virtual_table_test.dart @@ -33,7 +33,7 @@ exampleSearch: SELECT example_table.**, s.* FROM example_table ON s.rowid = example_table.rowid; ''', }, - options: const MoorOptions.defaults(modules: [SqlModule.fts5]), + options: const DriftOptions.defaults(modules: [SqlModule.fts5]), ); addTearDown(state.close); @@ -63,7 +63,7 @@ SELECT rowid, highlight(example_table_search, 0, '[match]', '[match]') name, FROM example_table_search WHERE example_table_search MATCH simple_query(:search); ''', }, - options: const MoorOptions.defaults(modules: [SqlModule.fts5]), + options: const DriftOptions.defaults(modules: [SqlModule.fts5]), ); addTearDown(state.close); final result = await state.analyze('package:a/table.moor'); diff --git a/drift_dev/test/analyzer/options_test.dart b/drift_dev/test/analyzer/options_test.dart index 7a61d025..062e75bf 100644 --- a/drift_dev/test/analyzer/options_test.dart +++ b/drift_dev/test/analyzer/options_test.dart @@ -4,8 +4,8 @@ import 'package:sqlparser/sqlparser.dart'; import 'package:test/test.dart'; void main() { - MoorOptions parse(String yaml) { - return checkedYamlDecode(yaml, (m) => MoorOptions.fromJson(m!)); + DriftOptions parse(String yaml) { + return checkedYamlDecode(yaml, (m) => DriftOptions.fromJson(m!)); } test('does not allow modules and sqlite options', () { @@ -31,7 +31,7 @@ sqlite: sqlite: version: "3.35" '''), - isA().having((e) => e.sqliteVersion, 'sqliteVersion', + isA().having((e) => e.sqliteVersion, 'sqliteVersion', const SqliteVersion(3, 35, 0)), ); }); diff --git a/drift_dev/test/analyzer/runner/task_test.dart b/drift_dev/test/analyzer/runner/task_test.dart index 1d41e9e0..c0ad2094 100644 --- a/drift_dev/test/analyzer/runner/task_test.dart +++ b/drift_dev/test/analyzer/runner/task_test.dart @@ -17,7 +17,7 @@ import 'b.moor'; expect( result.errors.errors, - contains(const TypeMatcher().having( + contains(const TypeMatcher().having( (e) => e.message, 'message', allOf(contains('b.moor'), contains('file does not exist')), diff --git a/drift_dev/test/analyzer/sql_queries/custom_result_class_test.dart b/drift_dev/test/analyzer/sql_queries/custom_result_class_test.dart index ee738a7f..a5f3909c 100644 --- a/drift_dev/test/analyzer/sql_queries/custom_result_class_test.dart +++ b/drift_dev/test/analyzer/sql_queries/custom_result_class_test.dart @@ -7,12 +7,12 @@ import 'package:test/test.dart'; import '../utils.dart'; void main() { - Future _analyzeQueries(String moorFile) async { + Future _analyzeQueries(String moorFile) async { final state = TestState.withContent({'foo|lib/a.moor': moorFile}); final result = await state.analyze('package:foo/a.moor'); state.close(); - final queries = (result.currentResult as ParsedMoorFile).resolvedQueries; + final queries = (result.currentResult as ParsedDriftFile).resolvedQueries; return Database()..queries = queries; } diff --git a/drift_dev/test/analyzer/sql_queries/inference_test.dart b/drift_dev/test/analyzer/sql_queries/inference_test.dart index c1777059..b5b930d0 100644 --- a/drift_dev/test/analyzer/sql_queries/inference_test.dart +++ b/drift_dev/test/analyzer/sql_queries/inference_test.dart @@ -35,10 +35,10 @@ totalDurationByArtist: INNER JOIN tracks ON tracks.album = albums.id GROUP BY a.id; ''' - }, options: const MoorOptions.defaults()); + }, options: const DriftOptions.defaults()); final file = await state.analyze('package:foo/a.moor'); - final result = file.currentResult as ParsedMoorFile; + final result = file.currentResult as ParsedDriftFile; final queries = result.resolvedQueries; expect(state.session.errorsInFileAndImports(file), isEmpty); diff --git a/drift_dev/test/analyzer/sql_queries/linter_test.dart b/drift_dev/test/analyzer/sql_queries/linter_test.dart index 73121d17..57379e73 100644 --- a/drift_dev/test/analyzer/sql_queries/linter_test.dart +++ b/drift_dev/test/analyzer/sql_queries/linter_test.dart @@ -58,7 +58,7 @@ all ($limit = 3): SELECT * FROM foo LIMIT $limit; expect( result.errors.errors, - contains(isA().having( + contains(isA().having( (e) => e.message, 'message', contains('only supported for expressions'), @@ -83,7 +83,7 @@ in: INSERT INTO foo (id) $placeholder; expect( result.errors.errors, - contains(isA().having( + contains(isA().having( (e) => e.message, 'message', contains("Dart placeholders can't be used here"), @@ -110,7 +110,7 @@ all: SELECT foo.** FROM foo UNION ALL SELECT foo.** FROM foo; expect( result.errors.errors, - contains(isA().having( + contains(isA().having( (e) => e.message, 'message', contains('columns may only appear in a top-level select'), @@ -139,7 +139,7 @@ all: SELECT foo.**, LIST(SELECT *, LIST(SELECT * FROM foo) FROM foo) FROM foo; expect( result.errors.errors, - contains(isA().having( + contains(isA().having( (e) => e.message, 'message', contains('query may only appear in a top-level select'), @@ -158,7 +158,7 @@ all: SELECT foo.**, LIST(SELECT *, LIST(SELECT * FROM foo) FROM foo) FROM foo; final file = await state!.analyze('package:foo/a.moor'); expect( file.errors.errors, - contains(const TypeMatcher().having( + contains(const TypeMatcher().having( (e) => e.message, 'message', 'Expected tuple to have 2 values')), ); } diff --git a/drift_dev/test/analyzer/sql_queries/queries_from_views.dart b/drift_dev/test/analyzer/sql_queries/queries_from_views.dart index 017b9548..0ea5a35c 100644 --- a/drift_dev/test/analyzer/sql_queries/queries_from_views.dart +++ b/drift_dev/test/analyzer/sql_queries/queries_from_views.dart @@ -38,10 +38,10 @@ CREATE VIEW total_duration_by_artist_view AS totalDurationByArtist: SELECT * FROM total_duration_by_artist_view; ''' - }, options: const MoorOptions.defaults()); + }, options: const DriftOptions.defaults()); final file = await state.analyze('package:foo/a.moor'); - final result = file.currentResult as ParsedMoorFile; + final result = file.currentResult as ParsedDriftFile; final queries = result.resolvedQueries; expect(state.session.errorsInFileAndImports(file), isEmpty); diff --git a/drift_dev/test/analyzer/sql_queries/query_analyzer_test.dart b/drift_dev/test/analyzer/sql_queries/query_analyzer_test.dart index f12f792b..a46e535c 100644 --- a/drift_dev/test/analyzer/sql_queries/query_analyzer_test.dart +++ b/drift_dev/test/analyzer/sql_queries/query_analyzer_test.dart @@ -17,7 +17,7 @@ bar(?1 AS TEXT, :foo AS BOOLEAN): SELECT ?, :foo; state.close(); expect(file.errors.errors, isEmpty); - final content = file.currentResult as ParsedMoorFile; + final content = file.currentResult as ParsedDriftFile; final query = content.resolvedQueries!.single; expect(query, const TypeMatcher()); @@ -41,7 +41,7 @@ bar(REQUIRED ?1 AS TEXT OR NULL, REQUIRED :foo AS BOOLEAN): SELECT ?, :foo; state.close(); expect(file.errors.errors, isEmpty); - final content = file.currentResult as ParsedMoorFile; + final content = file.currentResult as ParsedDriftFile; final query = content.resolvedQueries!.single; expect( diff --git a/drift_dev/test/analyzer/sql_queries/query_handler_test.dart b/drift_dev/test/analyzer/sql_queries/query_handler_test.dart index f7fd5b90..0c890297 100644 --- a/drift_dev/test/analyzer/sql_queries/query_handler_test.dart +++ b/drift_dev/test/analyzer/sql_queries/query_handler_test.dart @@ -1,5 +1,5 @@ import 'package:drift_dev/moor_generator.dart'; -import 'package:drift_dev/src/analyzer/moor/create_table_reader.dart'; +import 'package:drift_dev/src/analyzer/drift/create_table_reader.dart'; import 'package:drift_dev/src/analyzer/runner/file_graph.dart'; import 'package:drift_dev/src/analyzer/runner/results.dart'; import 'package:drift_dev/src/analyzer/runner/steps.dart'; @@ -32,7 +32,7 @@ Future main() async { final task = await state.runTask('package:a/foo.drift'); final step = ParseMoorStep( - task, FoundFile(Uri.parse('file://foo'), FileType.moor), ''); + task, FoundFile(Uri.parse('file://foo'), FileType.drift), ''); final parsedFoo = engine.parse(createFoo).rootNode as CreateTableStatement; final foo = await CreateTableReader(parsedFoo, step, await task.helper) @@ -99,7 +99,7 @@ FROM routes }); final file = await state.analyze('package:foo/main.moor'); - final result = file.currentResult as ParsedMoorFile; + final result = file.currentResult as ParsedDriftFile; state.close(); expect(file.errors.errors, isEmpty); @@ -146,7 +146,7 @@ LEFT JOIN tableB1 AS tableB2 -- nullable }); final file = await state.analyze('package:foo/main.moor'); - final result = file.currentResult as ParsedMoorFile; + final result = file.currentResult as ParsedDriftFile; state.close(); expect(file.errors.errors, isEmpty); @@ -177,7 +177,7 @@ query: SELECT * FROM my_view; final file = await state.analyze('package:foo/main.moor'); expect(file.errors.errors, isEmpty); - final result = file.currentResult as ParsedMoorFile; + final result = file.currentResult as ParsedDriftFile; final query = result.resolvedQueries!.single; expect( @@ -200,7 +200,7 @@ query: SELECT foo.**, bar.** FROM my_view foo, my_view bar; final file = await state.analyze('package:foo/main.moor'); expect(file.errors.errors, isEmpty); - final result = file.currentResult as ParsedMoorFile; + final result = file.currentResult as ParsedDriftFile; final query = result.resolvedQueries!.single; expect(query.resultSet!.nestedResults, hasLength(2)); diff --git a/drift_dev/test/analyzer/utils.dart b/drift_dev/test/analyzer/utils.dart index 587f43c7..9c62a0a8 100644 --- a/drift_dev/test/analyzer/utils.dart +++ b/drift_dev/test/analyzer/utils.dart @@ -16,7 +16,7 @@ class TestState { TestState(this.backend, this.session); factory TestState.withContent(Map content, - {MoorOptions? options}) { + {DriftOptions? options}) { final backend = TestBackend( { for (final entry in content.entries) diff --git a/drift_dev/test/backends/build/generators/moor_generator_test.dart b/drift_dev/test/backends/build/generators/moor_generator_test.dart index a96dabee..98e3ae5f 100644 --- a/drift_dev/test/backends/build/generators/moor_generator_test.dart +++ b/drift_dev/test/backends/build/generators/moor_generator_test.dart @@ -14,17 +14,17 @@ void main() { logs.stream, emitsThrough( allOf( - contains('Dart 2.1'), + contains('Dart 2.11'), contains('Please consider raising the minimum SDK version'), ), ), ); await testBuilder( - moorBuilder(BuilderOptions.empty), + driftBuilder(BuilderOptions.empty), { 'foo|lib/a.dart': ''' -// @dart = 2.1 +// @dart = 2.11 import 'package:drift/drift.dart'; diff --git a/drift_dev/test/backends/build/preprocess_builder_tests.dart b/drift_dev/test/backends/build/preprocess_builder_tests.dart index 9da9ab3d..bf1fa9b5 100644 --- a/drift_dev/test/backends/build/preprocess_builder_tests.dart +++ b/drift_dev/test/backends/build/preprocess_builder_tests.dart @@ -42,7 +42,7 @@ class MyConverter extends TypeConverter { ); final output = - utf8.decode(writer.assets[AssetId.parse('foo|main.dart_in_moor')]!); + utf8.decode(writer.assets[AssetId.parse('foo|main.dart_in_drift')]!); final serialized = json.decode(output); expect(serialized['const MyConverter()'], { @@ -90,7 +90,7 @@ class MyConverter extends TypeConverter { ); final output = - utf8.decode(writer.assets[AssetId.parse('foo|main.dart_in_moor')]!); + utf8.decode(writer.assets[AssetId.parse('foo|main.dart_in_drift')]!); final serialized = json.decode(output); expect(serialized['const MyConverter()'], { diff --git a/drift_dev/test/model/specified_table_test.dart b/drift_dev/test/model/specified_table_test.dart index 83d3dc26..b19f697c 100644 --- a/drift_dev/test/model/specified_table_test.dart +++ b/drift_dev/test/model/specified_table_test.dart @@ -4,15 +4,15 @@ import 'package:test/test.dart'; void main() { test('companion names', () { - final table = MoorTable( + final table = DriftTable( sqlName: 'user', overriddenName: 'GoogleUser', dartTypeName: 'User'); - expect(table.getNameForCompanionClass(const MoorOptions.defaults()), + expect(table.getNameForCompanionClass(const DriftOptions.defaults()), 'GoogleUserCompanion'); expect( table.getNameForCompanionClass( - const MoorOptions.defaults(useDataClassNameForCompanions: true)), + const DriftOptions.defaults(useDataClassNameForCompanions: true)), 'UserCompanion', ); }); diff --git a/drift_dev/test/services/schema/writer_test.dart b/drift_dev/test/services/schema/writer_test.dart index 39b6e90b..51522b08 100644 --- a/drift_dev/test/services/schema/writer_test.dart +++ b/drift_dev/test/services/schema/writer_test.dart @@ -64,7 +64,7 @@ class SettingsConverter extends TypeConverter { @DriftDatabase(include: {'a.moor'}, tables: [Users]) class Database {} ''', - }, options: const MoorOptions.defaults(modules: [SqlModule.fts5])); + }, options: const DriftOptions.defaults(modules: [SqlModule.fts5])); final file = await state.analyze('package:foo/main.dart'); expect(state.session.errorsInFileAndImports(file), isEmpty); @@ -83,7 +83,7 @@ class Database {} // Write the database. Not crashing is good enough for us here, we have // separate tests for verification - final writer = Writer(const MoorOptions.defaults(), + final writer = Writer(const DriftOptions.defaults(), generationOptions: const GenerationOptions(forSchema: 1)); DatabaseWriter(fakeDb, writer.child()).write(); }); diff --git a/drift_dev/test/utils/entity_reference_sorter_test.dart b/drift_dev/test/utils/entity_reference_sorter_test.dart index 16d31810..b6dd1458 100644 --- a/drift_dev/test/utils/entity_reference_sorter_test.dart +++ b/drift_dev/test/utils/entity_reference_sorter_test.dart @@ -4,8 +4,8 @@ import 'package:test/test.dart'; void main() { test('throws cyclic exception when two tables reference each other', () { - final first = MoorTable(sqlName: 'a', dartTypeName: 'a'); - final second = MoorTable(sqlName: 'b', dartTypeName: 'b'); + final first = DriftTable(sqlName: 'a', dartTypeName: 'a'); + final second = DriftTable(sqlName: 'b', dartTypeName: 'b'); first.references.add(second); second.references.add(first); @@ -15,10 +15,10 @@ void main() { }); test('throws cyclic exception on a circular reference with three tables', () { - final a = MoorTable(sqlName: 'a', dartTypeName: 'a'); - final b = MoorTable(sqlName: 'b', dartTypeName: 'b'); - final c = MoorTable(sqlName: 'c', dartTypeName: 'c'); - final d = MoorTable(sqlName: 'd', dartTypeName: 'd'); + final a = DriftTable(sqlName: 'a', dartTypeName: 'a'); + final b = DriftTable(sqlName: 'b', dartTypeName: 'b'); + final c = DriftTable(sqlName: 'c', dartTypeName: 'c'); + final d = DriftTable(sqlName: 'd', dartTypeName: 'd'); a.references.add(b); b.references.add(c); @@ -31,10 +31,10 @@ void main() { }); test('sorts tables topologically when no cycles exist', () { - final a = MoorTable(sqlName: 'a', dartTypeName: 'a'); - final b = MoorTable(sqlName: 'b', dartTypeName: 'b'); - final c = MoorTable(sqlName: 'c', dartTypeName: 'c'); - final d = MoorTable(sqlName: 'd', dartTypeName: 'd'); + final a = DriftTable(sqlName: 'a', dartTypeName: 'a'); + final b = DriftTable(sqlName: 'b', dartTypeName: 'b'); + final c = DriftTable(sqlName: 'c', dartTypeName: 'c'); + final d = DriftTable(sqlName: 'd', dartTypeName: 'd'); a.references.add(b); b.references.add(c); @@ -45,8 +45,8 @@ void main() { test('accepts self-references', () { // https://github.com/simolus3/drift/issues/586 - final a = MoorTable(sqlName: 'a', dartTypeName: 'a'); - final b = MoorTable(sqlName: 'b', dartTypeName: 'b'); + final a = DriftTable(sqlName: 'a', dartTypeName: 'a'); + final b = DriftTable(sqlName: 'b', dartTypeName: 'b'); a.references ..add(a) @@ -57,7 +57,7 @@ void main() { }); } -CircularReferenceException _expectFails(Iterable table) { +CircularReferenceException _expectFails(Iterable table) { try { sortEntitiesTopologically(table); fail('Expected sortTablesTopologically to throw here'); diff --git a/drift_dev/test/writer/mutable_classes_integration_test.dart b/drift_dev/test/writer/mutable_classes_integration_test.dart index a0138096..26ef90e7 100644 --- a/drift_dev/test/writer/mutable_classes_integration_test.dart +++ b/drift_dev/test/writer/mutable_classes_integration_test.dart @@ -4,7 +4,7 @@ import 'package:analyzer/dart/ast/ast.dart'; import 'package:analyzer/file_system/memory_file_system.dart'; import 'package:build/build.dart'; import 'package:build_test/build_test.dart'; -import 'package:drift_dev/src/backends/build/moor_builder.dart'; +import 'package:drift_dev/src/backends/build/drift_builder.dart'; import 'package:pub_semver/pub_semver.dart'; import 'package:test/test.dart'; @@ -30,7 +30,7 @@ class Database extends _$Database {} void main() { test('generates mutable classes if needed', () async { await testBuilder( - MoorPartBuilder(const BuilderOptions({'mutable_classes': true})), + DriftPartBuilder(const BuilderOptions({'mutable_classes': true})), const {'a|lib/main.dart': _testInput}, reader: await PackageAssetReader.currentIsolate(), outputs: const { diff --git a/drift_dev/test/writer/queries/query_writer_test.dart b/drift_dev/test/writer/queries/query_writer_test.dart index b2ecc4c0..fd5f0b5f 100644 --- a/drift_dev/test/writer/queries/query_writer_test.dart +++ b/drift_dev/test/writer/queries/query_writer_test.dart @@ -19,10 +19,10 @@ void main() { addTearDown(state.close); final file = await state.analyze('package:a/main.moor'); - final fileState = file.currentResult as ParsedMoorFile; + final fileState = file.currentResult as ParsedDriftFile; final writer = - Writer(const MoorOptions.defaults(generateNamedParameters: true)); + Writer(const DriftOptions.defaults(generateNamedParameters: true)); QueryWriter(writer.child()).write(fileState.resolvedQueries!.single); expect(writer.writeGenerated(), contains('required List idList')); @@ -41,9 +41,9 @@ void main() { addTearDown(state.close); final file = await state.analyze('package:a/main.moor'); - final fileState = file.currentResult as ParsedMoorFile; + final fileState = file.currentResult as ParsedDriftFile; - final writer = Writer(const MoorOptions.defaults()); + final writer = Writer(const DriftOptions.defaults()); QueryWriter(writer.child()).write(fileState.resolvedQueries!.single); expect( @@ -68,9 +68,9 @@ void main() { addTearDown(state.close); final file = await state.analyze('package:a/main.moor'); - final fileState = file.currentResult as ParsedMoorFile; + final fileState = file.currentResult as ParsedDriftFile; - final writer = Writer(const MoorOptions.defaults()); + final writer = Writer(const DriftOptions.defaults()); QueryWriter(writer.child()).write(fileState.resolvedQueries!.single); expect( @@ -101,9 +101,9 @@ void main() { tearDown(() => state.close()); - Future _runTest(MoorOptions options, Matcher expectation) async { + Future _runTest(DriftOptions options, Matcher expectation) async { final file = await state.analyze('package:a/main.moor'); - final fileState = file.currentResult as ParsedMoorFile; + final fileState = file.currentResult as ParsedDriftFile; expect(file.errors.errors, isEmpty); @@ -115,7 +115,7 @@ void main() { test('with the new query generator', () { return _runTest( - const MoorOptions.defaults(), + const DriftOptions.defaults(), allOf( contains(r'var $arrayStartIndex = 3;'), contains(r'SELECT * FROM tbl WHERE a = ?1 AND b IN ($expandedb) ' @@ -151,9 +151,9 @@ void main() { tearDown(() => state.close()); Future _runTest( - MoorOptions options, List expectation) async { + DriftOptions options, List expectation) async { final file = await state.analyze('package:a/main.moor'); - final fileState = file.currentResult as ParsedMoorFile; + final fileState = file.currentResult as ParsedDriftFile; expect(file.errors.errors, isEmpty); @@ -168,7 +168,7 @@ void main() { test('should generate correct queries with variables', () { return _runTest( - const MoorOptions.defaults(), + const DriftOptions.defaults(), [ contains( r'SELECT parent.a, parent.a AS "\$n_0" FROM tbl AS parent WHERE parent.a = ?1', @@ -188,7 +188,7 @@ void main() { test('should generate correct data class', () { return _runTest( - const MoorOptions.defaults(), + const DriftOptions.defaults(), [ contains('QueryNestedQuery0({this.b,this.c,})'), contains('QueryResult({this.a,required this.nestedQuery0,})'), diff --git a/drift_dev/test/writer/queries/sql_writer_test.dart b/drift_dev/test/writer/queries/sql_writer_test.dart index fdc06258..b69b0ac2 100644 --- a/drift_dev/test/writer/queries/sql_writer_test.dart +++ b/drift_dev/test/writer/queries/sql_writer_test.dart @@ -12,7 +12,7 @@ void main() { InferredResultSet(null, []), null, null); final result = - SqlWriter(const MoorOptions.defaults(), query: query).write(); + SqlWriter(const DriftOptions.defaults(), query: query).write(); expect(result, expectedDart); } diff --git a/drift_dev/tool/debug_plugin.dart b/drift_dev/tool/debug_plugin.dart index f440d7e8..e328e10a 100644 --- a/drift_dev/tool/debug_plugin.dart +++ b/drift_dev/tool/debug_plugin.dart @@ -25,7 +25,7 @@ void main(List args) { return; } - MoorPlugin.forProduction().start(_WebSocketPluginServer(port: port)); + DriftPlugin.forProduction().start(_WebSocketPluginServer(port: port)); } class _WebSocketPluginServer implements PluginCommunicationChannel { diff --git a/moor_generator/build.yaml b/moor_generator/build.yaml index 0155fb8a..3dd4d684 100644 --- a/moor_generator/build.yaml +++ b/moor_generator/build.yaml @@ -14,7 +14,7 @@ builders: preparing_builder: import: "package:moor_generator/integrations/build.dart" builder_factories: ["preparingBuilder"] - build_extensions: {".moor": [".temp.dart", ".dart_in_moor"]} + build_extensions: {".moor": [".temp.dart", ".dart_in_drift"]} build_to: cache auto_apply: dependents applies_builders: ["moor_generator|moor_cleanup"] @@ -25,7 +25,7 @@ builders: build_extensions: {".dart": [".moor.g.part"]} auto_apply: dependents build_to: cache - required_inputs: [".dart_in_moor"] + required_inputs: [".dart_in_drift"] applies_builders: ["source_gen|combining_builder"] moor_generator_not_shared: @@ -34,7 +34,7 @@ builders: build_extensions: {".dart": [".moor.dart"]} build_to: source auto_apply: none - required_inputs: [".dart_in_moor"] + required_inputs: [".dart_in_drift"] post_process_builders: moor_cleanup: diff --git a/moor_generator/lib/integrations/build.dart b/moor_generator/lib/integrations/build.dart index 6027a1fd..0ff7c468 100644 --- a/moor_generator/lib/integrations/build.dart +++ b/moor_generator/lib/integrations/build.dart @@ -1,13 +1,13 @@ // ignore_for_file: implementation_imports import 'package:build/build.dart'; -import 'package:drift_dev/src/backends/build/moor_builder.dart'; +import 'package:drift_dev/src/backends/build/drift_builder.dart'; import 'package:drift_dev/src/backends/build/preprocess_builder.dart'; Builder moorBuilder(BuilderOptions options) => - MoorSharedPartBuilder(options, isForNewDriftPackage: false); + DriftSharedPartBuilder(options, isForNewDriftPackage: false); Builder moorBuilderNotShared(BuilderOptions options) => - MoorPartBuilder(options, isForNewDriftPackage: false); + DriftPartBuilder(options, isForNewDriftPackage: false); Builder preparingBuilder(BuilderOptions options) => PreprocessBuilder();