Skip to main content

nest_rs_database/
lib.rs

1//! ORM-agnostic seam for the request/job data layer.
2//!
3//! `nest-rs-database` ships **only the seam**: the [`Executor`] trait, the
4//! [`ExecutorScope`] tag, and the `tokio::task_local!` plumbing
5//! ([`with_request_executor`], [`with_job_executor`], [`current_executor`],
6//! [`current_executor_scope`]) that carries "the request's current handle
7//! on a unit of work" across the framework. It is what every ORM
8//! integration plugs into — not an ORM itself. The non-HTTP side is wired
9//! through `nest_rs_worker::JobContext`, which a worker transport
10//! (`#[scheduled]`, `#[processor]`) resolves before each job.
11//!
12//! The first-class implementation is `nest-rs-seaorm` (SeaORM): it ships
13//! `Repo` (row-level filter), `CrudService`, `Bind`, the HTTP mask
14//! shaper, and `DatabaseModule` (the request interceptor that opens the
15//! transaction). Those pieces are SeaORM-specific by design — the
16//! leverage comes from binding tightly to the ORM's query/model types.
17//! A future third-party `nest-rs-<other-orm>` crate (sqlx, diesel,
18//! prisma-client-rust, mongo, …) can plug a different engine into the
19//! same ambient seam without touching `nest-rs-core` or any feature code.
20//!
21//! ## Extension contract
22//!
23//! To add a new ORM:
24//!
25//! 1. Implement [`Executor`] on the type that represents your handle (a
26//!    pool, a transaction, or an enum forwarding to either).
27//! 2. Ship a `Module` that, for each HTTP request, wraps the handler in
28//!    [`with_request_executor`] passing your `Arc<dyn Executor>`. For
29//!    worker transports do the same with [`with_job_executor`] via
30//!    `nest_rs_worker::JobContext`.
31//! 3. Provide your own `Repo`-equivalent query API that calls
32//!    [`current_executor`] and downcasts to your concrete type.
33//!
34//! The SeaORM-specific pieces (`Repo`, `condition_for`, the mask shaper,
35//! `Bind<S, A>`, `CrudService`) are unreachable from your implementation —
36//! that is intentional. They couple to SeaORM's `EntityTrait`/`Model`; a
37//! generic abstraction over them would lose 80% of their value. A new ORM
38//! integration ships its own row-level-filter equivalent.
39#![warn(missing_docs)]
40
41mod executor;
42
43pub use executor::{
44    Executor, ExecutorScope, current_executor, current_executor_scope, with_executor,
45    with_job_executor, with_request_executor,
46};