Add test, simplify fix

This commit is contained in:
Simon Binder 2022-08-15 10:16:00 +02:00
parent d4ca27df58
commit dd6c013cc5
No known key found for this signature in database
GPG Key ID: 7891917E4147B8C0
4 changed files with 15 additions and 5 deletions

View File

@ -1,3 +1,8 @@
## 2.0.1
- Fix an error when inserting a null value into a nullable column defined with
additional checks in Dart.
## 2.0.0
💡: More information on how to migrate is available in the [documentation](https://drift.simonbinder.eu/docs/upgrading/).

View File

@ -190,11 +190,8 @@ class GeneratedColumn<T extends Object> extends Column<T> {
final nullOk = $nullable;
if (!nullOk && value == null) {
return _invalidNull;
} else if (nullOk && value == null) {
return const VerificationResult.success();
} else {
// ignore: null_check_on_nullable_type_parameter
return additionalChecks?.call(value!, meta) ??
return additionalChecks?.call(value, meta) ??
const VerificationResult.success();
}
}

View File

@ -1,6 +1,6 @@
name: drift
description: Drift is a reactive library to store relational data in Dart and Flutter applications.
version: 2.0.0
version: 2.0.1
repository: https://github.com/simolus3/drift
homepage: https://drift.simonbinder.eu/
issue_tracker: https://github.com/simolus3/drift/issues

View File

@ -150,6 +150,14 @@ void main() {
throwsA(isA<InvalidDataException>()),
);
});
test('can provide null value for column with additional checks', () async {
await db.todosTable.insertOne(
TodosTableCompanion.insert(content: 'content', title: Value(null)));
verify(executor.runInsert(
'INSERT INTO todos (title, content) VALUES (NULL, ?)', ['content']));
});
});
test('reports auto-increment id', () {