mirror of https://github.com/AMT-Cheif/drift.git
Improve changelog, error description for columns
This commit is contained in:
parent
fb66ad101a
commit
3f0c35abff
|
@ -1,6 +1,6 @@
|
||||||
## unreleased
|
## unreleased
|
||||||
|
|
||||||
- Support custom expressions from selects in the Dart API:
|
- Support custom expressions for selects in the Dart API:
|
||||||
```dart
|
```dart
|
||||||
final currentBalance = accounts.income - accounts.expenses;
|
final currentBalance = accounts.income - accounts.expenses;
|
||||||
select(accounts).addColumns([currentBalance]).map((row) {
|
select(accounts).addColumns([currentBalance]).map((row) {
|
||||||
|
@ -9,8 +9,9 @@
|
||||||
return ...
|
return ...
|
||||||
}).get();
|
}).get();
|
||||||
```
|
```
|
||||||
- Provide Dart apis for the json1 extension in the `package:moor/extensions/json1.dart` library. Note that
|
- Support the `json1` and `fts5` extensions! Using them also requires version 2.2 of `moor_generator`
|
||||||
json1 is not supported on most platforms.
|
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
|
- Standardized behavior of batches in transactions across backends
|
||||||
- Introduced `OrderingTerm.asc` and `OrderingTerm.desc` factories to construct ordering terms more
|
- Introduced `OrderingTerm.asc` and `OrderingTerm.desc` factories to construct ordering terms more
|
||||||
easily
|
easily
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import 'package:build/build.dart';
|
import 'package:build/build.dart';
|
||||||
import 'package:moor_generator/src/analyzer/options.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/results.dart';
|
||||||
import 'package:moor_generator/src/analyzer/runner/task.dart';
|
import 'package:moor_generator/src/analyzer/runner/task.dart';
|
||||||
import 'package:moor_generator/src/analyzer/session.dart';
|
import 'package:moor_generator/src/analyzer/session.dart';
|
||||||
|
@ -36,19 +37,20 @@ class MoorBuilder extends SharedPartBuilder {
|
||||||
|
|
||||||
Future<ParsedDartFile> analyzeDartFile(BuildStep step) async {
|
Future<ParsedDartFile> analyzeDartFile(BuildStep step) async {
|
||||||
Task task;
|
Task task;
|
||||||
|
FoundFile input;
|
||||||
try {
|
try {
|
||||||
final backend = BuildBackend();
|
final backend = BuildBackend();
|
||||||
final backendTask = backend.createTask(step);
|
final backendTask = backend.createTask(step);
|
||||||
final session = MoorSession(backend, options: options);
|
final session = MoorSession(backend, options: options);
|
||||||
|
|
||||||
final input = session.registerFile(step.inputId.uri);
|
input = session.registerFile(step.inputId.uri);
|
||||||
task = session.startTask(backendTask);
|
task = session.startTask(backendTask);
|
||||||
await task.runTask();
|
await task.runTask();
|
||||||
|
|
||||||
return input.currentResult as ParsedDartFile;
|
|
||||||
} finally {
|
} finally {
|
||||||
task.printErrors();
|
task?.printErrors();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return input?.currentResult as ParsedDartFile;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,3 +22,8 @@ part 'steps/type_resolver.dart';
|
||||||
part 'types/data.dart';
|
part 'types/data.dart';
|
||||||
part 'types/resolver.dart';
|
part 'types/resolver.dart';
|
||||||
part 'types/typeable.dart';
|
part 'types/typeable.dart';
|
||||||
|
|
||||||
|
/// Something that can be represented in a human-readable description.
|
||||||
|
abstract class HumanReadable {
|
||||||
|
String humanReadableDescription();
|
||||||
|
}
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
part of '../analysis.dart';
|
part of '../analysis.dart';
|
||||||
|
|
||||||
/// A column that appears in a [ResultSet]. Has a type and a name.
|
/// 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.
|
/// The name of this column in the result set.
|
||||||
String get name;
|
String get name;
|
||||||
|
|
||||||
|
@ -12,6 +14,11 @@ abstract class Column with Referencable, HasMetaMixin implements Typeable {
|
||||||
bool get includedInResults => true;
|
bool get includedInResults => true;
|
||||||
|
|
||||||
Column();
|
Column();
|
||||||
|
|
||||||
|
@override
|
||||||
|
String humanReadableDescription() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A column that is part of a table.
|
/// A column that is part of a table.
|
||||||
|
@ -83,6 +90,11 @@ class TableColumn extends Column {
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
String humanReadableDescription() {
|
||||||
|
return '$name in ${table.humanReadableDescription()}';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Refers to the special "rowid", "oid" or "_rowid_" column defined for tables
|
/// Refers to the special "rowid", "oid" or "_rowid_" column defined for tables
|
||||||
|
|
|
@ -26,7 +26,9 @@ abstract class ResultSet implements ResolvesToResultSet {
|
||||||
|
|
||||||
/// A database table. The information stored here will be used to resolve
|
/// A database table. The information stored here will be used to resolve
|
||||||
/// references and for type inference.
|
/// 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 name of this table, as it appears in sql statements. This should be
|
||||||
/// the raw name, not an escaped version.
|
/// the raw name, not an escaped version.
|
||||||
final String name;
|
final String name;
|
||||||
|
@ -78,4 +80,9 @@ class Table with ResultSet, VisibleToChildren, HasMetaMixin {
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
String humanReadableDescription() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,19 +16,13 @@ class ReferenceResolver extends RecursiveVisitor<void> {
|
||||||
|
|
||||||
if (e.tableName != null) {
|
if (e.tableName != null) {
|
||||||
// first find the referenced table, then use the column on that table.
|
// first find the referenced table, then use the column on that table.
|
||||||
final tableResolver =
|
final tableResolver = scope.resolve<ResolvesToResultSet>(e.tableName);
|
||||||
scope.resolve<ResolvesToResultSet>(e.tableName, orElse: () {
|
final resultSet = tableResolver?.resultSet;
|
||||||
context.reportError(AnalysisError(
|
|
||||||
type: AnalysisErrorType.referencedUnknownTable,
|
|
||||||
message: 'Unknown table: ${e.tableName}',
|
|
||||||
relevantNode: e,
|
|
||||||
));
|
|
||||||
});
|
|
||||||
final resultSet = tableResolver.resultSet;
|
|
||||||
|
|
||||||
if (resultSet == null) {
|
if (resultSet == null) {
|
||||||
context.reportError(AnalysisError(
|
context.reportError(AnalysisError(
|
||||||
type: AnalysisErrorType.referencedUnknownTable,
|
type: AnalysisErrorType.referencedUnknownTable,
|
||||||
|
message: 'Unknown table: ${e.tableName}',
|
||||||
relevantNode: e,
|
relevantNode: e,
|
||||||
));
|
));
|
||||||
} else {
|
} else {
|
||||||
|
@ -63,10 +57,13 @@ class ReferenceResolver extends RecursiveVisitor<void> {
|
||||||
type: AnalysisErrorType.referencedUnknownColumn, relevantNode: e));
|
type: AnalysisErrorType.referencedUnknownColumn, relevantNode: e));
|
||||||
} else {
|
} else {
|
||||||
if (columns.length > 1) {
|
if (columns.length > 1) {
|
||||||
|
final description =
|
||||||
|
columns.map((c) => c.humanReadableDescription()).join(', ');
|
||||||
|
|
||||||
context.reportError(AnalysisError(
|
context.reportError(AnalysisError(
|
||||||
type: AnalysisErrorType.ambiguousReference,
|
type: AnalysisErrorType.ambiguousReference,
|
||||||
relevantNode: e,
|
relevantNode: e,
|
||||||
message: 'Could refer to any in ${columns.join(', ')}',
|
message: 'Could refer to any of: $description',
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue