Replies: 1 comment 2 replies
-
|
Hey @e-rhodes, thanks for the proposal!! I think using bit-vec to represent |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Currently, the SQL type BIT is only partially supported--it's in
sea_query::ColumnType, but it doesn't get generated properly bysea-orm-cliand it doesn't get serialized withinto_json.For a table with a field like this:
seajust generates a "custom" field:Retrieving data with this model fails with the following error:
Changing the rust type to
bool(ifBIT(1)) oru32oru64(for larger numbers of bits) works fine for the model, but silently fails to be converted toserde_json::Valueusinginto_json-- the resultingObjects are simply missing the fields.An example repo to show the problem: https://github.com/e-rhodes/sea-orm-test/tree/bit
What should be done in this case?
Ideally, in my opinion, it would choose between
booloru{x}for the Rust type as appropriate for the number of bits (soBIT(1)->bool,BIT(2-8)=>u8,BIT(9-16)->u16, etc.). Even justbooloru64would be helpful, sinceBIT(1)is likely the most common. Automatically generatingu64but allowing retrieval to aboolafter changing it manually would also be acceptable (similar to the current behavior withTINYINT).The maximum value for the number of bits is 64 in MySQL (source), which means it could always go into a u64, but it doesn't look like there's a limit in postgres, which complicates things (source).
If there isn't a limit for Postgres, then maybe it would have to be
Vec<bool>. ForBITas opposed toBIT VARYING, it would be really cool to generate a fixed array (i.e.BIT(m)->[bool; m]). That way you can just destructure the array without having to check the length in the Rust code when you know it's guaranteed by the database. This might actually be a nicer interface to use thanu64.It doesn't seem like the
column_typeattribute really has an effect. Using the correctsea_query::ColumnType::Bitdoesn't change the output, only changing the Rust type fixes the error:So it seems like it should be left off entirely, but maybe it's helpful? I'm not familiar enough with the inner workings to know.
As for
into_json, the current behavior of silently failing, even when the model would deserialize correctly, is definitely not ideal lol. I think at the very least it should produce an error when it fails to match a type (just simply adding areturn Err()at then end of all thetry_get_type!s inimpl FromQueryResult for JsonValue). Ideally, it would go toValue::BoolorValue::Numberas appropriate (orValue::Array(Vec<Value::Bool>).Beta Was this translation helpful? Give feedback.
All reactions