Initial draft of outline model

This commit is contained in:
Simon Binder 2022-08-19 22:20:28 +02:00
parent 5a49c9540b
commit 7bc0aecf4c
No known key found for this signature in database
GPG Key ID: 7891917E4147B8C0
4 changed files with 110 additions and 0 deletions

View File

@ -0,0 +1,74 @@
import 'package:drift/drift.dart' show DriftSqlType;
import 'dart.dart';
import 'element.dart';
class DriftColumn {
final DriftSqlType sqlType;
/// Whether the user has explicitly declared this column to be nullable.
///
/// For Dart-defined columns, this defaults to `false`. For columns defined in
/// a drift file, this value will be `true` if there is no `NOT NULL`
/// constraint present on the column's definition.
final bool nullable;
final String nameInSql;
final String nameInDart;
final AppliedTypeConverter? typeConverter;
final DriftDeclaration? declaration;
DriftColumn({
required this.sqlType,
required this.nullable,
required this.nameInSql,
required this.nameInDart,
this.typeConverter,
this.declaration,
});
}
class AppliedTypeConverter {
/// The Dart expression creating an instance of the applied type converter.
final AnnotatedDartCode expression;
final AnnotatedDartCode dartType;
final DriftSqlType sqlType;
/// Whether the Dart-value output of this type converter is nullable.
///
/// In other words, [dartType] is potentially nullable.
final bool dartTypeIsNullable;
/// Whether the SQL-value output of this type converter is nullable.
///
/// In other words, [sqlType] is potentially nullable.
final bool sqlTypeIsNullable;
/// Whether this type converter should also be used in the generated JSON
/// serialization.
final bool alsoAppliesToJsonConversion;
/// Whether this type converter can be skipped for `null` values.
///
/// This applies to type converters with a non-nullable Dart and SQL type if
/// the column is nullable. For those converters, drift maps `null` to `null`
/// without calling the type converter at all.
///
/// For nullable columns, this is implemented by wrapping it in a
/// `NullAwareTypeConverter` in the generated code for table classes. For
/// nullable references to non-nullable columns (e.g. from outer joins), this
/// is done with static helper methods on `NullAwareTypeConverter`.
bool get canBeSkippedForNulls => !dartTypeIsNullable && !sqlTypeIsNullable;
AppliedTypeConverter({
required this.expression,
required this.dartType,
required this.sqlType,
required this.dartTypeIsNullable,
required this.sqlTypeIsNullable,
this.alsoAppliesToJsonConversion = false,
});
}

View File

@ -0,0 +1,14 @@
import 'element.dart';
class AnnotatedDartCode {
final List<dynamic> elements;
AnnotatedDartCode(this.elements);
}
class DartTopLevelSymbol {
final String lexeme;
final DriftElementId elementId;
DartTopLevelSymbol(this.lexeme, this.elementId);
}

View File

@ -0,0 +1,22 @@
import 'package:path/path.dart' show url;
class DriftElementId {
final Uri libraryUri;
final String name;
DriftElementId(this.libraryUri, this.name);
bool get isDefinedInDart => url.extension(libraryUri.path) == '.dart';
bool get isDefinedInDrift => url.extension(libraryUri.path) == '.drift';
}
class DriftDeclaration {
final Uri sourceUri;
final int offset;
DriftDeclaration(this.sourceUri, this.offset);
}
abstract class DriftElement {
DriftElementId get id;
}