Skip to main content

DbConfig

Struct DbConfig 

Source
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

Source

pub fn load(profile: Option<&str>) -> Result<Self>

profile selects a database by name; see [resolve_db_url].

Source

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.

Source

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.

Source

pub fn postgres_connection_string(&self) -> &str

Source

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
where *const u8 is !null: Freeze, PhantomData<u8>: Freeze,

§

impl Move for DbConfig

§

impl RefUnwindSafe for DbConfig

§

impl Send for DbConfig
where RawVecInner: Send,

§

impl Sync for DbConfig
where RawVecInner: Sync,

§

impl Unpin for DbConfig
where *const u8 is !null: Unpin,

§

impl UnsafeUnpin for DbConfig

§

impl UnwindSafe for DbConfig
where RawVecInner: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more