pub struct DatasourceRegistry { /* private fields */ }Expand description
应用持有的全部具名数据源。
Implementations§
Source§impl DatasourceRegistry
impl DatasourceRegistry
Sourcepub fn new(
default: Option<DatasourceId>,
datasources: Vec<Datasource>,
) -> Result<Self, BaseError>
pub fn new( default: Option<DatasourceId>, datasources: Vec<Datasource>, ) -> Result<Self, BaseError>
构造注册表。
default为None时:只有一个源则自动成为默认源,多个源则报错;- 重名、默认源不存在均报错。
Sourcepub fn default_id(&self) -> &DatasourceId
pub fn default_id(&self) -> &DatasourceId
返回默认数据源名。
Sourcepub fn default_datasource(&self) -> &Datasource
pub fn default_datasource(&self) -> &Datasource
返回默认数据源。
Sourcepub fn get(&self, id: &DatasourceId) -> Option<&Datasource>
pub fn get(&self, id: &DatasourceId) -> Option<&Datasource>
按逻辑名查找数据源。
Sourcepub fn resolve(
&self,
id: Option<&DatasourceId>,
) -> Result<&Datasource, BaseError>
pub fn resolve( &self, id: Option<&DatasourceId>, ) -> Result<&Datasource, BaseError>
解析可选数据源名:None 表示默认源。
Sourcepub fn resolve_id(&self, id: &DatasourceId) -> Result<&Datasource, BaseError>
pub fn resolve_id(&self, id: &DatasourceId) -> Result<&Datasource, BaseError>
解析数据源名:字面量 default 在未注册同名源时回退到注册表的默认源。
Sourcepub fn contains(&self, id: &DatasourceId) -> bool
pub fn contains(&self, id: &DatasourceId) -> bool
是否包含指定数据源。
Sourcepub fn iter(&self) -> impl Iterator<Item = &Datasource>
pub fn iter(&self) -> impl Iterator<Item = &Datasource>
按注册顺序迭代。
Sourcepub async fn health_check(&self) -> Vec<ResourceHealth>
pub async fn health_check(&self) -> Vec<ResourceHealth>
逐源健康检查;只包含参与 readiness 的 required 源。
Sourcepub async fn health(&self) -> Vec<DatasourceHealth>
pub async fn health(&self) -> Vec<DatasourceHealth>
逐源健康快照(带逻辑名与 required 标记)。
Sourcepub fn pool_statuses(&self) -> Vec<DatasourcePoolStatus>
pub fn pool_statuses(&self) -> Vec<DatasourcePoolStatus>
逐源连接池状态。
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for DatasourceRegistry
impl !UnwindSafe for DatasourceRegistry
impl Forget for DatasourceRegistry
impl Freeze for DatasourceRegistry
impl Move for DatasourceRegistry
impl Send for DatasourceRegistry
impl Sync for DatasourceRegistry
impl Unpin for DatasourceRegistry
impl UnsafeUnpin for DatasourceRegistry
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> 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