From 3f0c35abff2eebc81c645ac8ced117f4fe63f6bb Mon Sep 17 00:00:00 2001 From: Simon Binder Date: Mon, 23 Dec 2019 12:24:22 +0100 Subject: [PATCH] Improve changelog, error description for columns --- moor/CHANGELOG.md | 7 ++++--- .../lib/src/backends/build/moor_builder.dart | 10 ++++++---- sqlparser/lib/src/analysis/analysis.dart | 5 +++++ sqlparser/lib/src/analysis/schema/column.dart | 14 +++++++++++++- sqlparser/lib/src/analysis/schema/table.dart | 9 ++++++++- .../src/analysis/steps/reference_resolver.dart | 17 +++++++---------- 6 files changed, 43 insertions(+), 19 deletions(-) diff --git a/moor/CHANGELOG.md b/moor/CHANGELOG.md index ec171247..5f56e92a 100644 --- a/moor/CHANGELOG.md +++ b/moor/CHANGELOG.md @@ -1,6 +1,6 @@ ## unreleased -- Support custom expressions from selects in the Dart API: +- Support custom expressions for selects in the Dart API: ```dart final currentBalance = accounts.income - accounts.expenses; select(accounts).addColumns([currentBalance]).map((row) { @@ -9,8 +9,9 @@ return ... }).get(); ``` -- Provide Dart apis for the json1 extension in the `package:moor/extensions/json1.dart` library. Note that - json1 is not supported on most platforms. +- Support the `json1` and `fts5` extensions! Using them also requires version 2.2 of `moor_generator` + and they require `moor_ffi`. For details, see the [documentation](https://moor.simonbinder.eu/docs/using-sql/extensions/). +- Provide Dart apis for the json1 extension in the `package:moor/extensions/json1.dart` library. - Standardized behavior of batches in transactions across backends - Introduced `OrderingTerm.asc` and `OrderingTerm.desc` factories to construct ordering terms more easily diff --git a/moor_generator/lib/src/backends/build/moor_builder.dart b/moor_generator/lib/src/backends/build/moor_builder.dart index e2c63aae..23a45bb9 100644 --- a/moor_generator/lib/src/backends/build/moor_builder.dart +++ b/moor_generator/lib/src/backends/build/moor_builder.dart @@ -1,5 +1,6 @@ import 'package:build/build.dart'; import 'package:moor_generator/src/analyzer/options.dart'; +import 'package:moor_generator/src/analyzer/runner/file_graph.dart'; import 'package:moor_generator/src/analyzer/runner/results.dart'; import 'package:moor_generator/src/analyzer/runner/task.dart'; import 'package:moor_generator/src/analyzer/session.dart'; @@ -36,19 +37,20 @@ class MoorBuilder extends SharedPartBuilder { Future analyzeDartFile(BuildStep step) async { Task task; + FoundFile input; try { final backend = BuildBackend(); final backendTask = backend.createTask(step); final session = MoorSession(backend, options: options); - final input = session.registerFile(step.inputId.uri); + input = session.registerFile(step.inputId.uri); task = session.startTask(backendTask); await task.runTask(); - - return input.currentResult as ParsedDartFile; } finally { - task.printErrors(); + task?.printErrors(); } + + return input?.currentResult as ParsedDartFile; } } diff --git a/sqlparser/lib/src/analysis/analysis.dart b/sqlparser/lib/src/analysis/analysis.dart index a8087d8c..8280bbc7 100644 --- a/sqlparser/lib/src/analysis/analysis.dart +++ b/sqlparser/lib/src/analysis/analysis.dart @@ -22,3 +22,8 @@ part 'steps/type_resolver.dart'; part 'types/data.dart'; part 'types/resolver.dart'; part 'types/typeable.dart'; + +/// Something that can be represented in a human-readable description. +abstract class HumanReadable { + String humanReadableDescription(); +} diff --git a/sqlparser/lib/src/analysis/schema/column.dart b/sqlparser/lib/src/analysis/schema/column.dart index 032395d6..93084260 100644 --- a/sqlparser/lib/src/analysis/schema/column.dart +++ b/sqlparser/lib/src/analysis/schema/column.dart @@ -1,7 +1,9 @@ part of '../analysis.dart'; /// A column that appears in a [ResultSet]. Has a type and a name. -abstract class Column with Referencable, HasMetaMixin implements Typeable { +abstract class Column + with Referencable, HasMetaMixin + implements Typeable, HumanReadable { /// The name of this column in the result set. String get name; @@ -12,6 +14,11 @@ abstract class Column with Referencable, HasMetaMixin implements Typeable { bool get includedInResults => true; Column(); + + @override + String humanReadableDescription() { + return name; + } } /// A column that is part of a table. @@ -83,6 +90,11 @@ class TableColumn extends Column { return false; } + + @override + String humanReadableDescription() { + return '$name in ${table.humanReadableDescription()}'; + } } /// Refers to the special "rowid", "oid" or "_rowid_" column defined for tables diff --git a/sqlparser/lib/src/analysis/schema/table.dart b/sqlparser/lib/src/analysis/schema/table.dart index c27aeb53..b91c7cce 100644 --- a/sqlparser/lib/src/analysis/schema/table.dart +++ b/sqlparser/lib/src/analysis/schema/table.dart @@ -26,7 +26,9 @@ abstract class ResultSet implements ResolvesToResultSet { /// A database table. The information stored here will be used to resolve /// references and for type inference. -class Table with ResultSet, VisibleToChildren, HasMetaMixin { +class Table + with ResultSet, VisibleToChildren, HasMetaMixin + implements HumanReadable { /// The name of this table, as it appears in sql statements. This should be /// the raw name, not an escaped version. final String name; @@ -78,4 +80,9 @@ class Table with ResultSet, VisibleToChildren, HasMetaMixin { } return null; } + + @override + String humanReadableDescription() { + return name; + } } diff --git a/sqlparser/lib/src/analysis/steps/reference_resolver.dart b/sqlparser/lib/src/analysis/steps/reference_resolver.dart index c9b5a8f8..39a0695c 100644 --- a/sqlparser/lib/src/analysis/steps/reference_resolver.dart +++ b/sqlparser/lib/src/analysis/steps/reference_resolver.dart @@ -16,19 +16,13 @@ class ReferenceResolver extends RecursiveVisitor { if (e.tableName != null) { // first find the referenced table, then use the column on that table. - final tableResolver = - scope.resolve(e.tableName, orElse: () { - context.reportError(AnalysisError( - type: AnalysisErrorType.referencedUnknownTable, - message: 'Unknown table: ${e.tableName}', - relevantNode: e, - )); - }); - final resultSet = tableResolver.resultSet; + final tableResolver = scope.resolve(e.tableName); + final resultSet = tableResolver?.resultSet; if (resultSet == null) { context.reportError(AnalysisError( type: AnalysisErrorType.referencedUnknownTable, + message: 'Unknown table: ${e.tableName}', relevantNode: e, )); } else { @@ -63,10 +57,13 @@ class ReferenceResolver extends RecursiveVisitor { type: AnalysisErrorType.referencedUnknownColumn, relevantNode: e)); } else { if (columns.length > 1) { + final description = + columns.map((c) => c.humanReadableDescription()).join(', '); + context.reportError(AnalysisError( type: AnalysisErrorType.ambiguousReference, relevantNode: e, - message: 'Could refer to any in ${columns.join(', ')}', + message: 'Could refer to any of: $description', )); }