Skip to main content

RepositoryOptions

Struct RepositoryOptions 

Source
pub struct RepositoryOptions<U = NoUser>
where U: BaseEntity + Clone + Send + Sync + 'static,
{ pub limit: usize, pub cursor: Option<String>, pub distinct: bool, pub detach: bool, pub user: Option<U>, pub user_id: Option<i64>, pub correlation: Option<Arc<CorrelationContext>>, pub txn: Option<Arc<DatabaseTransaction>>, }
Expand description

Per-request settings for repository queries.

U is the caller identity type and must implement BaseEntity; it defaults to NoUser. An identity can be supplied either as a full entity (user) or as a raw id (user_id).

An optional database transaction can be attached via RepositoryOptions::with_transaction. When present, repository operations run against that transaction; otherwise they use the repository’s own connection.

Fields§

§limit: usize

Maximum rows for limited reads; default is 15.

§cursor: Option<String>

Opaque cursor from a previous page, if continuing pagination.

§distinct: bool

Whether selects use SELECT DISTINCT.

§detach: bool

Detach flag carried alongside the query; default is true.

§user: Option<U>

Caller identity as an entity, if supplied.

§user_id: Option<i64>

Caller identity as a raw id, if supplied.

§correlation: Option<Arc<CorrelationContext>>

Request correlation propagated with the query, if supplied.

§txn: Option<Arc<DatabaseTransaction>>

Optional transaction used as the query executor when set.

Held behind an Arc so the options stay cheaply cloneable even though DatabaseTransaction itself is neither Clone nor Send-free to move. Share with Arc::new(txn) — note a begun transaction cannot be cloned out of SeaORM, so callers typically wrap it at begin time (see RepositoryOptions::with_transaction).

Implementations§

Source§

impl<U> RepositoryOptions<U>
where U: BaseEntity + Clone + Send + Sync + 'static,

Source

pub fn new() -> Self

Creates options with defaults: limit 15, no cursor, distinct false, detach true.

Source

pub fn with_limit(self, limit: usize) -> Self

Sets the maximum rows for limited reads.

Source

pub fn with_cursor(self, cursor: impl Into<String>) -> Self

Sets the pagination cursor to continue from.

Source

pub fn with_user(self, user: U) -> Self

Sets the caller identity as an entity; also records its id as user_id.

Source

pub fn with_user_id(self, user_id: i64) -> Self

Sets the caller identity as a raw id without an entity.

Source

pub fn with_correlation(self, ctx: Arc<CorrelationContext>) -> Self

Attaches request correlation context to the options.

Source

pub fn distinct(self) -> Self

Enables SELECT DISTINCT for the query.

Source

pub fn with_detach(self, detach: bool) -> Self

Sets the detach flag carried alongside the query.

Source

pub fn with_transaction(self, txn: Arc<DatabaseTransaction>) -> Self

Attaches a transaction used as the executor for database operations.

When set, repository methods run against this transaction instead of the repository’s own connection. When unset, they fall back to the repository connection.

Source

pub fn with_txn(self, txn: Arc<DatabaseTransaction>) -> Self

Source

pub fn without_transaction(self) -> Self

Removes any attached transaction, restoring execution on the repository connection.

Source

pub fn transaction(&self) -> Option<&DatabaseTransaction>

Returns the attached transaction, if any.

Source

pub fn has_transaction(&self) -> bool

Returns true when a transaction is attached.

Source

pub fn user_id(&self) -> Option<i64>

Returns the effective caller id: user_id when set, else the user entity id.

Source

pub fn join(self, other: Self) -> Self

Overlays other on top of self, joining two parameter sets as you please.

Scalar fields (limit, distinct, detach) are taken from other; optional fields (cursor, user, user_id, correlation, txn) fall back to self when other leaves them unset. A replaced user entity clears a stale inherited user_id (the id is still derivable from the entity via RepositoryOptions::user_id).

Typical use: request-derived base joined with caller overrides — RepositoryOptions::from_ctx(ctx).join(RepositoryOptions::new().with_limit(50)).

Source§

impl RepositoryOptions<NoUser>

Source

pub fn from_ctx(ctx: Arc<CorrelationContext>) -> Self

Builds options from the request context: pagination limit and cursor, the numeric user id when the context carries one, and the correlation itself. Join caller overrides on top via RepositoryOptions::join.

Source

pub fn with_user_entity<U>(self, user: U) -> RepositoryOptions<U>
where U: BaseEntity + Clone + Send + Sync + 'static,

Replaces the NoUser identity with the given entity, keeping other settings.

Trait Implementations§

Source§

impl<U> Clone for RepositoryOptions<U>
where U: BaseEntity + Clone + Send + Sync + 'static + Clone,

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<U> Debug for RepositoryOptions<U>
where U: BaseEntity + Clone + Send + Sync + 'static + Debug,

Source§

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

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

impl<U> Default for RepositoryOptions<U>
where U: BaseEntity + Clone + Send + Sync + 'static,

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl<U = NoUser> !RefUnwindSafe for RepositoryOptions<U>

§

impl<U = NoUser> !UnwindSafe for RepositoryOptions<U>

§

impl<U> Freeze for RepositoryOptions<U>
where Option<U>: Freeze,

§

impl<U> Send for RepositoryOptions<U>
where Option<U>: Send,

§

impl<U> Sync for RepositoryOptions<U>
where Option<U>: Sync,

§

impl<U> Unpin for RepositoryOptions<U>
where Option<U>: Unpin,

§

impl<U> UnsafeUnpin for RepositoryOptions<U>
where Option<U>: UnsafeUnpin,

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<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

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> CompatExt for T

Source§

fn compat(self) -> Compat<T>
where T: Sized,

Applies the Compat adapter by value. Read more
Source§

fn compat_ref(&self) -> Compat<&T>

Applies the Compat adapter by shared reference. Read more
Source§

fn compat_mut(&mut self) -> Compat<&mut T>

Applies the Compat adapter by mutable reference. Read more
Source§

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

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more