drizzle-core 0.1.9

A type-safe SQL query builder for Rust
Documentation
//! `QueryRow<Base, Store>` — wrapper for a row with relation data.

use core::ops::Deref;

/// A query result row that wraps a base select model with optional relation data.
///
/// Users access base fields via `Deref` (transparent) and relation data
/// via extension trait methods generated by the table macro.
#[derive(Debug, Clone)]
pub struct QueryRow<Base, Store = ()> {
    base: Base,
    #[doc(hidden)]
    pub store: Store,
}

impl<Base, Store> QueryRow<Base, Store> {
    /// Creates a new `QueryRow` with the given base model and relation store.
    pub const fn new(base: Base, store: Store) -> Self {
        Self { base, store }
    }

    /// Returns a reference to the base model.
    pub const fn base(&self) -> &Base {
        &self.base
    }

    /// Consumes the `QueryRow` and returns the base model and store.
    pub fn into_parts(self) -> (Base, Store) {
        (self.base, self.store)
    }
}

impl<Base, Store> Deref for QueryRow<Base, Store> {
    type Target = Base;

    fn deref(&self) -> &Base {
        &self.base
    }
}