first commit
This commit is contained in:
commit
2da598738b
15 changed files with 3758 additions and 0 deletions
27
src/db/postgres.rs
Normal file
27
src/db/postgres.rs
Normal 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
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue