-
-
Notifications
You must be signed in to change notification settings - Fork 532
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 support for root arrays in JSON in SeaORM #1517
Comments
I also want this, in the mean time this simple workaround works (I use postgres) @a14e : #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, FromJsonQueryResult)]
pub struct IssueTag(pub Vec<IssueTagData>);
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, FromJsonQueryResult)]
pub struct IssueTagData {
pub name: String,
pub time: chrono::DateTime<Utc>
} |
After more careful inspection, it doesn't look to be the same thing. Sorry for the false alarm 😅 |
@billy1624 @tyt2y3 If this is something you guys don't mind supporting, I'd be happy to create a PR. |
…f JsonValue (#1598) * Add Support For PostgreSQL Arrays In FromQueryResult Implementation Of JsonValue * Add support for root arrays in JSON in SeaORM #1517 * Refactoring * Only when `postgres-array` is enabled * Add test cases --------- Co-authored-by: Billy Chan <[email protected]>
@tyt2y3 Are there any plans to implement this? In case more information is required, I normally create these columns with the Json data type in the database. manager
.alter_table(
Table::alter()
.table(Exercise::Table)
.add_column(ColumnDef::new(Exercise::Muscles).json().not_null())
.to_owned(),
)
.await?; |
Yes. A PR would be welcomed. Or we'll see if @darkmmon have the capacity to investigate. |
Could you guide me on what to do? Maybe I can make a PR. |
@IgnisDa I don't want to take away this issue from you, but are you able to proceed? This issue has raised in priority for me so I'd like to create a PR for it if you're unable to. |
@anshap1719 I don't plan working on this soon. I would be glad if you take it up! I can provide feedback on the PR you make. |
@IgnisDa Thanks for confirming. I'll take this up then. |
Update: Although this looked to be a simple change (and it is), there's a conflicting trait implementation that's impossible to get around without changing too much of the code. I'm gonna think more about this, and if I can't see a simple solution without too much refactor, will delegate the decision to one of the maintainers. |
@anshap1719 Thank you for the effort! Can you briefly describe the blockers you are facing? What are the errors? |
@tyt2y3 Basically, we need this more or less:
Even the blanket implementation is enough. But this causes a conflicting trait implementation for
This happens because we also have
|
Thank you for pointing this out. I would say it's unfortunate, because However without negative trait bounds, it means that both features cannot be enabled at the same time. What we wanted is a non-existient trait bound that can allow us to exclude I imagine we have to rework the In the end there will only be one This should be possible, because in the end, the number of sqlx types we want to support are bounded: we only support string (we always cast as text) or integers for enums, and Json for Json. It still require the user to implement |
@tyt2y3 Thanks for that direction. I think I can try that out. We need a |
Thanks, you see, |
@tyt2y3 Yup, I saw the doc comment on why it was needed. Makes sense. Thanks :) |
Lines 153 to 178 in af52e86
Another type shenanigan I just remembered. This basically 'unioned' I think |
…ait For Enums And JSON Array SeaQL#1517
@tyt2y3 An initial implementation is available here now: master...anshap1719:sea-orm:master I've tested this with my project and everything seems to work as expected. Checked against json (and it's array counterpart) as well as enum (and it's array counterpart). Still quite a lot to be done, such as unit tests, documentation and some cleanup (specially around feature configs), but would be great if I could receive an initial feedback on whether or not this is the right direction.
Also, I didn't go into this as it wasn't needed. But let me know if you'd prefer this to be done as well in this PR. Thanks for all your help. |
@anshap1719 I tried your commit. It does not work for me. Is the data type I have selected right? Here is the commit (in |
@IgnisDa I think I'll have to run your project locally to see why. Would that be fine? Do you have a sample db dump for me to use? |
Sure give me a sec. |
@IgnisDa Yeah, sorry about that. I did add tests 2 weeks ago but they were not ready, and also broken. I finally got some time today for this so I've made the PR ready for review and will ensure that tests are passing. |
@anshap1719 sorry for the nudge. When will you be able to get the PR ready? |
I think there is a PR already (or did I rmb wrongly)? But there are some intricate details I need to figure out. |
cool thanks! |
@IgnisDa I think we are pretty close, if you are interested you can check out https://github.com/SeaQL/sea-orm/pull/1898/files and try? |
@tyt2y3 I am not able to figure out how to put this git branch as a dependency. I have: sea-orm = { git = "https://github.com/SeaQL/sea-orm.git", branch = "rework-active-enum", features = [
"debug-print",
"macros",
"runtime-tokio-rustls",
"sqlx-mysql",
"sqlx-postgres",
"sqlx-sqlite",
"with-chrono",
"with-uuid",
"with-rust_decimal",
] } but it complains that Probably because it is a workspace? |
Yes. Try the patch syntax in Cargo.toml [patch.crates-io]
sea_orm = { git = 'https://github.com/SeaQL/sea-orm.git' } https://doc.rust-lang.org/cargo/reference/overriding-dependencies.html#the-patch-section |
@tyt2y3 The patching part is fine, but I am still getting this error: |
@IgnisDa Ah, sorry. Looks like it's the macro that needs to be updated in this case, and not a change that user of the crate should be doing... Please disregard my previous comment. |
Yep i have already made the imports but it doesn't work. |
@tyt2y3 Any updates on what I can do to test the changes you made? |
I guess you also need to patch [patch.crates-io]
sea-orm = { git = 'https://github.com/SeaQL/sea-orm.git' }
sea-orm-macros = { git = 'https://github.com/SeaQL/sea-orm.git' } # perhaps? |
@tyt2y3 Ah, I can't push to it (permission denied). Are you able to grant me push access, or should I create a PR to merge to your branch? |
Yes, you can create a PR targeting this branch.
…________________________________
From: Anshul Sanghi ***@***.***>
Sent: Sunday, October 8, 2023 11:48:03 AM
To: SeaQL/sea-orm ***@***.***>
Cc: Chris Tsang ***@***.***>; Mention ***@***.***>
Subject: Re: [SeaQL/sea-orm] Add support for root arrays in JSON in SeaORM (Issue #1517)
@tyt2y3<https://github.com/tyt2y3> Ah, I can't push to it (permission denied). Are you able to grant me push access, or should I create a PR to merge to your branch?
—
Reply to this email directly, view it on GitHub<#1517 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AANTHCFHTZK2YGPFUHKY7LTX6KAGHAVCNFSM6AAAAAAVMMJN4CVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTONJRHE4TKNJYGU>.
You are receiving this because you were mentioned.Message ID: ***@***.***>
|
@tyt2y3 @anshap1719 I am trying to get this working with |
@IgnisDa Add an attribute for your model field #[sea_orm(column_type = "JsonBinary")]
pub muscles: Vec<MyEnum>, |
@negezor The type in my database is JSON, not JSON Binary. |
@IgnisDa Then it could just be like that, although I haven’t tested it yet. #[sea_orm(column_type = "Json")]
pub muscles: Vec<MyEnum>, |
@negezor Awesome that works! |
Description
Greetings! I've been trying to use jsonb with a root array object in SeaORM, but it appears that the current implementation doesn't support it.
Steps to Reproduce
Expected Behavior
I expect the code to compile without errors.
Actual Behavior
Instead, I encounter the following error:
It would be great if SeaORM could support root array objects in JSON. Thank you for your attention to this matter!
The text was updated successfully, but these errors were encountered: