decodeValue method

dynamic decodeValue(
  1. String value,
  2. int pgType, {
  3. String? connectionName,
})

Implementation

decodeValue(String value, int pgType, {String? connectionName}) {
  switch (pgType) {
    case _BOOL:
      return value == 't';

    case _INT2: // smallint
    case _INT4: // integer
    case _INT8: // bigint
      return int.parse(value);

    case _FLOAT4: // real
    case _FLOAT8: // double precision
    case _NUMERIC: //Work only for smaller precision
      return double.parse(value);

    case _TIMESTAMP:
    case _TIMESTAMPZ:
    case _DATE:
      return decodeDateTime(value, pgType, connectionName: connectionName);

    case _JSON:
    case _JSONB:
      return jsonDecode(value);

    //TODO binary bytea

    // Not implemented yet - return a string.
    //case _MONEY:
    //case _TIMETZ:
    //case _TIME:
    //case _INTERVAL:

    default:
      final scalarType = _arrayTypes[pgType];
      if (scalarType != null)
        return decodeArray(value, scalarType, connectionName: connectionName);

      // Return a string for unknown types. The end user can parse this.
      return value;
  }
}