-
Notifications
You must be signed in to change notification settings - Fork 30
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
Remove header from document #36
Comments
You can put the for aragog I use the header to allow the user to wrap its document in a |
@EpiFouloux I think it's a difference talking from the perspective of As I personally don't use any ODM, I'm handling with the driver directly. Which means that my structures require the definition of Does that make sense? |
Yeah, I guess it does and it doesn't change anything for me. |
@EpiFouloux I would leave that as an exercise to the user of If you were to use AQL queries (instead of direct document access / insert), you were required to handle this case anyway, as Just assuming that I have:
that would not deserialize So what it comes down to:
That's inconsistent in my opinion. I've been working with AQL queries mostly, and it does the job, feels nice, no conversion required (except the handling of |
I did not notice that there was this inconstency while I did implement |
@EpiFouloux Just as a quick update. Assuming I created a struct like this:
I could use that structure (and I currently do use it in a similar form) with I think I can perfectly well live without the restructuring of the direct document access and removal of header. But as I realized the above 'issue', I thought I'd bring it up here, as it might result in a cleaner concept in the driver itself. |
When Edit: Also why not use a wrapper for that? why don't you use a ODM? |
@EpiFouloux I will paste a sample, just to make sure we talk about the same thing:
This will lead to: So no. They are deserialized into the header. If I change the struct
everything works fine. |
Yeah that's what I was talking about and indeed it's a bit weird, the |
Hey @inzanez I can make a pull request for this if you are not already doing one |
Hey guys ! Thank you for your messages 😃 . I think it is me who wrote the I wrote the API by using the official documentation and source code in the Python & Typescript version of the driver. Can you explain me shortly what is wrong with what we have ? |
@arn-the-long-beard Well, I don't really want to talk about 'right' and 'wrong' here, as it's not that simple. I see that also the Golang driver does the same thing we have here. Still, I ask whether or not that's good choice. Basically we have the following situation:
So either one is supposed to always deserialize to @EpiFouloux No, I haven't started on anything yet. |
Quick addition: Another option would be to implement Deref and DerefMut for Document. This would be convenient as it would allow for things like this:
Without the Deref, one could not work directly on And if this is the way to go, it might make sense to update the documentation to always use the |
Thank you for your message 👍 Okay, well my brain is not fresh on But I remember that @fMeow talked about the possibility to have something similar like this :
I did not know how to make this happen that is why it is missing also. Can you explain me this part ? Anyway, I think you are very welcomed make it happen 👍 PS : you posted a new message . I do not have the knowledge for |
@arn-the-long-beard Well, I guess I would wait for @EpiFouloux as he's working on a proposal. But in general, it would be similar to what the current AQL query interface does. It would not deserialize the response to As an example:
This would return a Regarding Deref/DerefMut: This would allow for automatic dereferencing so that working on a |
@inzanez That is exactly what my proposal is, I'll make a pull request soon. |
@EpiFouloux Which one? Deref/DerefMut or removing the document struct? |
Removing the document struct: https://github.com/EpiFouloux/arangors/commit/f03492bde18d0e6e135c0aa83b8c3a30bb355f3b Though I don't remove I don't know if @inzanez proposition for |
Yes please, do not remove Document Response 🙂 I made it according to the
official documentation and I find it very usefull. Good luck. I will still
follow so I can help if needed 😉
Le ven. 9 oct. 2020 à 17:24, Félix Lescaudey de Maneville <
[email protected]> a écrit :
… Removing the document struct: ***@***.***
<EpiFouloux/arangors@f03492b>
Though I don't remove DocumentResponse since it can be silent I do remove
its Header. I still have to work on the tests before making a pull
request.
I don't know if @inzanez <https://github.com/inzanez> proposition for
Deref/DerefMut is ideal since I never worked with this
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#36 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AHFYCCNERIA4FH67HURKEZ3SJ4TMVANCNFSM4RUH2VGQ>
.
|
Sorry for the long wait. Personally speaking, I think When creating data structure, I don't want to mingle it with database stuff like When come into serialization and deserialization, Let me give an example: struct User{
field1: bool
//more useful field ...
} // let's pretend we got a working User
let u =User::default();
// You can create a new document with doc and do not need to care about id, key and rev. They are skipped when serializing cause they are empty
let doc =Document::new(u);
// If you don't want to move, you can use a reference to create doc
let doc = Document::new(&u);
// When you need header
let x: Document<User> = col.document("100000").unwrap()
let u:Document<User> = db.aql_str("FOR u in users RETURN u");
// When you don't care about header
let u: User = db.aql_str("FOR u in users RETURN u"); The point is that, NEVER embed _id, _key and _rev in your own data structure, and use 'Document' when you need it. |
@fMeow Ok, that's definitely a valid choice, as I already pointed out above. But I think it would make sense to emphasize that in the doucmentation / Readme as a core concept? So that it's clear that the user is supposed to use the On the other hand, I still see some inconveniences floating around. Assuming you retrieved something as follows:
Of course, that function could be accepting |
Yes, I should emphasize this in readme/doc since it is a hidden breaking change. So bad I didn't come up with It is possible to change the signature of As for the user function to handle But that's not enough. Some times we do something complicated with the data structure, and finally need to update the doc. In this case, a not so good solution is to use Another solution is to keep data in let users: Vec<Document<User>> = db.aql_str("FOR u in users RETURN u");
user_magic(users.iter().map(|u| &u.document).collect::<Vec<&T>>()); The conversion can be facilitate with a handy function implemented in To summarize, I am reluctant to change the signature of document retrieval related function from
Is this solution sound acceptable to you? |
Just as an idea: couldn‘t you just leave the Or is there a drawback I dont see? I think this would not force any of the two concepts on anyone and give users of arangors the most freedom of choice. And existing code would not need to be adapted very much. Would that be a viable option too? |
One addition to @fMeow proposition would be to stop deleting |
@EpiFouloux I think they ( |
@inzanez From what I see in the source let _id = json.remove("_id").ok_or(DeError::missing_field("_id"))?;
let _key = json.remove("_key").ok_or(DeError::missing_field("_key"))?;
let _rev = json.remove("_rev").ok_or(DeError::missing_field("_rev"))?;
let header: Header = Header {
_id: serde_json::from_value(_id).map_err(DeError::custom)?,
_key: serde_json::from_value(_key).map_err(DeError::custom)?,
_rev: serde_json::from_value(_rev).map_err(DeError::custom)?,
}; It seems they are explicitely deleted from the json |
Oh, that‘s interesting. Well, but we would still have a deserialization to Document. Which would need to be unpacked... |
Now I manually deserialize |
But that still forces a user to unpack that Document,...couldn‘t that be optional? Or maybe add a second kind of functions on the collection that allows to use the functionality without using the Document struct? |
I am considering a more OOP liked design for document, like |
Could you not define a trait that exposed key, accept impl trait instead of Document struct, and just implement the trait for the internal Document type? |
Hi
does it really make sense to have the
Header
included in theDocument<T>
structure? Wouldn't it make more sense to let the user of the driver decide whether or not that part of the response is going to be deserialized? Simply by including the header properties (merged or not) in the structT
?I currently use AQL queries all over the place, and this works quite well as it just serializes/deserializes
T
. So I get my headers automatically, and I can send them along to the client.If I were to use the document level driver functions instead, I would have to copy the deserialized header parts over to my
T
if I needed them. And as far as I can tell, the Arango driver never actually uses theHeader
structure. So it should be safe to remove theHeader
fields and just deserialize toT
.The text was updated successfully, but these errors were encountered: