Remove generated code from core package

This commit is contained in:
Simon Binder 2023-10-18 22:47:24 +02:00
parent 63448dd070
commit 2ba3dfdcd8
No known key found for this signature in database
GPG Key ID: 7891917E4147B8C0
4 changed files with 65 additions and 25 deletions

View File

@ -2,18 +2,14 @@
@internal
library;
import 'package:json_annotation/json_annotation.dart';
import 'package:meta/meta.dart';
import '../api/runtime_api.dart';
import '../query_builder/query_builder.dart';
import '../types/mapping.dart';
part 'shared.g.dart';
typedef JsonObject = Map<String, Object?>;
@JsonSerializable()
class TypeDescription {
final DriftSqlType? type;
final String? customTypeName;
@ -28,16 +24,26 @@ class TypeDescription {
};
}
factory TypeDescription.fromJson(JsonObject obj) =>
_$TypeDescriptionFromJson(obj);
factory TypeDescription.fromJson(JsonObject obj) {
final typeName = obj['type'] as String?;
JsonObject toJson() => _$TypeDescriptionToJson(this);
return TypeDescription(
type: typeName != null ? DriftSqlType.values.byName(typeName) : null,
customTypeName: obj['customTypeName'] as String?,
);
}
JsonObject toJson() {
return {
'type': type?.name,
'customTypeName': customTypeName,
};
}
}
@JsonSerializable()
class ColumnDescription {
final String name;
final TypeDescription? type;
final TypeDescription type;
final bool isNullable;
ColumnDescription(
@ -52,13 +58,23 @@ class ColumnDescription {
);
}
factory ColumnDescription.fromJson(JsonObject obj) =>
_$ColumnDescriptionFromJson(obj);
factory ColumnDescription.fromJson(JsonObject obj) {
return ColumnDescription(
name: obj['name'] as String,
type: TypeDescription.fromJson(obj['type'] as JsonObject),
isNullable: obj['isNullable'] as bool,
);
}
JsonObject toJson() => _$ColumnDescriptionToJson(this);
JsonObject toJson() {
return {
'name': name,
'type': type.toJson(),
'isNullable': isNullable,
};
}
}
@JsonSerializable()
class EntityDescription {
final String name;
final String type;
@ -93,13 +109,28 @@ class EntityDescription {
);
}
factory EntityDescription.fromJson(JsonObject obj) =>
_$EntityDescriptionFromJson(obj);
factory EntityDescription.fromJson(JsonObject obj) {
return EntityDescription(
name: obj['name'] as String,
type: obj['type'] as String,
columns: (obj['columns'] as List<dynamic>)
.map((e) => ColumnDescription.fromJson(e as JsonObject))
.toList(),
);
}
JsonObject toJson() => _$EntityDescriptionToJson(this);
JsonObject toJson() {
return {
'name': name,
'type': type,
'columns': [
if (columns != null)
for (final column in columns!) column.toJson()
],
};
}
}
@JsonSerializable()
class DatabaseDescription {
final bool dateTimeAsText;
final List<EntityDescription> entities;
@ -124,8 +155,19 @@ class DatabaseDescription {
);
}
factory DatabaseDescription.fromJson(JsonObject obj) =>
_$DatabaseDescriptionFromJson(obj);
factory DatabaseDescription.fromJson(JsonObject obj) {
return DatabaseDescription(
dateTimeAsText: obj['dateTimeAsText'] as bool,
entities: (obj['entities'] as List<dynamic>)
.map((e) => EntityDescription.fromJson(e as Map<String, dynamic>))
.toList(),
);
}
JsonObject toJson() => _$DatabaseDescriptionToJson(this);
JsonObject toJson() {
return <String, dynamic>{
'dateTimeAsText': dateTimeAsText,
'entities': [for (final entity in entities) entity.toJson()],
};
}
}

View File

@ -13,7 +13,6 @@ dependencies:
convert: ^3.0.0
collection: ^1.15.0
js: ^0.6.3
json_annotation: ^4.8.1
meta: ^1.3.0
stream_channel: ^2.1.0
sqlite3: ^2.0.0
@ -25,7 +24,6 @@ dev_dependencies:
build_runner_core: ^7.0.0
build_verify: ^3.0.0
build_web_compilers: ^4.0.3
json_serializable: ^6.7.1
drift_dev: any
drift_testcases:
path: ../extras/integration_tests/drift_testcases

View File

@ -76,7 +76,7 @@ class ViewerDatabase implements DbViewerDatabase {
@override
String getType(String entityName, String columnName) {
final type = database.description.entitiesByName[entityName]!
.columnsByName[columnName]!.type!;
.columnsByName[columnName]!.type;
final genContext = GenerationContext(
DriftDatabaseOptions(
storeDateTimeAsText: database.description.dateTimeAsText),
@ -101,7 +101,7 @@ class ViewerDatabase implements DbViewerDatabase {
final resolvedColumn = entity.columnsByName[column];
if (resolvedColumn != null) {
final type = resolvedColumn.type?.type ?? DriftSqlType.any;
final type = resolvedColumn.type.type ?? DriftSqlType.any;
mappedRow[column] = types.read(type, value);
} else {

View File

@ -135,7 +135,7 @@ class _DatabaseListState extends ConsumerState<DatabaseList> {
class _DatabaseEntry extends ConsumerWidget {
final TrackedDatabase database;
const _DatabaseEntry({super.key, required this.database});
const _DatabaseEntry({required this.database});
@override
Widget build(BuildContext context, WidgetRef ref) {