Merge pull request #1601 from yanivshaked/develop

Fix support for BlobType
This commit is contained in:
Simon Binder 2021-12-27 22:11:53 +01:00 committed by GitHub
commit 70e83b5a74
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 1 deletions

View File

@ -168,6 +168,10 @@ class BlobType extends SqlType<Uint8List> {
@override
Uint8List? mapFromDatabaseResponse(dynamic response) {
if (response is String) {
final list = response.codeUnits;
return Uint8List.fromList(list);
}
return response as Uint8List?;
}

View File

@ -4,7 +4,7 @@ import 'package:drift/drift.dart';
import 'package:test/test.dart';
void main() {
test('maps without transormation', () {
test('maps without transformation', () {
const type = BlobType();
final data = Uint8List.fromList(List.generate(256, (i) => i));
@ -19,4 +19,14 @@ void main() {
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);
});
}