Skip to main content

init_default_non_sqlite

Function init_default_non_sqlite 

Source
pub async fn init_default_non_sqlite(
    creds: Option<Credentials>,
) -> Result<Box<dyn Database>, InitDbError>
Expand description

Initializes a non-SQLite database connection based on active feature flags.

This function is similar to init but specifically for non-SQLite backends (e.g., PostgreSQL). It selects the appropriate database based on compile-time features and returns a boxed trait object implementing the Database interface.

§Panics

  • If invalid features are specified for the crate

§Errors

  • InitDbError::CredentialsRequired when a credentials-based backend is active and creds is None
  • InitDbError::InitPostgres when postgres backend initialization fails (when enabled)
  • InitDbError::InitDatabase when sqlx/raw PostgreSQL initialization fails (when enabled)

§Examples

use switchy_database_connection::{init_default_non_sqlite, Credentials};

let creds = Credentials::from_url("postgres://user:pass@localhost:5432/moosicbox")
    .expect("URL should parse");

let _db = init_default_non_sqlite(Some(creds)).await?;