forked from denodrivers/mongo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ff72aa4
commit e584633
Showing
10 changed files
with
109 additions
and
54 deletions.
There are no files selected for viewing
This file contains 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 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,3 +1,4 @@ | ||
export { ClientOptions, MongoClient } from "./ts/client.ts"; | ||
export { Database } from "./ts/database.ts"; | ||
export { init } from "./ts/util.ts"; | ||
export const VERSION = "v0.3.0"; |
This file contains 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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
use crate::*; | ||
use bson::Document; | ||
use mongodb::error::Result; | ||
use serde_json::Value; | ||
use util::maybe_json_to_document; | ||
|
||
#[derive(Deserialize, Debug)] | ||
#[serde(rename_all = "camelCase")] | ||
struct FindArgs { | ||
db_name: String, | ||
collection_name: String, | ||
filter: Option<Value>, | ||
find_one: bool, | ||
} | ||
|
||
pub fn find(command: Command) -> CoreOp { | ||
let fut = async move { | ||
let client = command.get_client(); | ||
let data = command.data; | ||
let args: FindArgs = serde_json::from_slice(data.unwrap().as_ref()).unwrap(); | ||
let db_name = args.db_name; | ||
let collection_name = args.collection_name; | ||
let filter = maybe_json_to_document(args.filter); | ||
let database = client.database(&db_name); | ||
let collection = database.collection(&collection_name); | ||
|
||
if args.find_one { | ||
let doc = collection.find_one(filter, None).unwrap(); | ||
Ok(util::async_result(&command.args, doc)) | ||
} else { | ||
let cursor = collection.find(filter, None).unwrap(); | ||
let docs: Vec<Document> = cursor | ||
.filter_map(|doc: Result<Document>| match doc { | ||
Ok(doc) => Some(doc), | ||
_ => None, | ||
}) | ||
.collect(); | ||
Ok(util::async_result(&command.args, docs)) | ||
} | ||
}; | ||
CoreOp::Async(fut.boxed()) | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains 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,13 +1,13 @@ | ||
mod connect; | ||
mod delete; | ||
mod find_one; | ||
mod find; | ||
mod insert; | ||
mod list_collection_names; | ||
mod list_database_names; | ||
|
||
pub use connect::{connect_with_options, connect_with_uri}; | ||
pub use delete::delete; | ||
pub use find_one::find_one; | ||
pub use find::find; | ||
pub use insert::{insert_many, insert_one}; | ||
pub use list_collection_names::list_collection_names; | ||
pub use list_database_names::list_database_names; |
This file contains 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 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 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 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 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