-
Notifications
You must be signed in to change notification settings - Fork 27
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 Working with a document #19
Add Working with a document #19
Conversation
03637e2
to
268e2f9
Compare
I remade my changes. My build for document_url was missing collection name in it |
Actually I don't quite understand why arangoDB offers API on But it is good to fulfill these API. |
I agree with you. I also use AQL myself directly because it gives more freedom/flexibility to do stuff. But when there is no need for it, I used the By the way, do you thimk it is fine with document_base_url ? |
Sure. This is an internal API, and names for them are not that important as long as it is clear enough. |
Ok :) Since we did update develop, should I merge my branch from it or should I continue my work on it ? |
I perfer rebase current branch from develop for two reasons.
|
268e2f9
to
0e8121e
Compare
Well, I made the Rebase and used the awesome cherry-pick . Then i made push force, since it is my own branch, it is ok right ? |
I saw that your doc comments are nice and justified. Did you do it manually or did you use some tool for this ? I am still failing with mmfiles it seems- |
Nightly rustfmt can format doc comment. I use stable by default, but sometimes switch to nightly only to utilize the doc format features in nightly rustfmt. I think this line is to be blamed for. It's wierd, sometimes the server return status Updated: Status 2 means unloaded and 4 denotes unloading, see arango DB doc. I think both 2 and 4 are valid status, and I fixed it in this commit, together with a replacement of the collection.status type from |
Okay, Maybe there is some behavior of ArangoDB that we do not know of. Thank you for your explanations !!!! |
Hello ! the last commit is very much a draft. I have an issue that I do not succeed to solve. When running the test I got this
It seems there is an issue with deserialization/mapping of the error coming from Arangodb. Strangely, I got the document created on my DB: |
db07c4a
to
d8128e3
Compare
…etter typing for building header from it
Well, I am happy about these changes. Thank you a lot for your Inputs, you make me learning so much. I really appreciate it 👍 Anyway, do you think the Also I choose fn make_header_from_options(
document_read_options: DocumentReadOptions,
) -> Option<(http::header::HeaderName, http::header::HeaderValue)> pub fn header<K, V>(self, key: K, value: V) -> Builder
where
HeaderName: TryFrom<K>,
<HeaderName as TryFrom<K>>::Error: Into<crate::Error>,
HeaderValue: TryFrom<V>,
<HeaderValue as TryFrom<V>>::Error: Into<crate::Error>,
{
self.and_then(move |mut head| {
let name = <HeaderName as TryFrom<K>>::try_from(key).map_err(Into::into)?;
let value = <HeaderValue as TryFrom<V>>::try_from(value).map_err(Into::into)?;
head.headers.append(name, value);
Ok(head)
})
} |
I think |
Thank you for your feedback :) I wish /// Gives extra method on the DocumentResponse to quickly check what the server
/// returns
impl<T> DocumentResponse<T> {
/// Should be true when the server send back an empty object {}
pub fn is_silent(&self) -> bool {
match self {
DocumentResponse::Silent => true,
_ => false,
}
}
/// Should be true if there is a response from the server
pub fn has_response(&self) -> bool {
match self {
DocumentResponse::Response { .. } => true,
_ => false,
}
}
/// Should give None or Some(Response)
pub fn get_response(self) -> Option<OperationResponse<T>> {
if let DocumentResponse::Response {
header,
old,
new,
_old_rev,
} = self
{
Some(OperationResponse {
header,
old,
new,
_old_rev,
})
} else {
None
}
}
}
Is there a way I can return these values without a struct ? |
377e389
to
730412d
Compare
I see, the only usage of What about removing PS: Rustacean tend to use field name for getter and |
Okay, I try to deserialize into |
Haa nice catch ! I am gonna try it :) PS : my last commit is not this clean, I got some style/format stuff in it. Sorry about that. |
… updated unit test
I learned how to use the |
Yes ! You are right. I do not know why, I thought I had to keep it because I was having error, but in fact it was because of something else. I just removed and the tests still pass correctly. |
{ | ||
let mut obj = serde_json::Value::deserialize(deserializer)?; | ||
|
||
let json = obj.as_object_mut().unwrap(); |
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.
unwrap
might be fine, but I think a better way to handle this error is to map error to serde json's error type.
Here is a minimal example for proof of concept:
let json = obj.as_object_mut().map_err(|_| de::Error::invalid_type(Unexpected::Other("not object"), &self))?;
json.remove("_id").map_err(|_| de::Error::missing_filed("_id"))?;
Yeah, right about the variant. I just removed it. For the error handling, there is no |
My mistake. let json = obj.as_object_mut().ok_or(de::Error::invalid_type(Unexpected::Other("not object"), &self))?; |
Well, we do not have Do you think we should go this far for this case ? |
I think no. My point is to raise a |
Well, I am sorry but I do not succeed to raise Error with any kind of good code. For example this break let json_result = obj.as_object_mut().ok_or(de::Error::custom);
if json_result.is_err() {
json_result <--- break there
};
let json = json_result.unwrap(); <--- break there I do not understand how I made this code compile but I do not succeed to test it let mut obj = serde_json::Value::deserialize(deserializer)?;
let json_result = obj.as_object_mut();
if json_result.is_none() {
eprintln!(" DESERIALIZATION FAILED");
return Err(de::Error::custom(
"DocumentResponse deserialization has failed",
));
} I think I am missing the point because I am a bit lost on how to manage error properly there. |
Thank you for the merge by the way :) |
Thank you for your great great work! I can't believe we have come so far. You can refer to the latest commit in I copy it here: fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
let mut obj = serde_json::Value::deserialize(deserializer)?;
let json = obj
.as_object_mut()
.ok_or(DeError::custom("should be a json object"))?;
if json.is_empty() {
Ok(DocumentResponse::Silent)
} else {
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: DocumentHeader = DocumentHeader {
_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)?,
};
let old = json
.remove("old")
.map(T::deserialize)
.transpose()
.map_err(DeError::custom)?;
let new = json
.remove("new")
.map(T::deserialize)
.transpose()
.map_err(DeError::custom)?;
let _old_rev = json.remove("_old_rev").map(|v| v.to_string());
Ok(DocumentResponse::Response {
header,
old,
new,
_old_rev,
})
}
} |
Thank you !!! The code is beautiful 👍 let json = obj
.as_object_mut()
.ok_or(DeError::custom("should be a json object"))?; Arf, why I did not think about that lol. So simple :P Thank you a lot for your guidance. |
You are welcome~ :) Thank you so much! Would you like to add some examples on document operation? |
:) Yeah sure ! |
Hey ! Let's implement from the Arangodb documentation -> Working with a Document
read a single document
read document header
create document
replace document
update document
removes a document
From our work on documents we saw the need for updating some of the existing code regarding request and response. Therefore the todolist for this PR gets also updated
update how we do request to the server to have more flexibility for adding headers and other options on a request
update how we handle response from the server
Same as previously, each item is implemented with code and unit test :)
I see that I got some previous commits. No worries. I ll hard push on my branch later when stuff will be ready.
Let's go !