Skip to main content

vantage_mongodb/select/
mod.rs

1//! MongoDB SELECT (find) query builder.
2//!
3//! Accumulates collection name, field projection, filter conditions, sort,
4//! limit/skip — all as native MongoDB types. Implements
5//! `Selectable<AnyMongoType, MongoCondition>` so `table.select()` works.
6
7pub mod builder;
8pub mod impls;
9pub mod pipeline;
10pub mod render;
11
12use crate::condition::MongoCondition;
13
14/// MongoDB query builder — the equivalent of `SqliteSelect` / `SurrealSelect`.
15///
16/// Instead of rendering SQL, it accumulates native `bson::Document` parts
17/// that map directly onto the `mongodb` driver's find/aggregate API.
18#[derive(Debug, Clone, Default)]
19pub struct MongoSelect {
20    /// Collection name (equivalent to FROM).
21    pub collection: Option<String>,
22    /// Field names to include in projection. Empty = all fields.
23    pub fields: Vec<String>,
24    /// Filter conditions (combined with $and at resolve time).
25    pub conditions: Vec<MongoCondition>,
26    /// Sort specification: field name → 1 (asc) or -1 (desc).
27    pub sort: Vec<(String, i32)>,
28    /// GROUP BY fields (for aggregation pipeline).
29    pub group_by: Vec<String>,
30    /// Whether to return distinct results.
31    pub distinct: bool,
32    /// Max number of documents to return.
33    pub limit: Option<i64>,
34    /// Number of documents to skip.
35    pub skip: Option<i64>,
36}
37
38impl MongoSelect {
39    pub fn new() -> Self {
40        Self::default()
41    }
42}