angel-dart / angel

[ARCHIVED] A polished, production-ready backend framework in Dart for the VM, AOT, and Flutter.
https://angel-dart.dev/
MIT License
1.06k stars 67 forks source link

Incorrect cast of ColumnType.float to DECIMAL in SQL #213

Closed thosakwe closed 3 years ago

thosakwe commented 4 years ago

This issue was originally created by @kevinelliott here, before being automatically moved: https://github.com/angel-dart-archive/orm/issues/101


On the Dart side, I have a model that has double attributes, and it is defined with a column type of float:

  @Column(isNullable: true, type: ColumnType.float)
  double get latitude;
  @Column(isNullable: true, type: ColumnType.float)
  double get longitude;

On the PostgreSQL side, I have these columns as FLOAT.

 latitude            | double precision            |           |          | 
 longitude           | double precision            |           |          | 

However, when the insert occurs, I see in the SQL debug that it is casting to DECIMAL.

FINE: 2019-12-08 19:19:23.217102: Query: WITH messages as (INSERT INTO messages (timestamp, source_type, source, link_direction, from_hex, to_hex, channel, frequency, level, error, mode, label, block_id, ack, tail, flight, message_number, data, text, departing_airport, destination_airport, block_end, latitude, longitude, altitude) VALUES (@timestamp, @source_type, @source, @link_direction, @from_hex, @to_hex, @channel, CAST (@frequency as decimal), @level, @error, @mode, @label, @block_id, @ack, @tail, @flight, @message_number, @data, @text, @departing_airport, @destination_airport, @block_end, CAST (@latitude as decimal), CAST (@longitude as decimal), @altitude) RETURNING messages.id, messages.created_at, messages.updated_at, messages.timestamp, messages.station_id, messages.airframe_id, messages.flight_id, messages.source, messages.source_type, messages.link_direction, messages.from_hex, messages.to_hex, messages.channel, messages.frequency, messages.level, messages.error, messages.mode, messages.label, messages.block_id, messages.ack, messages.tail, messages.flight, messages.message_number, messages.data, messages.text, messages.departing_airport, messages.destination_airport, messages.latitude, messages.longitude, messages.altitude, messages.block_end) SELECT id, created_at, updated_at, timestamp, station_id, airframe_id, flight_id, source, source_type, link_direction, from_hex, to_hex, channel, CAST (frequency AS text), level, error, mode, label, block_id, ack, tail, flight, message_number, data, text, departing_airport, destination_airport, CAST (latitude AS text), CAST (longitude AS text), altitude, block_end FROM messages

These values never seem to make it into the DB.

thosakwe commented 4 years ago

@thosakwe commented:

Question - does the generated migration file also have decimal? Or float? IIRC I specifically added the DECIMAL casts because the postgres library returned doubles as strings (not sure if it still does this, but didn't want to fix what wasn't broken).

thosakwe commented 4 years ago

@kevinelliott commented:

I don't use the migrations (database is defined elsewhere), so I can't say there. Postgres returns the FLOAT as a number not a string.

thosakwe commented 4 years ago

@kevinelliott commented:

@thosakwe Any further update here?

thosakwe commented 4 years ago

@thosakwe commented:

Sorry, won't be able to do much this week, as I have final exams.

thosakwe commented 4 years ago

@kevinelliott commented:

OK understandable, I will fork and make some kind of correction for myself in the meantime. Thanks.

thosakwe commented 4 years ago

@thosakwe commented:

Feel free to send in a PR if you get it fixed on your end.