Explicit nullability

This commit is contained in:
Simon Binder 2019-02-14 16:01:57 +01:00
parent 624d0980e0
commit b2736421d8
7 changed files with 39 additions and 1 deletions

View File

@ -44,6 +44,7 @@
<value>
<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.1/lib" />
</list>
</value>
</entry>
@ -58,6 +59,7 @@
<value>
<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.4.0/lib" />
</list>
</value>
</entry>
@ -65,6 +67,7 @@
<value>
<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-1.0.3/lib" />
</list>
</value>
</entry>
@ -72,6 +75,7 @@
<value>
<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.6/lib" />
</list>
</value>
</entry>
@ -79,6 +83,7 @@
<value>
<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.3/lib" />
</list>
</value>
</entry>
@ -489,6 +494,7 @@
<value>
<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.15/lib" />
</list>
</value>
</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/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.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_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-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.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.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/built_collection-4.1.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/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.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/term_glyph-1.1.0/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/test-1.5.3/lib" />

View File

@ -27,6 +27,10 @@ class ColumnBuilder<Builder, ResultColumn> {
Builder named(String name) => null;
Builder primaryKey() => null;
/// Marks this column as nullable. Nullable columns should not appear in a
/// primary key.
Builder nullable() => null;
ResultColumn call() => null;
}

View File

@ -11,5 +11,8 @@ dependencies:
meta: '>= 1.0.0 <2.0.0'
dev_dependencies:
sally_generator:
path: ../sally_generator
build_runner: ^1.2.6
test: ^1.5.3
mockito: ^4.0.0

View File

@ -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()();
}

View File

@ -47,6 +47,9 @@ class SpecifiedColumn {
final ColumnType type;
/// The name of this column, as chosen by the user
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.
bool get hasAI => features.any((f) => f is AutoIncrement);
@ -96,6 +99,7 @@ class SpecifiedColumn {
this.dartGetterName,
this.name,
this.declaredAsPrimaryKey = false,
this.nullable = false,
this.features = const []});
}

View File

@ -17,6 +17,7 @@ const String functionPrimaryKey = 'primaryKey';
const String functionReferences = 'references';
const String functionAutoIncrement = 'autoIncrement';
const String functionWithLength = 'withLength';
const String functionNullable = 'nullable';
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 '
@ -53,6 +54,7 @@ class ColumnParser extends ParserBase {
String foundStartMethod;
String foundExplicitName;
var wasDeclaredAsPrimaryKey = false;
var nullable = false;
// todo parse reference
final foundFeatures = <ColumnFeature>[];
@ -104,6 +106,8 @@ class ColumnParser extends ParserBase {
wasDeclaredAsPrimaryKey = true;
foundFeatures.add(AutoIncrement());
break;
case functionNullable:
nullable = true;
}
// 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,
name: name.escapeIfSqlKeyword(),
declaredAsPrimaryKey: wasDeclaredAsPrimaryKey,
nullable: nullable,
features: foundFeatures);
}

View File

@ -115,7 +115,7 @@ class TableWriter {
}
void _writeColumnGetter(StringBuffer buffer, SpecifiedColumn column) {
final isNullable = false; // todo nullability for columns
final isNullable = column.nullable;
final additionalParams = <String, String>{};
if (column.hasAI) {