pub struct Database { /* private fields */ }Expand description
A database wrapper
Contains (potentially) separate connections for readonly database instances and read/write instances.
This allows you to benefit from multi node database clusters which provide a read-only endpoint.
By if not readonly endpoint is configured the read-write endpoint is used instead.
Implementations§
Trait Implementations§
Source§impl FromRef<DefaultState> for Database
impl FromRef<DefaultState> for Database
Source§fn from_ref(state: &DefaultState) -> Self
fn from_ref(state: &DefaultState) -> Self
Converts to this type from a reference to the input type.
Source§impl ProvideState<Database> for DefaultState
impl ProvideState<Database> for DefaultState
Source§impl ProvideStateRef<Database> for DefaultState
impl ProvideStateRef<Database> for DefaultState
fn provide_ref(&self) -> &Database
fn provide_mut(&mut self) -> &mut Database
Source§impl TryFromModule for Database
impl TryFromModule for Database
Source§async fn try_from_module(module: &Module) -> Result<Option<Self>>where
Self: Sized,
async fn try_from_module(module: &Module) -> Result<Option<Self>>where
Self: Sized,
Builds the Database module from a Module configuration item. It requires the values outlined in the DatabaseConfig struct. Requires the module name to be “database”.
use quokka::{state::Database, config::{Module, TryFromModule}};
#[tokio::main]
async fn main() {
let module = Module {
module: "database".to_string(),
config: toml::Value::Table(toml::toml! {
url = "postgres://database.fail"
})
};
assert!(Database::try_from_module(&module).await.unwrap().is_some());
let module = Module {
module: "not_database".to_string(),
config: toml::Value::String(String::new())
};
assert!(Database::try_from_module(&module).await.unwrap().is_none()); // Return [Option::None] as the module is not responsible for the database configuration
let module = Module {
module: "database".to_string(),
config: toml::Value::String(String::new())
};
assert_eq!(Database::try_from_module(&module).await.unwrap_err().status_code, 500); // Failes because the configuration format is not matched
}Auto Trait Implementations§
impl Freeze for Database
impl !RefUnwindSafe for Database
impl Send for Database
impl Sync for Database
impl Unpin for Database
impl !UnwindSafe for Database
Blanket Implementations§
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
Mutably borrows from an owned value. Read more
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>
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 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>
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