Skip to content

Unimplemented Text Decoding Types in PostgresTextDecoder #125

Closed
@osaxma

Description

@osaxma

I think at some point we need to implement the rest of the types here:

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.

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

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions