pub struct RepositoryOptions<U = NoUser>{
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: usizeMaximum rows for limited reads; default is 15.
cursor: Option<String>Opaque cursor from a previous page, if continuing pagination.
distinct: boolWhether selects use SELECT DISTINCT.
detach: boolDetach 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>
impl<U> RepositoryOptions<U>
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates options with defaults: limit 15, no cursor, distinct false, detach true.
Sourcepub fn with_limit(self, limit: usize) -> Self
pub fn with_limit(self, limit: usize) -> Self
Sets the maximum rows for limited reads.
Sourcepub fn with_cursor(self, cursor: impl Into<String>) -> Self
pub fn with_cursor(self, cursor: impl Into<String>) -> Self
Sets the pagination cursor to continue from.
Sourcepub fn with_user(self, user: U) -> Self
pub fn with_user(self, user: U) -> Self
Sets the caller identity as an entity; also records its id as user_id.
Sourcepub fn with_user_id(self, user_id: i64) -> Self
pub fn with_user_id(self, user_id: i64) -> Self
Sets the caller identity as a raw id without an entity.
Sourcepub fn with_correlation(self, ctx: Arc<CorrelationContext>) -> Self
pub fn with_correlation(self, ctx: Arc<CorrelationContext>) -> Self
Attaches request correlation context to the options.
Sourcepub fn with_detach(self, detach: bool) -> Self
pub fn with_detach(self, detach: bool) -> Self
Sets the detach flag carried alongside the query.
Sourcepub fn with_transaction(self, txn: Arc<DatabaseTransaction>) -> Self
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.
Sourcepub fn with_txn(self, txn: Arc<DatabaseTransaction>) -> Self
pub fn with_txn(self, txn: Arc<DatabaseTransaction>) -> Self
Alias for RepositoryOptions::with_transaction.
Sourcepub fn without_transaction(self) -> Self
pub fn without_transaction(self) -> Self
Removes any attached transaction, restoring execution on the repository connection.
Sourcepub fn transaction(&self) -> Option<&DatabaseTransaction>
pub fn transaction(&self) -> Option<&DatabaseTransaction>
Returns the attached transaction, if any.
Sourcepub fn has_transaction(&self) -> bool
pub fn has_transaction(&self) -> bool
Returns true when a transaction is attached.
Sourcepub fn user_id(&self) -> Option<i64>
pub fn user_id(&self) -> Option<i64>
Returns the effective caller id: user_id when set, else the user entity id.
Sourcepub fn join(self, other: Self) -> Self
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>
impl RepositoryOptions<NoUser>
Sourcepub fn from_ctx(ctx: Arc<CorrelationContext>) -> Self
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.
Sourcepub fn with_user_entity<U>(self, user: U) -> RepositoryOptions<U>
pub fn with_user_entity<U>(self, user: U) -> RepositoryOptions<U>
Replaces the NoUser identity with the given entity, keeping other settings.
Trait Implementations§
Source§impl<U> Clone for RepositoryOptions<U>
impl<U> Clone for RepositoryOptions<U>
Source§impl<U> Debug for RepositoryOptions<U>
impl<U> Debug for RepositoryOptions<U>
Auto Trait Implementations§
impl<U = NoUser> !RefUnwindSafe for RepositoryOptions<U>
impl<U = NoUser> !UnwindSafe for RepositoryOptions<U>
impl<U> Freeze for RepositoryOptions<U>
impl<U> Send for RepositoryOptions<U>
impl<U> Sync for RepositoryOptions<U>
impl<U> Unpin for RepositoryOptions<U>
impl<U> UnsafeUnpin for RepositoryOptions<U>where
Option<U>: UnsafeUnpin,
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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