Added database connection

Code now connects to database and prints out errors. Also the ticket
table now includes a timestamp field
This commit is contained in:
2026-04-22 15:50:08 +02:00
parent 9972863232
commit bc0d3cb589
5 changed files with 214 additions and 0 deletions

View File

@@ -1,10 +1,24 @@
mod models;
use axum::{Router, routing};
use dotenv::dotenv;
use models::*;
use serde::{Deserialize, Serialize};
use sqlx::{PgPool, postgres::PgPoolOptions};
#[tokio::main]
async fn main() {
dotenv().ok();
let database_url = std::env::var("DATABASE_URL").expect("DATABASE_URL variable not set");
let pool = match PgPoolOptions::new().connect(&database_url).await {
Ok(pool) => {
println!("Database connection successful");
pool
}
Err(err) => {
println!("Failed to connect to database: {:?}", err);
std::process::exit(1);
}
};
let app = Router::new().route("/", routing::get(root_handler));
let listener = tokio::net::TcpListener::bind("0.0.0.0:8001").await.unwrap();