Fox crash when serializing simple queries

This commit is contained in:
Simon Binder 2022-12-12 22:18:10 +01:00
parent b6cff50135
commit ec2b564611
No known key found for this signature in database
GPG Key ID: 7891917E4147B8C0
2 changed files with 16 additions and 12 deletions

View File

@ -31,9 +31,7 @@ class SchemaWriter {
'version': _infoVersion,
},
'options': _serializeOptions(),
'entities': [
for (final entity in elements) _entityToJson(entity),
],
'entities': elements.map(_entityToJson).whereType<Map>().toList(),
};
}
@ -45,9 +43,9 @@ class SchemaWriter {
return asJson;
}
Map _entityToJson(DriftElement entity) {
String type;
Map data;
Map? _entityToJson(DriftElement entity) {
String? type;
Map? data;
if (entity is DriftTable) {
type = 'table';
@ -86,16 +84,20 @@ class SchemaWriter {
'dart_info_name': entity.entityInfoName,
'columns': [for (final column in entity.columns) _columnData(column)],
};
} else if (entity is DefinedSqlQuery && entity.mode == QueryMode.atCreate) {
type = 'special-query';
data = {
'scenario': 'create',
'sql': entity.sql,
};
} else if (entity is DefinedSqlQuery) {
if (entity.mode == QueryMode.atCreate) {
type = 'special-query';
data = {
'scenario': 'create',
'sql': entity.sql,
};
}
} else {
throw AssertionError('unknown entity type $entity');
}
if (type == null) return null;
return {
'id': _idOf(entity),
'references': [

View File

@ -43,6 +43,8 @@ END;
CREATE INDEX groups_name ON "groups"(name);
CREATE VIEW my_view AS SELECT id FROM "groups";
simple_query: SELECT * FROM my_view; -- not part of the schema
''',
'a|lib/main.dart': '''
import 'package:drift/drift.dart';