Skip to main content

ForeignModel

Trait ForeignModel 

Source
pub trait ForeignModel: StoredModel {
    // Required methods
    fn persist_foreign(
        value: Self,
    ) -> impl Future<Output = Result<Self::Stored>> + Send;
    fn hydrate_foreign(
        stored: Self::Stored,
    ) -> impl Future<Output = Result<Self>> + Send;

    // Provided methods
    fn has_foreign_fields() -> bool { ... }
    fn foreign_field_names() -> &'static [&'static str] { ... }
    fn has_relation_fields() -> bool { ... }
    fn relation_field_names() -> &'static [&'static str] { ... }
    fn strip_relation_fields(_row: &mut Value) { ... }
    fn inject_relation_values_from_model(&self, _row: &mut Value) -> Result<()> { ... }
    fn prepare_relation_writes(
        &self,
        _record: RecordId,
    ) -> impl Future<Output = Result<Vec<RelationWrite>>> + Send { ... }
    fn inject_relation_values_from_db(
        _record: RecordId,
        _row: &mut Value,
    ) -> impl Future<Output = Result<()>> + Send { ... }
    fn decode_stored_row(row: Value) -> Result<Self::Stored>
       where Self::Stored: DeserializeOwned { ... }
}
Expand description

Runtime seam for explicit nested #[foreign] persistence and hydration.

Required Methods§

Source

fn persist_foreign( value: Self, ) -> impl Future<Output = Result<Self::Stored>> + Send

Rewrites a caller-facing value into a stored representation where nested refs become record ids.

Source

fn hydrate_foreign( stored: Self::Stored, ) -> impl Future<Output = Result<Self>> + Send

Rehydrates nested refs in a stored representation back into the caller-facing value.

Provided Methods§

Source

fn has_foreign_fields() -> bool

Source

fn foreign_field_names() -> &'static [&'static str]

Names of fields backed by #[foreign].

Source

fn has_relation_fields() -> bool

Whether the model contains any #[relate(...)] fields.

Source

fn relation_field_names() -> &'static [&'static str]

Names of fields backed by #[relate(...)].

Source

fn strip_relation_fields(_row: &mut Value)

Removes relation-backed fields from a serialized row before persistence.

Source

fn inject_relation_values_from_model(&self, _row: &mut Value) -> Result<()>

Injects relation-backed field values from the caller-facing model into a serialized row.

Source

fn prepare_relation_writes( &self, _record: RecordId, ) -> impl Future<Output = Result<Vec<RelationWrite>>> + Send

Prepares ordered relation-table writes for this model value at record.

Source

fn inject_relation_values_from_db( _record: RecordId, _row: &mut Value, ) -> impl Future<Output = Result<()>> + Send

Loads relation-backed field values from edge tables into a serialized row.

Source

fn decode_stored_row(row: Value) -> Result<Self::Stored>
where Self::Stored: DeserializeOwned,

Decodes a raw row returned by SurrealDB into the stored representation for this model.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§