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:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user