first commit

This commit is contained in:
creations 2025-05-31 18:20:37 -04:00
commit 2da598738b
Signed by: creations
GPG key ID: 8F553AA4320FC711
15 changed files with 3758 additions and 0 deletions

27
src/db/postgres.rs Normal file
View file

@ -0,0 +1,27 @@
use sqlx::{postgres::PgPoolOptions, PgPool};
use std::env;
pub async fn connect() -> PgPool {
let db_url = env::var("DATABASE_URL").expect("DATABASE_URL is required");
let pool = PgPoolOptions::new()
.max_connections(5)
.connect(&db_url)
.await
.expect("Failed to connect to Postgres");
sqlx::query(
r#"
CREATE TABLE IF NOT EXISTS timezones (
user_id TEXT PRIMARY KEY,
username TEXT NOT NULL,
timezone TEXT NOT NULL
);
"#,
)
.execute(&pool)
.await
.expect("Failed to create timezones table");
pool
}