pub struct DbConfig { /* private fields */ }Expand description
A resolved database connection, and the profile it came from.
The profile is carried only for logging: the finished URL is the only thing a caller needs.
Implementations§
Source§impl DbConfig
impl DbConfig
Sourcepub fn load(profile: Option<&str>) -> Result<Self>
pub fn load(profile: Option<&str>) -> Result<Self>
profile selects a database by name; see [resolve_db_url].
Sourcepub fn from_env_var(profile_var: &str) -> Result<Self>
pub fn from_env_var(profile_var: &str) -> Result<Self>
Loads the profile from an environment variable, then resolves it.
The CLI takes a --profile argument; a server has no command line worth
parsing for this, so tango-api reads TANGO_PROFILE through here. One
resolver, two front doors.
Sourcepub fn from_url(url: impl Into<String>) -> Self
pub fn from_url(url: impl Into<String>) -> Self
A connection string supplied by the caller, not by the environment.
The two front doors above assume what this project’s own binaries have:
a .env, or environment variables, and nothing else. A downstream
project that stitches tango into a larger server usually does not work
that way - its configuration comes from its own file, its flags, or a
secret manager - and the only ways to reuse a URL through the other
constructors would be to write it into the process environment first
(unsafe { std::env::set_var(...) } since edition 2024) or to re-derive
the connection options by hand. This is the way in.
Nothing is read here: no .env is loaded and no variable is consulted,
so a caller that uses this cannot accidentally end up on a database it
did not name. profile_name is None, because there is no profile - the
URL is the whole answer.
pub fn postgres_connection_string(&self) -> &str
Sourcepub fn profile_name(&self) -> Option<&str>
pub fn profile_name(&self) -> Option<&str>
The profile in use, for a startup line. None is the default database.
Auto Trait Implementations§
impl Forget for DbConfig
impl Freeze for DbConfig
impl Move for DbConfig
impl RefUnwindSafe for DbConfig
impl Send for DbConfigwhere
RawVecInner: Send,
impl Sync for DbConfigwhere
RawVecInner: Sync,
impl Unpin for DbConfig
impl UnsafeUnpin for DbConfig
impl UnwindSafe for DbConfigwhere
RawVecInner: UnwindSafe,
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
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