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(crate) mod join;
10pub mod pipeline;
11pub mod render;
12
13use crate::condition::MongoCondition;
14
15pub(crate) use join::{JoinColumn, JoinHop, join_alias};
16
17/// MongoDB query builder — the equivalent of `SqliteSelect` / `SurrealSelect`.
18///
19/// Instead of rendering SQL, it accumulates native `bson::Document` parts
20/// that map directly onto the `mongodb` driver's find/aggregate API.
21///
22/// A select built from a typed table (`table.select()`) carries the table's
23/// joined (dotted) columns as plain field names: running it through
24/// `execute_select` does not lower them into `$lookup` stages. Reads through
25/// the table (`list_values` and friends) and through a Vista do.
26#[derive(Debug, Clone, Default)]
27#[non_exhaustive]
28pub struct MongoSelect {
29 /// Collection name (equivalent to FROM).
30 pub collection: Option<String>,
31 /// Aggregation stages that run before the filter. Non-empty makes every
32 /// read an `aggregate` over their output instead of a `find`.
33 pub(crate) pre_stages: Vec<bson::Document>,
34 /// Dotted columns read through `$lookup` stages; see the `join` module.
35 /// Non-empty makes every read an `aggregate`.
36 pub(crate) joins: Vec<JoinColumn>,
37 /// Field names to include in projection. Empty = all fields.
38 pub fields: Vec<String>,
39 /// Filter conditions (combined with $and at resolve time).
40 pub conditions: Vec<MongoCondition>,
41 /// Sort specification: field name → 1 (asc) or -1 (desc).
42 pub sort: Vec<(String, i32)>,
43 /// GROUP BY fields (for aggregation pipeline).
44 pub group_by: Vec<String>,
45 /// Whether to return distinct results.
46 pub distinct: bool,
47 /// Max number of documents to return.
48 pub limit: Option<i64>,
49 /// Number of documents to skip.
50 pub skip: Option<i64>,
51}
52
53impl MongoSelect {
54 pub fn new() -> Self {
55 Self::default()
56 }
57}