|
2 | 2 |
|
3 | 3 | use std::collections::{HashMap, VecDeque}; |
4 | 4 |
|
5 | | -use crate::bson::{Bson, Document}; |
| 5 | +use crate::{bson::{Bson, Document}, db::options::CreateCollectionOptions}; |
6 | 6 |
|
7 | | -use serde::Serialize; |
| 7 | +use bson::Binary; |
| 8 | +use serde::{Deserialize, Serialize}; |
8 | 9 |
|
9 | 10 | /// The result of a [`Collection::insert_one`](../struct.Collection.html#method.insert_one) |
10 | 11 | /// operation. |
@@ -71,3 +72,77 @@ pub(crate) struct GetMoreResult { |
71 | 72 | pub(crate) batch: VecDeque<Document>, |
72 | 73 | pub(crate) exhausted: bool, |
73 | 74 | } |
| 75 | + |
| 76 | +/// Describes the type of data store returned when executing |
| 77 | +/// [`Database::list_collections`](../struct.Database.html#method.list_collections). |
| 78 | +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] |
| 79 | +#[serde(rename_all = "camelCase")] |
| 80 | +#[non_exhaustive] |
| 81 | +pub enum CollectionType { |
| 82 | + /// Indicates that the data store is a view. |
| 83 | + View, |
| 84 | + |
| 85 | + /// Indicates that the data store is a collection. |
| 86 | + Collection, |
| 87 | +} |
| 88 | + |
| 89 | +/// Info about the collection that is contained in the `CollectionSpecification::info` field of a specification returned from |
| 90 | +/// [`Database::list_collections`](../struct.Database.html#method.list_collections). |
| 91 | +/// |
| 92 | +/// See the MongoDB [manual](https://docs.mongodb.com/manual/reference/command/listCollections/#listCollections.cursor) |
| 93 | +/// for more information. |
| 94 | +#[derive(Debug, Clone, Deserialize, Serialize)] |
| 95 | +#[serde(rename_all = "camelCase")] |
| 96 | +#[non_exhaustive] |
| 97 | +pub struct CollectionSpecificationInfo { |
| 98 | + /// Indicates whether or not the data store is read-only. |
| 99 | + pub read_only: bool, |
| 100 | + |
| 101 | + /// The collection's UUID - once established, this does not change and remains the same across replica |
| 102 | + /// set members and shards in a sharded cluster. If the data store is a view, this field is `None`. |
| 103 | + pub uuid: Option<Binary>, |
| 104 | +} |
| 105 | + |
| 106 | +/// Information about a collection as reported by [`Database::list_collections`](../struct.Database.html#method.list_collections). |
| 107 | +#[derive(Debug, Clone, Deserialize, Serialize)] |
| 108 | +#[serde(rename_all = "camelCase")] |
| 109 | +#[non_exhaustive] |
| 110 | +pub struct CollectionSpecification { |
| 111 | + /// The name of the collection. |
| 112 | + pub name: String, |
| 113 | + |
| 114 | + /// Type of the data store. |
| 115 | + #[serde(rename="type")] |
| 116 | + pub collection_type: CollectionType, |
| 117 | + |
| 118 | + /// The options used to create the collection. |
| 119 | + pub options: CreateCollectionOptions, |
| 120 | + |
| 121 | + /// Additional info pertaining to the collection. |
| 122 | + pub info: CollectionSpecificationInfo, |
| 123 | + |
| 124 | + /// Provides information on the _id index for the collection |
| 125 | + /// For views, this is `None`. |
| 126 | + pub id_index: Option<Document>, |
| 127 | +} |
| 128 | + |
| 129 | +/// A struct modeling the information about an individual database returned from |
| 130 | +/// [`Client::list_databases`](../struct.Client.html#method.list_databases). |
| 131 | +#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)] |
| 132 | +#[serde(rename_all = "camelCase")] |
| 133 | +#[non_exhaustive] |
| 134 | +pub struct DatabaseSpecification { |
| 135 | + /// The name of the database. |
| 136 | + pub name: String, |
| 137 | + |
| 138 | + /// The amount of disk space in bytes that is consumed by the database. |
| 139 | + #[serde(deserialize_with = "crate::bson_util::deserialize_u64_from_bson_number")] |
| 140 | + pub size_on_disk: u64, |
| 141 | + |
| 142 | + /// Whether the database has any data. |
| 143 | + pub empty: bool, |
| 144 | + |
| 145 | + /// For sharded clusters, this field includes a document which maps each shard to the size in bytes of the database |
| 146 | + /// on disk on that shard. For non sharded environments, this field is `None`. |
| 147 | + pub shards: Option<Document>, |
| 148 | +} |
0 commit comments