SeaQL / seaql.github.io

📙 The official website of SeaQL
https://www.sea-ql.org/
Other
19 stars 42 forks source link

[SeaORM docs] clarify PostgreSQL does not support unsigned integers #37

Closed billy1624 closed 2 years ago

billy1624 commented 2 years ago

Motivation

Additional Information

Context

penso commented 2 years ago

To clarify the issue, if you use a u32 as a struct attribute in Model and create your migration with a .unsigned() it fallbacks as integer. When fetching models from the DB those integer will be mapped incorrectly and you'll get:

mismatched types; Rust type core::option::Option<u32> (as SQL type OID) is not compatible with SQL type INT4

My guess is:

  1. Listing converted type per DB type would have helped me finding the issue and I would have seen pgsql doesn't support unsigned integer.
  2. DeriveEntityModel macro should display at least a warning when using u32 since that can't work with a pgsql backend. A clear error when used with pgsql would be even better.
  3. Maybe something that converts that i32 into u32 with warning so you can use u32 as attribute type, noting there might be addressing space issue at conversion but that error could maybe just be returned?
billy1624 commented 2 years ago
  1. Listing converted type per DB type would have helped me finding the issue and I would have seen pgsql doesn't support unsigned integer.

Agree! And, I updated https://www.sea-ql.org/SeaORM/docs/generate-entity/entity-structure/#column-type

  1. DeriveEntityModel macro should display at least a warning when using u32 since that can't work with a pgsql backend. A clear error when used with pgsql would be even better.

This can't be right. At compile-time we don't know for sure which database SeaORM will be connected to.

However, with sea-orm-linter we could catch that logical error at test-time.

CC @tyt2y3 @kirawi