mirror of https://github.com/AMT-Cheif/drift.git
Scaffold classes for type and reference analysis
This commit is contained in:
parent
b0649ee208
commit
5d1046ba3a
|
@ -0,0 +1,10 @@
|
||||||
|
import 'package:meta/meta.dart';
|
||||||
|
|
||||||
|
part 'schema/column.dart';
|
||||||
|
part 'schema/references.dart';
|
||||||
|
part 'schema/table.dart';
|
||||||
|
|
||||||
|
part 'types/data.dart';
|
||||||
|
part 'types/resolution.dart';
|
||||||
|
|
||||||
|
part 'types/typeable.dart';
|
|
@ -0,0 +1,7 @@
|
||||||
|
part of '../analysis.dart';
|
||||||
|
|
||||||
|
class Column with Referencable, Typeable {
|
||||||
|
final String name;
|
||||||
|
|
||||||
|
Column(this.name);
|
||||||
|
}
|
|
@ -0,0 +1,38 @@
|
||||||
|
part of '../analysis.dart';
|
||||||
|
|
||||||
|
/// Mixin for classes which represent a reference.
|
||||||
|
mixin ReferenceOwner {}
|
||||||
|
|
||||||
|
/// Mixin for classes which can be referenced by a [ReferenceOwner].
|
||||||
|
mixin Referencable {}
|
||||||
|
|
||||||
|
/// Class which keeps track of references tables, columns and functions in a
|
||||||
|
/// query.
|
||||||
|
class ReferenceScope {
|
||||||
|
final ReferenceScope parent;
|
||||||
|
final Map<String, Referencable> _references = {};
|
||||||
|
|
||||||
|
ReferenceScope(this.parent);
|
||||||
|
|
||||||
|
ReferenceScope createChild() {
|
||||||
|
return ReferenceScope(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void register(String identifier, Referencable ref) {
|
||||||
|
_references[identifier.toUpperCase()] = ref;
|
||||||
|
}
|
||||||
|
|
||||||
|
Referencable resolve(String name) {
|
||||||
|
var scope = this;
|
||||||
|
final upper = name.toUpperCase();
|
||||||
|
|
||||||
|
while (scope != null) {
|
||||||
|
if (scope._references.containsKey(upper)) {
|
||||||
|
return scope._references[upper];
|
||||||
|
}
|
||||||
|
scope = scope.parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null; // not found in any parent scope
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,8 @@
|
||||||
|
part of '../analysis.dart';
|
||||||
|
|
||||||
|
class Table with Referencable {
|
||||||
|
final String name;
|
||||||
|
final List<Column> columns;
|
||||||
|
|
||||||
|
Table({@required this.name, @required this.columns});
|
||||||
|
}
|
|
@ -0,0 +1,23 @@
|
||||||
|
part of '../analysis.dart';
|
||||||
|
|
||||||
|
/// A type that sql expressions can have at runtime.
|
||||||
|
abstract class SqlType {}
|
||||||
|
|
||||||
|
class NullType extends SqlType {}
|
||||||
|
|
||||||
|
class IntegerType extends SqlType {}
|
||||||
|
|
||||||
|
class RealType extends SqlType {}
|
||||||
|
|
||||||
|
class TextType extends SqlType {}
|
||||||
|
|
||||||
|
class BlobType extends SqlType {}
|
||||||
|
|
||||||
|
/// Provides more precise hints than the [SqlType]. For instance, booleans are
|
||||||
|
/// stored as ints in sqlite, but it might be desirable to know whether an
|
||||||
|
/// expression will actually be a boolean.
|
||||||
|
abstract class TypeHint {}
|
||||||
|
|
||||||
|
class IsBoolean extends TypeHint {}
|
||||||
|
|
||||||
|
class IsDateTime extends TypeHint {}
|
|
@ -0,0 +1,3 @@
|
||||||
|
part of '../analysis.dart';
|
||||||
|
|
||||||
|
class TypeResolutionState {}
|
|
@ -0,0 +1,6 @@
|
||||||
|
part of '../analysis.dart';
|
||||||
|
|
||||||
|
/// Something that has a type.
|
||||||
|
mixin Typeable {
|
||||||
|
TypeResolutionState resolutionState;
|
||||||
|
}
|
Loading…
Reference in New Issue