-
Notifications
You must be signed in to change notification settings - Fork 178
RUST-740 Return Deserialize structs from list_databases and list_collections #328
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
Changes from all commits
636e1ae
af174da
4ff67dc
8959a04
8a036b9
48fa073
7163d85
8a5b787
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,7 +29,7 @@ pub struct DatabaseOptions { | |
/// These are the valid options for creating a collection with | ||
/// [`Database::create_collection`](../struct.Database.html#method.create_collection). | ||
#[skip_serializing_none] | ||
#[derive(Debug, Default, TypedBuilder, Serialize)] | ||
#[derive(Clone, Debug, Default, TypedBuilder, Serialize, Deserialize)] | ||
#[serde(rename_all = "camelCase")] | ||
#[builder(field_defaults(default, setter(strip_option)))] | ||
#[non_exhaustive] | ||
|
@@ -55,8 +55,7 @@ pub struct CreateCollectionOptions { | |
/// Specifies a validator to restrict the schema of documents which can exist in the | ||
/// collection. Expressions can be specified using any query operators except `$near`, | ||
/// `$nearSphere`, `$text`, and `$where`. | ||
#[serde(rename = "validator")] | ||
pub validation: Option<Document>, | ||
pub validator: Option<Document>, | ||
|
||
/// Specifies how strictly the database should apply the validation rules to existing documents | ||
/// during an update. | ||
|
@@ -86,7 +85,7 @@ pub struct CreateCollectionOptions { | |
|
||
/// Specifies how strictly the database should apply validation rules to existing documents during | ||
/// an update. | ||
#[derive(Debug, Serialize)] | ||
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] | ||
#[serde(rename_all = "camelCase")] | ||
#[non_exhaustive] | ||
pub enum ValidationLevel { | ||
|
@@ -101,7 +100,7 @@ pub enum ValidationLevel { | |
|
||
/// Specifies whether the database should return an error or simply raise a warning if inserted | ||
/// documents do not pass the validation. | ||
#[derive(Debug, Serialize)] | ||
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] | ||
#[serde(rename_all = "camelCase")] | ||
#[non_exhaustive] | ||
pub enum ValidationAction { | ||
|
@@ -112,8 +111,9 @@ pub enum ValidationAction { | |
} | ||
|
||
/// Specifies default configuration for indexes created on a collection, including the _id index. | ||
#[derive(Clone, Debug, PartialEq, Serialize)] | ||
#[derive(Clone, Debug, TypedBuilder, PartialEq, Serialize, Deserialize)] | ||
#[serde(rename_all = "camelCase")] | ||
#[non_exhaustive] | ||
pub struct IndexOptionDefaults { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This struct was missing a few attributes so I added them. I don't think any of our users will use this though. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TIL (I guess we do support it in Swift, so I knew this at some point, but we just take in a document so it was easier to forget about it than if it had a concrete type) |
||
/// The `storageEngine` document should be in the following form: | ||
/// | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -85,5 +85,4 @@ impl Operation for ListDatabases { | |
#[derive(Debug, Deserialize)] | ||
struct ResponseBody { | ||
databases: Vec<Document>, | ||
total_size: Option<i64>, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This wasn't being used and in fact wasn't even being deserialized, since the server returned this value as a double until 5.0. |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,9 +2,10 @@ | |
|
||
use std::collections::{HashMap, VecDeque}; | ||
|
||
use crate::bson::{Bson, Document}; | ||
use crate::{bson::{Bson, Document}, db::options::CreateCollectionOptions}; | ||
|
||
use serde::Serialize; | ||
use bson::Binary; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
/// The result of a [`Collection::insert_one`](../struct.Collection.html#method.insert_one) | ||
/// operation. | ||
|
@@ -71,3 +72,77 @@ pub(crate) struct GetMoreResult { | |
pub(crate) batch: VecDeque<Document>, | ||
pub(crate) exhausted: bool, | ||
} | ||
|
||
/// Describes the type of data store returned when executing | ||
/// [`Database::list_collections`](../struct.Database.html#method.list_collections). | ||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] | ||
#[serde(rename_all = "camelCase")] | ||
#[non_exhaustive] | ||
pub enum CollectionType { | ||
/// Indicates that the data store is a view. | ||
View, | ||
|
||
/// Indicates that the data store is a collection. | ||
Collection, | ||
} | ||
|
||
/// Info about the collection that is contained in the `CollectionSpecification::info` field of a specification returned from | ||
/// [`Database::list_collections`](../struct.Database.html#method.list_collections). | ||
/// | ||
/// See the MongoDB [manual](https://docs.mongodb.com/manual/reference/command/listCollections/#listCollections.cursor) | ||
/// for more information. | ||
#[derive(Debug, Clone, Deserialize, Serialize)] | ||
#[serde(rename_all = "camelCase")] | ||
#[non_exhaustive] | ||
pub struct CollectionSpecificationInfo { | ||
/// Indicates whether or not the data store is read-only. | ||
pub read_only: bool, | ||
|
||
/// The collection's UUID - once established, this does not change and remains the same across replica | ||
/// set members and shards in a sharded cluster. If the data store is a view, this field is `None`. | ||
pub uuid: Option<Binary>, | ||
} | ||
|
||
/// Information about a collection as reported by [`Database::list_collections`](../struct.Database.html#method.list_collections). | ||
#[derive(Debug, Clone, Deserialize, Serialize)] | ||
#[serde(rename_all = "camelCase")] | ||
#[non_exhaustive] | ||
pub struct CollectionSpecification { | ||
/// The name of the collection. | ||
pub name: String, | ||
|
||
/// Type of the data store. | ||
#[serde(rename="type")] | ||
pub collection_type: CollectionType, | ||
|
||
/// The options used to create the collection. | ||
pub options: CreateCollectionOptions, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought about creating a separate type for this in case they ever diverge (and also because it contains fields like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree it seems low risk There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sgtm |
||
|
||
/// Additional info pertaining to the collection. | ||
pub info: CollectionSpecificationInfo, | ||
|
||
/// Provides information on the _id index for the collection | ||
/// For views, this is `None`. | ||
pub id_index: Option<Document>, | ||
} | ||
|
||
/// A struct modeling the information about an individual database returned from | ||
/// [`Client::list_databases`](../struct.Client.html#method.list_databases). | ||
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)] | ||
#[serde(rename_all = "camelCase")] | ||
#[non_exhaustive] | ||
pub struct DatabaseSpecification { | ||
/// The name of the database. | ||
pub name: String, | ||
|
||
/// The amount of disk space in bytes that is consumed by the database. | ||
#[serde(deserialize_with = "crate::bson_util::deserialize_u64_from_bson_number")] | ||
pub size_on_disk: u64, | ||
|
||
/// Whether the database has any data. | ||
pub empty: bool, | ||
|
||
/// For sharded clusters, this field includes a document which maps each shard to the size in bytes of the database | ||
/// on disk on that shard. For non sharded environments, this field is `None`. | ||
pub shards: Option<Document>, | ||
} |
Uh oh!
There was an error while loading. Please reload this page.