Skip to main content

RelationDataSource

Struct RelationDataSource 

Source
pub struct RelationDataSource { /* private fields */ }
Expand description

关联数据源

提供按外键查找关联数据的能力,用于解析嵌套字段

Implementations§

Source§

impl RelationDataSource

Source

pub fn new() -> Self

Source

pub fn insert(&self, type_name: &str, doc: Value)

插入文档到指定类型

Source

pub fn insert_many(&self, type_name: &str, docs: Vec<Value>)

批量插入文档

Source

pub fn get_all(&self, type_name: &str) -> Vec<Value>

获取指定类型的所有文档

Source

pub fn find_by_id(&self, type_name: &str, id: &str) -> Option<Value>

按 ID 查找文档

Source

pub fn add_relation(&self, relation: Relation)

添加关联关系

Source

pub fn resolve_one_to_many( &self, from_type: &str, from_field: &str, parent_id: &str, ) -> Vec<Value>

解析一对多关联:返回 from_type 中外键等于 to_type 主键的文档列表

例如:User -> Orders,查找 order.user_id == user.id 的 orders

Source

pub fn resolve_many_to_one( &self, to_type: &str, to_field: &str, foreign_key: &str, ) -> Option<Value>

解析多对一关联:返回 to_type 中主键等于 from_type 外键的文档

例如:Order -> User,查找 user.id == order.user_id 的 user

Trait Implementations§

Source§

impl Default for RelationDataSource

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.