mirror of https://github.com/AMT-Cheif/drift.git
Merge pull request #1601 from yanivshaked/develop
Fix support for BlobType
This commit is contained in:
commit
70e83b5a74
|
@ -168,6 +168,10 @@ class BlobType extends SqlType<Uint8List> {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Uint8List? mapFromDatabaseResponse(dynamic response) {
|
Uint8List? mapFromDatabaseResponse(dynamic response) {
|
||||||
|
if (response is String) {
|
||||||
|
final list = response.codeUnits;
|
||||||
|
return Uint8List.fromList(list);
|
||||||
|
}
|
||||||
return response as Uint8List?;
|
return response as Uint8List?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ import 'package:drift/drift.dart';
|
||||||
import 'package:test/test.dart';
|
import 'package:test/test.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
test('maps without transormation', () {
|
test('maps without transformation', () {
|
||||||
const type = BlobType();
|
const type = BlobType();
|
||||||
final data = Uint8List.fromList(List.generate(256, (i) => i));
|
final data = Uint8List.fromList(List.generate(256, (i) => i));
|
||||||
|
|
||||||
|
@ -19,4 +19,14 @@ void main() {
|
||||||
|
|
||||||
expect(type.mapToSqlConstant(data), equalsIgnoringCase("x'$hex'"));
|
expect(type.mapToSqlConstant(data), equalsIgnoringCase("x'$hex'"));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('maps of string', () {
|
||||||
|
const chars = 'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz';
|
||||||
|
const type = BlobType();
|
||||||
|
final data = List.generate(256, (i) => chars[i % chars.length]);
|
||||||
|
final dataString = data.join();
|
||||||
|
final dataInt = data.map((e) => e.codeUnits[0]).toList();
|
||||||
|
final dataUint8 = Uint8List.fromList(dataInt);
|
||||||
|
expect(type.mapFromDatabaseResponse(dataString), dataUint8);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue