mirror of https://github.com/AMT-Cheif/drift.git
parent
40dafa1f2e
commit
17aabbe446
|
@ -26,16 +26,24 @@ class BoolType extends SqlType<bool> {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
bool mapFromDatabaseResponse(response) {
|
bool mapFromDatabaseResponse(response) {
|
||||||
|
// ignore: avoid_returning_null
|
||||||
|
if (response == null) return null;
|
||||||
return response != 0;
|
return response != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String mapToSqlConstant(bool content) {
|
String mapToSqlConstant(bool content) {
|
||||||
|
if (content == null) {
|
||||||
|
return 'NULL';
|
||||||
|
}
|
||||||
return content ? '1' : '0';
|
return content ? '1' : '0';
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
mapToSqlVariable(bool content) {
|
mapToSqlVariable(bool content) {
|
||||||
|
if (content == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
return content ? 1 : 0;
|
return content ? 1 : 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
import 'package:moor/moor.dart' hide isNull;
|
||||||
|
import 'package:test/test.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
test('types map null values to null', () {
|
||||||
|
final typeSystem = const SqlTypeSystem.withDefaults();
|
||||||
|
|
||||||
|
for (var type in typeSystem.types) {
|
||||||
|
expect(type.mapToSqlVariable(null), isNull,
|
||||||
|
reason: '$type should map null to null variables');
|
||||||
|
expect(type.mapFromDatabaseResponse(null), isNull,
|
||||||
|
reason: '$type should map null response to null value');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
Loading…
Reference in New Issue