mirror of https://github.com/AMT-Cheif/drift.git
parent
87e39c7ad4
commit
acbcc6bb58
|
@ -116,10 +116,15 @@ class RealType extends SqlType<double> {
|
|||
const RealType();
|
||||
|
||||
@override
|
||||
double mapFromDatabaseResponse(response) => (response as num).toDouble();
|
||||
double mapFromDatabaseResponse(response) => (response as num)?.toDouble();
|
||||
|
||||
@override
|
||||
String mapToSqlConstant(num content) => content.toString();
|
||||
String mapToSqlConstant(num content) {
|
||||
if (content == null) {
|
||||
return 'NULL';
|
||||
}
|
||||
return content.toString();
|
||||
}
|
||||
|
||||
@override
|
||||
mapToSqlVariable(num content) => content;
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
import 'package:moor/moor.dart' as moor;
|
||||
import 'package:test_api/test_api.dart';
|
||||
|
||||
void main() {
|
||||
final type = const moor.RealType();
|
||||
|
||||
group('RealType', () {
|
||||
test('can be read from floating point values returned by sql', () {
|
||||
expect(type.mapFromDatabaseResponse(3.1234), 3.1234);
|
||||
});
|
||||
|
||||
test('can read null value from sql', () {
|
||||
expect(type.mapFromDatabaseResponse(null), isNull);
|
||||
});
|
||||
|
||||
test('can be mapped to sql constants', () {
|
||||
expect(type.mapToSqlConstant(1.123), '1.123');
|
||||
});
|
||||
|
||||
test('can be mapped to variables', () {
|
||||
expect(type.mapToSqlVariable(1.123), 1.123);
|
||||
});
|
||||
|
||||
test('map null to null', () {
|
||||
expect(type.mapToSqlConstant(null), 'NULL');
|
||||
expect(type.mapToSqlVariable(null), null);
|
||||
});
|
||||
});
|
||||
}
|
Loading…
Reference in New Issue