pub trait Executor:
Any
+ Send
+ Sync
+ 'static {
// Required method
fn as_any(&self) -> &dyn Any;
// Provided method
fn non_transactional(&self) -> Option<Arc<dyn Executor>> { ... }
}Expand description
An ambient handle to a unit of database work, installed in the task-local for the lifetime of a request or a worker job.
The trait is object-safe so the engine can carry it as
Arc<dyn Executor> without naming a concrete ORM. The concrete handle
(a SeaORM Executor enum, a sqlx::Pool, a diesel_async::Connection,
…) implements this trait; an ORM-specific Repo recovers the concrete
type via Executor::as_any when it needs to issue a query.
Downcasting is the documented seam: this crate stays free of every
candidate ORM’s query API, and each Repo knows exactly which executor
shape its Module installs. A downcast miss is a framework bug
(mismatched Module + Repo); the contract is log at error and
degrade to None — the Repo then fails the operation (no ambient
executor), so the request errors loudly instead of panicking a worker
thread or silently reading “no rows”.
Required Methods§
Provided Methods§
Sourcefn non_transactional(&self) -> Option<Arc<dyn Executor>>
fn non_transactional(&self) -> Option<Arc<dyn Executor>>
A handle on the same database outside this executor’s transaction,
or None when there is nothing to step out of (already a pool) or the
ORM cannot produce one.
A transport that has proven an operation cannot write installs this for the operation’s duration, so the work runs without opening — and without pinning a connection to — the request transaction. The one caller today is the GraphQL endpoint: every operation arrives as a POST, so the HTTP boundary hands even a pure query a transaction it will never need.
Only ever pass work that cannot write. A mutation on the returned
handle loses atomicity and rollback. The default None is therefore
the fail-closed answer: an ORM that ignores this keeps the request
executor it was given.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".