Some checks failed
Release Tagging / release (push) Successful in 47s
Rust Build / Check (push) Successful in 53s
Rust Build / Test Suite (push) Failing after 54s
Rust Build / Rustfmt (push) Successful in 28s
Rust Build / Clippy (push) Successful in 50s
Rust Build / build (push) Successful in 1m5s
Reviewed-on: #9 Co-authored-by: KD <kundeng94@gmail.com> Co-committed-by: KD <kundeng94@gmail.com>
34 lines
716 B
Rust
34 lines
716 B
Rust
pub mod callers;
|
|
pub mod config;
|
|
pub mod models;
|
|
|
|
mod keys {
|
|
pub const DBURL: &str = "DATABASE_URL";
|
|
|
|
pub mod error {
|
|
pub const ERROR: &str = "DATABASE_URL must be set in .env";
|
|
}
|
|
}
|
|
|
|
mod connection_settings {
|
|
pub const MAXCONN: u32 = 5;
|
|
}
|
|
|
|
pub mod db_pool {
|
|
|
|
use sqlx::postgres::PgPoolOptions;
|
|
use std::env;
|
|
|
|
use crate::{connection_settings, keys};
|
|
|
|
pub async fn create_pool() -> Result<sqlx::PgPool, sqlx::Error> {
|
|
dotenv::dotenv().ok();
|
|
let database_url = env::var(keys::DBURL).expect(keys::error::ERROR);
|
|
|
|
PgPoolOptions::new()
|
|
.max_connections(connection_settings::MAXCONN)
|
|
.connect(&database_url)
|
|
.await
|
|
}
|
|
}
|