mirror of https://github.com/AMT-Cheif/drift.git
Fix compilation errors in CLI
This commit is contained in:
parent
3b12faaa46
commit
360ee348a2
|
@ -265,3 +265,9 @@ class LimitingTextLength extends DriftColumnConstraint {
|
||||||
typedOther.maxLength == maxLength;
|
typedOther.maxLength == maxLength;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class DefaultConstraintsFromSchemaFile extends DriftColumnConstraint {
|
||||||
|
final String constraints;
|
||||||
|
|
||||||
|
DefaultConstraintsFromSchemaFile(this.constraints);
|
||||||
|
}
|
||||||
|
|
|
@ -8,8 +8,8 @@ import 'package:logging/logging.dart';
|
||||||
import '../backends/analyzer_context_backend.dart';
|
import '../backends/analyzer_context_backend.dart';
|
||||||
import 'commands/analyze.dart';
|
import 'commands/analyze.dart';
|
||||||
import 'commands/identify_databases.dart';
|
import 'commands/identify_databases.dart';
|
||||||
//import 'commands/migrate.dart';
|
import 'commands/migrate.dart';
|
||||||
//import 'commands/schema.dart';
|
import 'commands/schema.dart';
|
||||||
import 'logging.dart';
|
import 'logging.dart';
|
||||||
|
|
||||||
Future run(List<String> args) async {
|
Future run(List<String> args) async {
|
||||||
|
@ -35,9 +35,9 @@ class MoorCli {
|
||||||
usageLineLength: 80,
|
usageLineLength: 80,
|
||||||
)
|
)
|
||||||
..addCommand(AnalyzeCommand(this))
|
..addCommand(AnalyzeCommand(this))
|
||||||
..addCommand(IdentifyDatabases(this));
|
..addCommand(IdentifyDatabases(this))
|
||||||
// ..addCommand(SchemaCommand(this))
|
..addCommand(SchemaCommand(this))
|
||||||
// ..addCommand(MigrateCommand(this));
|
..addCommand(MigrateCommand(this));
|
||||||
|
|
||||||
_runner.argParser
|
_runner.argParser
|
||||||
.addFlag('verbose', abbr: 'v', defaultsTo: false, negatable: false);
|
.addFlag('verbose', abbr: 'v', defaultsTo: false, negatable: false);
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import 'package:args/command_runner.dart';
|
import 'package:args/command_runner.dart';
|
||||||
import 'package:drift_dev/src/cli/commands/schema/dump.dart';
|
|
||||||
import 'package:drift_dev/src/cli/commands/schema/generate_utils.dart';
|
import 'schema/dump.dart';
|
||||||
|
import 'schema/generate_utils.dart';
|
||||||
|
|
||||||
import '../cli.dart';
|
import '../cli.dart';
|
||||||
|
|
||||||
|
|
|
@ -2,10 +2,10 @@ import 'dart:convert';
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:args/command_runner.dart';
|
import 'package:args/command_runner.dart';
|
||||||
import 'package:drift_dev/src/analyzer/runner/results.dart';
|
|
||||||
import 'package:drift_dev/src/services/schema/schema_files.dart';
|
|
||||||
import 'package:path/path.dart';
|
import 'package:path/path.dart';
|
||||||
|
|
||||||
|
import '../../../analysis/results/results.dart';
|
||||||
|
import '../../../services/schema/schema_files.dart';
|
||||||
import '../../cli.dart';
|
import '../../cli.dart';
|
||||||
|
|
||||||
class DumpSchemaCommand extends Command {
|
class DumpSchemaCommand extends Command {
|
||||||
|
@ -45,10 +45,19 @@ class DumpSchemaCommand extends Command {
|
||||||
cli.exit('Unexpected error: The input file could not be analyzed');
|
cli.exit('Unexpected error: The input file could not be analyzed');
|
||||||
}
|
}
|
||||||
|
|
||||||
final result = input.fileAnalysis;
|
final databases =
|
||||||
|
input.analysis.values.map((e) => e.result).whereType<DriftDatabase>();
|
||||||
|
|
||||||
final db = result.declaredDatabases.single;
|
if (databases.length != 1) {
|
||||||
final writer = SchemaWriter(db, options: cli.project.moorOptions);
|
cli.exit('Expected the input file to contain exactly one database.');
|
||||||
|
}
|
||||||
|
|
||||||
|
final result = input.fileAnalysis!;
|
||||||
|
final databaseElement = databases.single;
|
||||||
|
final db = result.resolvedDatabases[databaseElement]!;
|
||||||
|
|
||||||
|
final writer =
|
||||||
|
SchemaWriter(db.availableElements, options: cli.project.moorOptions);
|
||||||
|
|
||||||
var target = rest[1];
|
var target = rest[1];
|
||||||
// This command is most commonly used to write into
|
// This command is most commonly used to write into
|
||||||
|
@ -56,7 +65,7 @@ class DumpSchemaCommand extends Command {
|
||||||
// try to infer the file name.
|
// try to infer the file name.
|
||||||
if (await FileSystemEntity.isDirectory(target) ||
|
if (await FileSystemEntity.isDirectory(target) ||
|
||||||
!target.endsWith('.json')) {
|
!target.endsWith('.json')) {
|
||||||
final version = db.schemaVersion;
|
final version = databaseElement.schemaVersion;
|
||||||
|
|
||||||
if (version == null) {
|
if (version == null) {
|
||||||
// Couldn't read schema from database, so fail.
|
// Couldn't read schema from database, so fail.
|
||||||
|
|
|
@ -3,13 +3,16 @@ import 'dart:io';
|
||||||
|
|
||||||
import 'package:args/command_runner.dart';
|
import 'package:args/command_runner.dart';
|
||||||
import 'package:dart_style/dart_style.dart';
|
import 'package:dart_style/dart_style.dart';
|
||||||
import 'package:drift_dev/moor_generator.dart';
|
|
||||||
import 'package:drift_dev/src/cli/cli.dart';
|
|
||||||
import 'package:drift_dev/src/services/schema/schema_files.dart';
|
|
||||||
import 'package:drift_dev/writer.dart';
|
|
||||||
import 'package:path/path.dart' as p;
|
import 'package:path/path.dart' as p;
|
||||||
|
|
||||||
|
import '../../../analysis/results/file_results.dart';
|
||||||
|
import '../../../analysis/results/results.dart';
|
||||||
import '../../../analyzer/options.dart';
|
import '../../../analyzer/options.dart';
|
||||||
|
import '../../../services/schema/schema_files.dart';
|
||||||
|
import '../../../writer/database_writer.dart';
|
||||||
|
import '../../../writer/import_manager.dart';
|
||||||
|
import '../../../writer/writer.dart';
|
||||||
|
import '../../cli.dart';
|
||||||
|
|
||||||
class GenerateUtilsCommand extends Command {
|
class GenerateUtilsCommand extends Command {
|
||||||
final MoorCli cli;
|
final MoorCli cli;
|
||||||
|
@ -117,6 +120,7 @@ class GenerateUtilsCommand extends Command {
|
||||||
forSchema: version,
|
forSchema: version,
|
||||||
writeCompanions: companions,
|
writeCompanions: companions,
|
||||||
writeDataClasses: dataClasses,
|
writeDataClasses: dataClasses,
|
||||||
|
imports: ImportManagerForPartFiles(),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
final file = File(p.join(output.path, _filenameForVersion(version)));
|
final file = File(p.join(output.path, _filenameForVersion(version)));
|
||||||
|
@ -126,12 +130,19 @@ class GenerateUtilsCommand extends Command {
|
||||||
..writeln('//@dart=2.12')
|
..writeln('//@dart=2.12')
|
||||||
..writeln("import 'package:drift/drift.dart';");
|
..writeln("import 'package:drift/drift.dart';");
|
||||||
|
|
||||||
final db = Database(
|
final database = DriftDatabase(
|
||||||
declaredQueries: const [],
|
id: DriftElementId(SchemaReader.elementUri, 'database'),
|
||||||
|
declaration: DriftDeclaration(SchemaReader.elementUri, 0, 'database'),
|
||||||
declaredIncludes: const [],
|
declaredIncludes: const [],
|
||||||
|
declaredQueries: const [],
|
||||||
declaredTables: const [],
|
declaredTables: const [],
|
||||||
)..entities = schema.schema;
|
declaredViews: const [],
|
||||||
DatabaseWriter(db, writer.child()).write();
|
);
|
||||||
|
final resolved =
|
||||||
|
ResolvedDatabaseAccessor(const {}, const [], schema.schema);
|
||||||
|
final input = DatabaseGenerationInput(database, resolved, const {});
|
||||||
|
|
||||||
|
DatabaseWriter(input, writer.child()).write();
|
||||||
|
|
||||||
return file.writeAsString(_dartfmt.format(writer.writeGenerated()));
|
return file.writeAsString(_dartfmt.format(writer.writeGenerated()));
|
||||||
}
|
}
|
||||||
|
@ -178,7 +189,7 @@ class GenerateUtilsCommand extends Command {
|
||||||
}
|
}
|
||||||
|
|
||||||
class _ExportedSchema {
|
class _ExportedSchema {
|
||||||
final List<DriftSchemaEntity> schema;
|
final List<DriftElement> schema;
|
||||||
final Map<String, Object?> options;
|
final Map<String, Object?> options;
|
||||||
|
|
||||||
_ExportedSchema(this.schema, this.options);
|
_ExportedSchema(this.schema, this.options);
|
||||||
|
|
|
@ -1,20 +0,0 @@
|
||||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
|
||||||
|
|
||||||
part of '../../../analysis/results/table.dart';
|
|
||||||
|
|
||||||
// **************************************************************************
|
|
||||||
// JsonSerializableGenerator
|
|
||||||
// **************************************************************************
|
|
||||||
|
|
||||||
VirtualTableData _$VirtualTableDataFromJson(Map json) => VirtualTableData(
|
|
||||||
json['module'] as String,
|
|
||||||
(json['module_arguments'] as List<dynamic>)
|
|
||||||
.map((e) => e as String)
|
|
||||||
.toList(),
|
|
||||||
);
|
|
||||||
|
|
||||||
Map<String, dynamic> _$VirtualTableDataToJson(VirtualTableData instance) =>
|
|
||||||
<String, dynamic>{
|
|
||||||
'module': instance.module,
|
|
||||||
'module_arguments': instance.moduleArguments,
|
|
||||||
};
|
|
|
@ -176,7 +176,7 @@ class SchemaWriter {
|
||||||
|
|
||||||
/// Reads files generated by [SchemaWriter].
|
/// Reads files generated by [SchemaWriter].
|
||||||
class SchemaReader {
|
class SchemaReader {
|
||||||
static final Uri _elementUri = Uri.parse('drift:hidden');
|
static final Uri elementUri = Uri.parse('drift:hidden');
|
||||||
|
|
||||||
final Map<int, DriftElement> _entitiesById = {};
|
final Map<int, DriftElement> _entitiesById = {};
|
||||||
final Map<int, Map<String, dynamic>> _rawById = {};
|
final Map<int, Map<String, dynamic>> _rawById = {};
|
||||||
|
@ -218,10 +218,10 @@ class SchemaReader {
|
||||||
return _entitiesById[id as int] as T;
|
return _entitiesById[id as int] as T;
|
||||||
}
|
}
|
||||||
|
|
||||||
DriftElementId _id(String name) => DriftElementId(_elementUri, name);
|
DriftElementId _id(String name) => DriftElementId(elementUri, name);
|
||||||
|
|
||||||
DriftDeclaration get _declaration =>
|
DriftDeclaration get _declaration =>
|
||||||
DriftDeclaration(_elementUri, -1, '<unknown>');
|
DriftDeclaration(elementUri, -1, '<unknown>');
|
||||||
|
|
||||||
void _processById(int id) {
|
void _processById(int id) {
|
||||||
if (_entitiesById.containsKey(id)) return;
|
if (_entitiesById.containsKey(id)) return;
|
||||||
|
|
Loading…
Reference in New Issue