prax_mongodb/lib.rs
1//! # prax-mongodb
2//!
3//! MongoDB driver for the Prax ORM with document mapping and aggregation support.
4//!
5//! This crate provides:
6//! - Connection management with the official MongoDB driver
7//! - Built-in connection pooling
8//! - Document serialization/deserialization via BSON
9//! - Type-safe query building
10//! - Aggregation pipeline support
11//! - Change streams for real-time updates
12//!
13//! ## Example
14//!
15//! ```rust,ignore
16//! use prax_mongodb::MongoClient;
17//!
18//! #[tokio::main]
19//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
20//! // Create a client (connection pooling is built-in)
21//! let client = MongoClient::builder()
22//! .uri("mongodb://localhost:27017")
23//! .database("mydb")
24//! .build()
25//! .await?;
26//!
27//! // Get a collection
28//! let users = client.collection::<User>("users");
29//!
30//! // Insert a document
31//! users.insert_one(User { name: "Alice".into(), age: 30 }).await?;
32//!
33//! Ok(())
34//! }
35//! ```
36//!
37//! ## Document Mapping
38//!
39//! Models can be mapped to MongoDB documents using serde:
40//!
41//! ```rust,ignore
42//! use serde::{Deserialize, Serialize};
43//! use prax_mongodb::ObjectId;
44//!
45//! #[derive(Debug, Serialize, Deserialize)]
46//! struct User {
47//! #[serde(rename = "_id", skip_serializing_if = "Option::is_none")]
48//! id: Option<ObjectId>,
49//! name: String,
50//! email: String,
51//! }
52//! ```
53
54pub mod client;
55pub mod config;
56pub mod document;
57pub mod engine;
58pub mod error;
59pub mod filter;
60pub mod types;
61pub mod view;
62
63pub use bson::oid::ObjectId;
64pub use bson::{Bson, Document, doc};
65pub use client::{MongoClient, MongoClientBuilder};
66pub use config::{MongoConfig, MongoConfigBuilder};
67pub use engine::MongoEngine;
68pub use error::{MongoError, MongoResult};
69pub use filter::FilterBuilder;
70pub use view::{
71 AggregationView, AggregationViewBuilder, MaterializedAggregationView, MergeAction,
72 MergeNotMatchedAction, MergeOptions,
73};
74
75/// Prelude for convenient imports.
76pub mod prelude {
77 pub use crate::client::{MongoClient, MongoClientBuilder};
78 pub use crate::config::{MongoConfig, MongoConfigBuilder};
79 pub use crate::document::DocumentExt;
80 pub use crate::engine::MongoEngine;
81 pub use crate::error::{MongoError, MongoResult};
82 pub use crate::filter::FilterBuilder;
83 pub use crate::view::{
84 AggregationView, AggregationViewBuilder, MaterializedAggregationView, MergeAction,
85 MergeNotMatchedAction, MergeOptions, accumulators, stages,
86 };
87 pub use bson::oid::ObjectId;
88 pub use bson::{Bson, Document, doc};
89}