-
Notifications
You must be signed in to change notification settings - Fork 191
RUST-2198 Add run_raw_command method
#1356
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
Merged
Merged
Changes from 6 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
4d0cf4c
raw_run_command
beckerinj eb836e5
implement requested changes
beckerinj 8ac32a9
fix other RunCommand usage in coll.rs
beckerinj 97d1745
add corresponding sync methods
beckerinj 75d5092
undo formatting change
beckerinj 0c948ee
fix "in-use-encryption" feature
beckerinj ea1ed3e
Fix to command.get("readConcern") check
beckerinj 76e29e6
revert formatting change
beckerinj b44dcd0
fix docs
beckerinj 4b9fb66
Add @kevinAlbs test
beckerinj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,6 +1,6 @@ | ||||||
| use std::time::Duration; | ||||||
|
|
||||||
| use bson::{Bson, Document}; | ||||||
| use bson::{Bson, Document, RawDocumentBuf}; | ||||||
|
|
||||||
| use crate::{ | ||||||
| client::session::TransactionState, | ||||||
|
|
@@ -40,7 +40,27 @@ impl Database { | |||||
| pub fn run_command(&self, command: Document) -> RunCommand { | ||||||
| RunCommand { | ||||||
| db: self, | ||||||
| command, | ||||||
| command: RawDocumentBuf::from_document(&command), | ||||||
| options: None, | ||||||
| session: None, | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| /// Runs a database-level command. | ||||||
| /// | ||||||
| /// Note that no inspection is done on `doc`, so the command will not use the database's default | ||||||
| /// read concern or write concern. If specific read concern or write concern is desired, it must | ||||||
| /// be specified manually. | ||||||
| /// Please note that run_command doesn't validate WriteConcerns passed into the body of the | ||||||
beckerinj marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| /// command document. | ||||||
| /// | ||||||
| /// `await` will return d[`Result<Document>`]. | ||||||
| #[deeplink] | ||||||
| #[options_doc(run_command)] | ||||||
| pub fn run_raw_command(&self, command: RawDocumentBuf) -> RunCommand { | ||||||
| RunCommand { | ||||||
| db: self, | ||||||
| command: Ok(command), | ||||||
| options: None, | ||||||
| session: None, | ||||||
| } | ||||||
|
|
@@ -55,7 +75,22 @@ impl Database { | |||||
| pub fn run_cursor_command(&self, command: Document) -> RunCursorCommand { | ||||||
| RunCursorCommand { | ||||||
| db: self, | ||||||
| command, | ||||||
| command: RawDocumentBuf::from_document(&command), | ||||||
| options: None, | ||||||
| session: ImplicitSession, | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| /// Runs a database-level command and returns a cursor to the response. | ||||||
| /// | ||||||
| /// `await` will return d[`Result<Cursor<Document>>`] or a | ||||||
| /// d[`Result<SessionCursor<Document>>`] if a [`ClientSession`] is provided. | ||||||
| #[deeplink] | ||||||
| #[options_doc(run_cursor_command)] | ||||||
| pub fn run_raw_cursor_command(&self, command: RawDocumentBuf) -> RunCursorCommand { | ||||||
| RunCursorCommand { | ||||||
| db: self, | ||||||
| command: Ok(command), | ||||||
| options: None, | ||||||
| session: ImplicitSession, | ||||||
| } | ||||||
|
|
@@ -79,6 +114,21 @@ impl crate::sync::Database { | |||||
| self.async_database.run_command(command) | ||||||
| } | ||||||
|
|
||||||
| /// Runs a database-level command. | ||||||
| /// | ||||||
| /// Note that no inspection is done on `doc`, so the command will not use the database's default | ||||||
| /// read concern or write concern. If specific read concern or write concern is desired, it must | ||||||
| /// be specified manually. | ||||||
| /// Please note that run_command doesn't validate WriteConcerns passed into the body of the | ||||||
beckerinj marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| /// command document. | ||||||
| /// | ||||||
| /// [`run`](RunCommand::run) will return d[`Result<Document>`]. | ||||||
| #[deeplink] | ||||||
| #[options_doc(run_command, sync)] | ||||||
| pub fn run_raw_command(&self, command: RawDocumentBuf) -> RunCommand { | ||||||
beckerinj marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
| self.async_database.run_raw_command(command) | ||||||
| } | ||||||
|
|
||||||
| /// Runs a database-level command and returns a cursor to the response. | ||||||
| /// | ||||||
| /// [`run`](RunCursorCommand::run) will return d[`Result<crate::sync::Cursor<Document>>`] or a | ||||||
|
|
@@ -88,13 +138,23 @@ impl crate::sync::Database { | |||||
| pub fn run_cursor_command(&self, command: Document) -> RunCursorCommand { | ||||||
| self.async_database.run_cursor_command(command) | ||||||
| } | ||||||
|
|
||||||
| /// Runs a database-level command and returns a cursor to the response. | ||||||
| /// | ||||||
| /// [`run`](RunCursorCommand::run) will return d[`Result<crate::sync::Cursor<Document>>`] or a | ||||||
| /// d[`Result<crate::sync::SessionCursor<Document>>`] if a [`ClientSession`] is provided. | ||||||
| #[deeplink] | ||||||
| #[options_doc(run_cursor_command, sync)] | ||||||
| pub fn run_raw_cursor_command(&self, command: RawDocumentBuf) -> RunCursorCommand { | ||||||
| self.async_database.run_raw_cursor_command(command) | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| /// Run a database-level command. Create with [`Database::run_command`]. | ||||||
| #[must_use] | ||||||
| pub struct RunCommand<'a> { | ||||||
| db: &'a Database, | ||||||
| command: Document, | ||||||
| command: bson::raw::Result<RawDocumentBuf>, | ||||||
| options: Option<RunCommandOptions>, | ||||||
| session: Option<&'a mut ClientSession>, | ||||||
| } | ||||||
|
|
@@ -115,10 +175,11 @@ impl<'a> Action for RunCommand<'a> { | |||||
|
|
||||||
| async fn execute(self) -> Result<Document> { | ||||||
| let mut selection_criteria = self.options.and_then(|o| o.selection_criteria); | ||||||
| let command = self.command?; | ||||||
| if let Some(session) = &self.session { | ||||||
| match session.transaction.state { | ||||||
| TransactionState::Starting | TransactionState::InProgress => { | ||||||
| if self.command.contains_key("readConcern") { | ||||||
| if command.get("readConcern").ok().is_some() { | ||||||
|
||||||
| if command.get("readConcern").ok().is_some() { | |
| if command.get("readConcern").is_ok_and(|rc| rc.is_some()) { |
get returns an error if the document is malformed, so this as currently written will evaluate to true for any valid document
Contributor
Author
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.
Got it, made this change 👍
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.