-
Notifications
You must be signed in to change notification settings - Fork 176
/
Copy pathdrop_collection.rs
72 lines (60 loc) · 1.74 KB
/
drop_collection.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
use bson::rawdoc;
use crate::{
cmap::{Command, RawCommandResponse, StreamDescription},
error::{Error, Result},
operation::{
append_options_to_raw_document,
remove_empty_write_concern,
OperationWithDefaults,
WriteConcernOnlyBody,
},
options::{DropCollectionOptions, WriteConcern},
Namespace,
};
use super::ExecutionContext;
#[derive(Debug)]
pub(crate) struct DropCollection {
ns: Namespace,
options: Option<DropCollectionOptions>,
}
impl DropCollection {
pub(crate) fn new(ns: Namespace, options: Option<DropCollectionOptions>) -> Self {
DropCollection { ns, options }
}
}
impl OperationWithDefaults for DropCollection {
type O = ();
const NAME: &'static str = "drop";
fn build(&mut self, _description: &StreamDescription) -> Result<Command> {
let mut body = rawdoc! {
Self::NAME: self.ns.coll.clone(),
};
remove_empty_write_concern!(self.options);
append_options_to_raw_document(&mut body, self.options.as_ref())?;
Ok(Command::new(
Self::NAME.to_string(),
self.ns.db.clone(),
body,
))
}
fn handle_response<'a>(
&'a self,
response: RawCommandResponse,
_context: ExecutionContext<'a>,
) -> Result<Self::O> {
let response: WriteConcernOnlyBody = response.body()?;
response.validate()
}
fn handle_error(&self, error: Error) -> Result<Self::O> {
if error.is_ns_not_found() {
Ok(())
} else {
Err(error)
}
}
fn write_concern(&self) -> Option<&WriteConcern> {
self.options
.as_ref()
.and_then(|opts| opts.write_concern.as_ref())
}
}