-
-
Notifications
You must be signed in to change notification settings - Fork 520
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add JsonBinary attribute #1346
Add JsonBinary attribute #1346
Conversation
So @billy1624 this seems to work correctly now that Before (compact form) pub struct Model {
#[sea_orm(primary_key)]
pub id: i32,
pub status: Json,
pub payload: Json,
} After (compact form): pub struct Model {
#[sea_orm(primary_key)]
pub id: i32,
#[sea_orm(column_type = "JsonBinary")]
pub status: Json,
#[sea_orm(column_type = "JsonBinary")]
pub payload: Json,
} After (expanded form): #[derive(Clone, Debug, PartialEq, DeriveModel, DeriveActiveModel, Eq, Serialize, Deserialize)]
pub struct Model {
pub id: i32,
pub status: Json,
pub payload: Json,
}
...
#[derive(Copy, Clone, Debug, EnumIter, DerivePrimaryKey)]
pub enum PrimaryKey {
Id,
}
impl PrimaryKeyTrait for PrimaryKey {
type ValueType = i32;
fn auto_increment() -> bool {
true
}
} So as we can see, in the expanded form the attributes aren't added. I don't exactly know how they expand, but in the case above I've included the PrimaryKey as it appears to be the expansion of What would the next steps be to properly add this attribute to the expanded structure? Also, re: tests, I'm not sure where a new one would fit best, and I think that only Postgres has Binary Json, so would the path |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @AngelOnFira, thanks for contributing as always!
For the expanded entity, I think it already handled the JsonBinary
column type.
sea-orm/sea-orm-codegen/src/entity/column.rs
Lines 149 to 150 in bef37c3
ColumnType::Json => quote! { ColumnType::Json }, | |
ColumnType::JsonBinary => quote! { ColumnType::JsonBinary }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, re: tests, I'm not sure where a new one would fit best, and I think that only Postgres has Binary Json, so would the path
sea-orm-codegen/tests/postgres/binary_json.rs
work?
Good call! Yes, please :)
Oh, is this the part of the extended format that covers that? impl ColumnTrait for Column {
type EntityName = Entity;
fn def(&self) -> ColumnDef {
match self {
Self::Id => ColumnType::Integer.def(),
Self::Status => ColumnType::JsonBinary.def(),
Self::Payload => ColumnType::JsonBinary.def(),
}
}
} It does look like it's working now, so I must have had something out of sync when I first thought it was an issue 😅 either way, glad to get the tests wrapped up on this PR 👍 |
b7c3631
to
8aadc9b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @AngelOnFira, thanks for adding test case for the compact entity format. Would it be possible to include a test case for the expanded format as well?
@billy1624 that should be everything :) let me know if any test could be improved! |
df79cbf
to
44d6575
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!! @AngelOnFira Appreciated!
* Add JsonBinary attribute to column * Add Postgres test section, test binary json * Added expanded entity format test * Fixed unit test
PR Info
JsonBinary
field doesn't add attribute to model #1344Notes
Currently, this only seems to work on compact entity structures. As of writing this, I'm unsure on how the attribute should be added in the expanded form, so I'll need some insights on that.
TODO
- Get this to work on expanded entity structure