pub struct Database { /* private fields */ }Expand description
A database handle: a shared Connection, cheap to clone.
Lives as a container singleton and is cloned into repositories, jobs and console commands freely.
Implementations§
Source§impl Database
impl Database
Sourcepub fn new(connection: impl Connection) -> Database
pub fn new(connection: impl Connection) -> Database
Wrap a concrete connection.
Sourcepub fn from_arc(connection: Arc<dyn Connection>) -> Database
pub fn from_arc(connection: Arc<dyn Connection>) -> Database
Wrap an already-shared connection.
Sourcepub fn connection(&self) -> &Arc<dyn Connection> ⓘ
pub fn connection(&self) -> &Arc<dyn Connection> ⓘ
The underlying connection.
Sourcepub fn is_sharded(&self) -> bool
pub fn is_sharded(&self) -> bool
Whether the backend is a sharded fleet.
Sourcepub fn shard_family(&self) -> Option<String>
pub fn shard_family(&self) -> Option<String>
The shard family, if any.
Sourcepub async fn fetch(
&self,
prepared: Prepared,
columns: Vec<ColumnRequest>,
) -> Result<Vec<OwnedRow>, Error>
pub async fn fetch( &self, prepared: Prepared, columns: Vec<ColumnRequest>, ) -> Result<Vec<OwnedRow>, Error>
Run a prepared query, reading back the named columns.
Sourcepub async fn fetch_all<E>(&self, prepared: Prepared) -> Result<Vec<E>, Error>where
E: Entity,
pub async fn fetch_all<E>(&self, prepared: Prepared) -> Result<Vec<E>, Error>where
E: Entity,
Run a prepared query and decode every row into E.
Sourcepub async fn fetch_one<E>(&self, prepared: Prepared) -> Result<Option<E>, Error>where
E: Entity,
pub async fn fetch_one<E>(&self, prepared: Prepared) -> Result<Option<E>, Error>where
E: Entity,
Run a prepared query and decode the first row into E.
Sourcepub async fn fetch_count(&self, prepared: Prepared) -> Result<u64, Error>
pub async fn fetch_count(&self, prepared: Prepared) -> Result<u64, Error>
Run a prepared COUNT(*) AS cnt and read the total.
Trait Implementations§
Source§impl Executor for Database
Implementing Executor is what keeps Rainier ORM’s whole surface available.
impl Executor for Database
Implementing Executor is what keeps Rainier ORM’s whole surface available.
repo::insert, repo::query::<E>(), Cursor and Migrator::run are all
generic over X: Executor, so they accept a Database directly. Their
futures are !Send (see the module docs), so use them from a console
command, a migration, or a Worker — not from a request handler, which needs
the Send path above.
Source§fn dialect(&self) -> Dialect
fn dialect(&self) -> Dialect
Source§fn shard_family(&self) -> Option<&str>
fn shard_family(&self) -> Option<&str>
None for a
single, unsharded database. Read moreSource§fn is_sharded(&self) -> bool
fn is_sharded(&self) -> bool
true when this connector is sharded — sugar for
shard_family().is_some().Source§fn allocate_id(&self, shard_key: u64) -> Option<u64>
fn allocate_id(&self, shard_key: u64) -> Option<u64>
shard_key (e.g. the owning user_id). repo::insert calls this when
an entity’s primary key is itself a shard key, is not auto-increment,
and is unset — so id assignment for the sharded data tier happens here,
in the connector, transparently, not in the service. The default is
None (no allocation: the caller’s id or the DB’s auto-increment stands)
so single, unsharded executors are unaffected.Source§async fn fetch_all(
&self,
sql: &str,
params: Vec<Value>,
) -> Result<Vec<Box<dyn Row>>, Error>
async fn fetch_all( &self, sql: &str, params: Vec<Value>, ) -> Result<Vec<Box<dyn Row>>, Error>
Source§async fn execute(
&self,
sql: &str,
params: Vec<Value>,
) -> Result<ExecOutcome, Error>
async fn execute( &self, sql: &str, params: Vec<Value>, ) -> Result<ExecOutcome, Error>
ExecOutcome.Source§async fn fetch_all_routed(
&self,
route: ShardRoute,
sql: &str,
params: Vec<Value>,
) -> Result<Vec<Box<dyn Row>>, Error>
async fn fetch_all_routed( &self, route: ShardRoute, sql: &str, params: Vec<Value>, ) -> Result<Vec<Box<dyn Row>>, Error>
ShardRoute selects. Read moreSource§async fn execute_routed(
&self,
route: ShardRoute,
sql: &str,
params: Vec<Value>,
) -> Result<ExecOutcome, Error>
async fn execute_routed( &self, route: ShardRoute, sql: &str, params: Vec<Value>, ) -> Result<ExecOutcome, Error>
execute. Defaults to ignoring
the route — see fetch_all_routed.Auto Trait Implementations§
impl !RefUnwindSafe for Database
impl !UnwindSafe for Database
impl Freeze for Database
impl Send for Database
impl Sync for Database
impl Unpin for Database
impl UnsafeUnpin for Database
Blanket Implementations§
impl<T> Actor for T
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Event for T
impl<T> Event for T
Source§fn event_name() -> &'static strwhere
Self: Sized,
fn event_name() -> &'static strwhere
Self: Sized,
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