Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

brokkr-models Rust

Functions

brokkr-models::establish_connection

pub(crate)

#![allow(unused)]
fn main() {
fn establish_connection (database_url : String) -> PgConnection
}

Establishes a connection to the PostgreSQL database.

This function exists to manage migrations and perform basic testing in this crate without a specific Data Access Layer (DAL) in place.

Parameters:

NameTypeDescription
database_url-A string slice that holds the URL of the database to connect to.

Returns:

  • PgConnection - A connection to the PostgreSQL database.

Raises:

ExceptionDescription
PanicThis function will panic if it fails to establish a connection to the database.
Source
#![allow(unused)]
fn main() {
pub(crate) fn establish_connection(database_url: String) -> PgConnection {
    PgConnection::establish(&database_url)
        .unwrap_or_else(|_| panic!("Error connecting to {}", database_url))
}
}