-
Notifications
You must be signed in to change notification settings - Fork 40
Closed
Description
I think at some point we need to implement the rest of the types here:
postgresql-dart/lib/src/text_codec.dart
Lines 221 to 254 in 18b22c5
class PostgresTextDecoder<T extends Object> extends Converter<Uint8List?, T?> { | |
final PgDataType<T> _dataType; | |
const PostgresTextDecoder(this._dataType); | |
@override | |
T? convert(Uint8List? input) { | |
if (input == null) return null; | |
final asText = utf8.decode(input); | |
// ignore: unnecessary_cast | |
switch (_dataType as PgDataType<Object>) { | |
case PgDataType.text: | |
return asText as T; | |
case PgDataType.integer: | |
case PgDataType.smallInteger: | |
case PgDataType.bigInteger: | |
case PgDataType.serial: | |
case PgDataType.bigSerial: | |
return int.parse(asText) as T; | |
case PgDataType.real: | |
case PgDataType.double: | |
return num.parse(asText) as T; | |
case PgDataType.boolean: | |
return (asText == 'true') as T; | |
// We could list out all cases, but it's about 20 lines of code. | |
// ignore: no_default_cases | |
default: | |
throw UnimplementedError('Text decoding for $_dataType'); | |
} | |
} | |
} |
Also:
I caught this incorrect decoding by coincidence when testing. Like in psql
, in text data format (such in the simple protocol), true
and false
are returned as t
and f
, respectively.
postgresql-dart/lib/src/text_codec.dart
Lines 245 to 246 in 18b22c5
case PgDataType.boolean: | |
return (asText == 'true') as T; |
Though, I am not sure if other valid boolean representation are possible (e.g. for true
: 1
, y
, yes
, on
.. etc) to appear here.
I will push a small fix for this one in #118
Metadata
Metadata
Assignees
Labels
No labels