Skip to main content

Mode

Enum Mode 

Source
pub enum Mode {
    Find,
    TwoPhase,
    Aggregate,
}
Expand description

读路径形态:决定 Host 如何执行命令序列

Variants§

§

Find

纯 $match → 走 find 快路径

§

TwoPhase

$lookup + 分页 → 两阶段(先取 ID 再关联)

§

Aggregate

标准单阶段聚合

Implementations§

Source§

impl Mode

Source

pub fn as_str(self) -> &'static str

Examples found in repository?
examples/quickstart.rs (line 39)
14fn main() -> Result<(), String> {
15    // 1. A model is plain JSON — defined once, usable against every backend.
16    let mut registry = Registry::new();
17    registry.register(&json!({
18        "name": "Post",
19        "collection": "posts",
20        "timestamps": true,
21        "fields": {
22            "title":  { "type": "string" },
23            "status": { "type": "string", "default": "draft" },
24            "views":  { "type": "int" }
25        },
26        "relations": {}
27    }))?;
28
29    // 2. GQL in, MongoDB command JSON out. Values are referenced by `@key`.
30    let gql = "Post($condition:@c0,$sort:@s1,$limit:@l0){title, status, views}";
31    let mut params = Map::new();
32    params.insert("c0".to_string(), json!({ "status": "published" }));
33    params.insert("s1".to_string(), json!({ "views": -1 }));
34    params.insert("l0".to_string(), json!(20));
35
36    let plan = plan_query(gql, &params, &registry, None)?;
37
38    println!("collection = {}", plan.collection);
39    println!("mode       = {}", plan.mode.as_str());
40
41    for cmd in &plan.commands {
42        println!("command    = {}", serde_json::to_string(cmd).unwrap());
43
44        // 3. The host runs `cmd` against MongoDB — or, for a SQL backend, asks the
45        //    core for parameterized SQL and binds it with its own driver.
46        let sql = translate(Backend::Postgres, cmd, &registry)?;
47        println!("sql        = {}", serde_json::to_string(&sql).unwrap());
48    }
49
50    Ok(())
51}

Trait Implementations§

Source§

impl Clone for Mode

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Mode

Source§

impl Debug for Mode

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Mode

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Mode

Auto Trait Implementations§

§

impl Freeze for Mode

§

impl RefUnwindSafe for Mode

§

impl Send for Mode

§

impl Sync for Mode

§

impl Unpin for Mode

§

impl UnsafeUnpin for Mode

§

impl UnwindSafe for Mode

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.