doido-model 0.1.0

SeaORM re-exports plus connection pooling and model testing helpers for Doido apps.
Documentation
//! Named, chainable query scopes (Rails `scope :published, -> { where(...) }`).
//!
//! A scope is any query transformation `FnOnce(Select<E>) -> Select<E>` — a free
//! function or a closure. [`Scoped`] lets them chain fluently off a sea-orm
//! `Select`, e.g. `Entity::find().scope(published).scope(recent)`.

use sea_orm::{EntityTrait, Select};

/// Fluent application of named scopes to a query.
pub trait Scoped: Sized {
    /// Apply a scope (a query transformation).
    fn scope(self, transform: impl FnOnce(Self) -> Self) -> Self {
        transform(self)
    }

    /// Apply a scope only when `condition` holds (Rails conditional scope).
    fn scope_if(self, condition: bool, transform: impl FnOnce(Self) -> Self) -> Self {
        if condition {
            transform(self)
        } else {
            self
        }
    }
}

impl<E: EntityTrait> Scoped for Select<E> {}