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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
use std::collections::{HashMap, VecDeque};
use crate::{
bson::{Bson, Document},
bson_util,
db::options::CreateCollectionOptions,
};
use bson::Binary;
use serde::{Deserialize, Serialize};
#[derive(Debug, Serialize)]
#[serde(rename_all = "camelCase")]
#[non_exhaustive]
pub struct InsertOneResult {
pub inserted_id: Bson,
}
impl InsertOneResult {
pub(crate) fn from_insert_many_result(result: InsertManyResult) -> Self {
Self {
inserted_id: result.inserted_ids.get(&0).cloned().unwrap_or(Bson::Null),
}
}
}
#[derive(Debug, Serialize)]
#[serde(rename_all = "camelCase")]
#[non_exhaustive]
pub struct InsertManyResult {
pub inserted_ids: HashMap<usize, Bson>,
}
impl InsertManyResult {
pub(crate) fn new() -> Self {
InsertManyResult {
inserted_ids: HashMap::new(),
}
}
}
#[derive(Debug, Serialize)]
#[serde(rename_all = "camelCase")]
#[non_exhaustive]
pub struct UpdateResult {
#[serde(serialize_with = "crate::bson::serde_helpers::serialize_u64_as_i64")]
pub matched_count: u64,
#[serde(serialize_with = "crate::bson::serde_helpers::serialize_u64_as_i64")]
pub modified_count: u64,
pub upserted_id: Option<Bson>,
}
#[derive(Debug, Serialize)]
#[serde(rename_all = "camelCase")]
#[non_exhaustive]
pub struct DeleteResult {
#[serde(serialize_with = "crate::bson::serde_helpers::serialize_u64_as_i64")]
pub deleted_count: u64,
}
#[derive(Debug, Clone, PartialEq)]
#[non_exhaustive]
pub struct CreateIndexResult {
pub index_name: String,
}
#[derive(Debug, Clone, PartialEq)]
#[non_exhaustive]
pub struct CreateIndexesResult {
pub index_names: Vec<String>,
}
impl CreateIndexesResult {
pub(crate) fn into_create_index_result(self) -> CreateIndexResult {
CreateIndexResult {
index_name: self.index_names.into_iter().next().unwrap(),
}
}
}
#[derive(Debug, Clone)]
pub(crate) struct GetMoreResult<T> {
pub(crate) batch: VecDeque<T>,
pub(crate) exhausted: bool,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
#[serde(rename_all = "camelCase")]
#[non_exhaustive]
pub enum CollectionType {
View,
Collection,
}
#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
#[non_exhaustive]
pub struct CollectionSpecificationInfo {
pub read_only: bool,
pub uuid: Option<Binary>,
}
#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
#[non_exhaustive]
pub struct CollectionSpecification {
pub name: String,
#[serde(rename = "type")]
pub collection_type: CollectionType,
pub options: CreateCollectionOptions,
pub info: CollectionSpecificationInfo,
pub id_index: Option<Document>,
}
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
#[serde(rename_all = "camelCase")]
#[non_exhaustive]
pub struct DatabaseSpecification {
pub name: String,
#[serde(
deserialize_with = "bson_util::deserialize_u64_from_bson_number",
serialize_with = "crate::bson::serde_helpers::serialize_u64_as_i64"
)]
pub size_on_disk: u64,
pub empty: bool,
pub shards: Option<Document>,
}