mirror of https://github.com/AMT-Cheif/drift.git
Explicit nullability
This commit is contained in:
parent
624d0980e0
commit
b2736421d8
|
@ -44,6 +44,7 @@
|
||||||
<value>
|
<value>
|
||||||
<list>
|
<list>
|
||||||
<option value="$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/build-1.1.0/lib" />
|
<option value="$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/build-1.1.0/lib" />
|
||||||
|
<option value="$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/build-1.1.1/lib" />
|
||||||
</list>
|
</list>
|
||||||
</value>
|
</value>
|
||||||
</entry>
|
</entry>
|
||||||
|
@ -58,6 +59,7 @@
|
||||||
<value>
|
<value>
|
||||||
<list>
|
<list>
|
||||||
<option value="$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/build_daemon-0.2.3/lib" />
|
<option value="$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/build_daemon-0.2.3/lib" />
|
||||||
|
<option value="$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/build_daemon-0.4.0/lib" />
|
||||||
</list>
|
</list>
|
||||||
</value>
|
</value>
|
||||||
</entry>
|
</entry>
|
||||||
|
@ -65,6 +67,7 @@
|
||||||
<value>
|
<value>
|
||||||
<list>
|
<list>
|
||||||
<option value="$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/build_resolvers-0.2.3/lib" />
|
<option value="$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/build_resolvers-0.2.3/lib" />
|
||||||
|
<option value="$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/build_resolvers-1.0.3/lib" />
|
||||||
</list>
|
</list>
|
||||||
</value>
|
</value>
|
||||||
</entry>
|
</entry>
|
||||||
|
@ -72,6 +75,7 @@
|
||||||
<value>
|
<value>
|
||||||
<list>
|
<list>
|
||||||
<option value="$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/build_runner-1.2.3/lib" />
|
<option value="$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/build_runner-1.2.3/lib" />
|
||||||
|
<option value="$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/build_runner-1.2.6/lib" />
|
||||||
</list>
|
</list>
|
||||||
</value>
|
</value>
|
||||||
</entry>
|
</entry>
|
||||||
|
@ -79,6 +83,7 @@
|
||||||
<value>
|
<value>
|
||||||
<list>
|
<list>
|
||||||
<option value="$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/build_runner_core-2.0.1/lib" />
|
<option value="$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/build_runner_core-2.0.1/lib" />
|
||||||
|
<option value="$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/build_runner_core-2.0.3/lib" />
|
||||||
</list>
|
</list>
|
||||||
</value>
|
</value>
|
||||||
</entry>
|
</entry>
|
||||||
|
@ -489,6 +494,7 @@
|
||||||
<value>
|
<value>
|
||||||
<list>
|
<list>
|
||||||
<option value="$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/stream_transform-0.0.14+1/lib" />
|
<option value="$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/stream_transform-0.0.14+1/lib" />
|
||||||
|
<option value="$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/stream_transform-0.0.15/lib" />
|
||||||
</list>
|
</list>
|
||||||
</value>
|
</value>
|
||||||
</entry>
|
</entry>
|
||||||
|
@ -604,11 +610,16 @@
|
||||||
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/async-2.0.8/lib" />
|
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/async-2.0.8/lib" />
|
||||||
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/boolean_selector-1.0.4/lib" />
|
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/boolean_selector-1.0.4/lib" />
|
||||||
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/build-1.1.0/lib" />
|
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/build-1.1.0/lib" />
|
||||||
|
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/build-1.1.1/lib" />
|
||||||
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/build_config-0.3.1+4/lib" />
|
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/build_config-0.3.1+4/lib" />
|
||||||
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/build_daemon-0.2.3/lib" />
|
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/build_daemon-0.2.3/lib" />
|
||||||
|
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/build_daemon-0.4.0/lib" />
|
||||||
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/build_resolvers-0.2.3/lib" />
|
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/build_resolvers-0.2.3/lib" />
|
||||||
|
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/build_resolvers-1.0.3/lib" />
|
||||||
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/build_runner-1.2.3/lib" />
|
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/build_runner-1.2.3/lib" />
|
||||||
|
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/build_runner-1.2.6/lib" />
|
||||||
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/build_runner_core-2.0.1/lib" />
|
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/build_runner_core-2.0.1/lib" />
|
||||||
|
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/build_runner_core-2.0.3/lib" />
|
||||||
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/build_test-0.10.6/lib" />
|
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/build_test-0.10.6/lib" />
|
||||||
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/built_collection-4.1.0/lib" />
|
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/built_collection-4.1.0/lib" />
|
||||||
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/built_value-6.3.0/lib" />
|
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/built_value-6.3.0/lib" />
|
||||||
|
@ -664,6 +675,7 @@
|
||||||
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/stack_trace-1.9.3/lib" />
|
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/stack_trace-1.9.3/lib" />
|
||||||
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/stream_channel-1.6.8/lib" />
|
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/stream_channel-1.6.8/lib" />
|
||||||
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/stream_transform-0.0.14+1/lib" />
|
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/stream_transform-0.0.14+1/lib" />
|
||||||
|
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/stream_transform-0.0.15/lib" />
|
||||||
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/string_scanner-1.0.4/lib" />
|
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/string_scanner-1.0.4/lib" />
|
||||||
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/term_glyph-1.1.0/lib" />
|
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/term_glyph-1.1.0/lib" />
|
||||||
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/test-1.5.3/lib" />
|
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/test-1.5.3/lib" />
|
||||||
|
|
|
@ -27,6 +27,10 @@ class ColumnBuilder<Builder, ResultColumn> {
|
||||||
Builder named(String name) => null;
|
Builder named(String name) => null;
|
||||||
Builder primaryKey() => null;
|
Builder primaryKey() => null;
|
||||||
|
|
||||||
|
/// Marks this column as nullable. Nullable columns should not appear in a
|
||||||
|
/// primary key.
|
||||||
|
Builder nullable() => null;
|
||||||
|
|
||||||
ResultColumn call() => null;
|
ResultColumn call() => null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,5 +11,8 @@ dependencies:
|
||||||
meta: '>= 1.0.0 <2.0.0'
|
meta: '>= 1.0.0 <2.0.0'
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
|
sally_generator:
|
||||||
|
path: ../sally_generator
|
||||||
|
build_runner: ^1.2.6
|
||||||
test: ^1.5.3
|
test: ^1.5.3
|
||||||
mockito: ^4.0.0
|
mockito: ^4.0.0
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
import 'package:sally/sally.dart';
|
||||||
|
|
||||||
|
@DataClassName('TodoEntry')
|
||||||
|
class TodosTable extends Table {
|
||||||
|
|
||||||
|
IntColumn get id => integer().autoIncrement()();
|
||||||
|
TextColumn get title => text().withLength(min: 4, max: 6)();
|
||||||
|
TextColumn get content => text()();
|
||||||
|
|
||||||
|
}
|
|
@ -47,6 +47,9 @@ class SpecifiedColumn {
|
||||||
final ColumnType type;
|
final ColumnType type;
|
||||||
/// The name of this column, as chosen by the user
|
/// The name of this column, as chosen by the user
|
||||||
final ColumnName name;
|
final ColumnName name;
|
||||||
|
/// Whether the user has explicitly declared this column to be nullable, the
|
||||||
|
/// default is false
|
||||||
|
final bool nullable;
|
||||||
|
|
||||||
/// Whether this column has auto increment.
|
/// Whether this column has auto increment.
|
||||||
bool get hasAI => features.any((f) => f is AutoIncrement);
|
bool get hasAI => features.any((f) => f is AutoIncrement);
|
||||||
|
@ -96,6 +99,7 @@ class SpecifiedColumn {
|
||||||
this.dartGetterName,
|
this.dartGetterName,
|
||||||
this.name,
|
this.name,
|
||||||
this.declaredAsPrimaryKey = false,
|
this.declaredAsPrimaryKey = false,
|
||||||
|
this.nullable = false,
|
||||||
this.features = const []});
|
this.features = const []});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,7 @@ const String functionPrimaryKey = 'primaryKey';
|
||||||
const String functionReferences = 'references';
|
const String functionReferences = 'references';
|
||||||
const String functionAutoIncrement = 'autoIncrement';
|
const String functionAutoIncrement = 'autoIncrement';
|
||||||
const String functionWithLength = 'withLength';
|
const String functionWithLength = 'withLength';
|
||||||
|
const String functionNullable = 'nullable';
|
||||||
|
|
||||||
const String errorMessage = 'This getter does not create a valid column that '
|
const String errorMessage = 'This getter does not create a valid column that '
|
||||||
'can be parsed by sally. Please refer to the readme from sally to see how '
|
'can be parsed by sally. Please refer to the readme from sally to see how '
|
||||||
|
@ -53,6 +54,7 @@ class ColumnParser extends ParserBase {
|
||||||
String foundStartMethod;
|
String foundStartMethod;
|
||||||
String foundExplicitName;
|
String foundExplicitName;
|
||||||
var wasDeclaredAsPrimaryKey = false;
|
var wasDeclaredAsPrimaryKey = false;
|
||||||
|
var nullable = false;
|
||||||
// todo parse reference
|
// todo parse reference
|
||||||
final foundFeatures = <ColumnFeature>[];
|
final foundFeatures = <ColumnFeature>[];
|
||||||
|
|
||||||
|
@ -104,6 +106,8 @@ class ColumnParser extends ParserBase {
|
||||||
wasDeclaredAsPrimaryKey = true;
|
wasDeclaredAsPrimaryKey = true;
|
||||||
foundFeatures.add(AutoIncrement());
|
foundFeatures.add(AutoIncrement());
|
||||||
break;
|
break;
|
||||||
|
case functionNullable:
|
||||||
|
nullable = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// We're not at a starting method yet, so we need to go deeper!
|
// We're not at a starting method yet, so we need to go deeper!
|
||||||
|
@ -123,6 +127,7 @@ class ColumnParser extends ParserBase {
|
||||||
dartGetterName: getter.name.name,
|
dartGetterName: getter.name.name,
|
||||||
name: name.escapeIfSqlKeyword(),
|
name: name.escapeIfSqlKeyword(),
|
||||||
declaredAsPrimaryKey: wasDeclaredAsPrimaryKey,
|
declaredAsPrimaryKey: wasDeclaredAsPrimaryKey,
|
||||||
|
nullable: nullable,
|
||||||
features: foundFeatures);
|
features: foundFeatures);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -115,7 +115,7 @@ class TableWriter {
|
||||||
}
|
}
|
||||||
|
|
||||||
void _writeColumnGetter(StringBuffer buffer, SpecifiedColumn column) {
|
void _writeColumnGetter(StringBuffer buffer, SpecifiedColumn column) {
|
||||||
final isNullable = false; // todo nullability for columns
|
final isNullable = column.nullable;
|
||||||
final additionalParams = <String, String>{};
|
final additionalParams = <String, String>{};
|
||||||
|
|
||||||
if (column.hasAI) {
|
if (column.hasAI) {
|
||||||
|
|
Loading…
Reference in New Issue