This repository has been archived on 2024-08-06. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
chellaris-rust-api/src/db/mod.rs

21 lines
547 B
Rust
Raw Normal View History

2023-08-25 03:42:19 +02:00
use std::error::Error;
use sqlx::{Postgres, postgres::PgConnectOptions, PgPool, Pool};
use crate::{PostgresConfig};
pub(crate) mod schemas;
pub(crate) async fn connect_postgres(config: PostgresConfig) -> Result<Pool<Postgres>, Box<dyn Error>> {
let connection_settings = PgConnectOptions::new()
.host(&config.host)
.port(config.port)
.username(&config.user)
.password(&config.password)
.database(&config.db);
let pool = PgPool::connect_with(connection_settings).await?;
return Ok(pool);
}