feat(main): now database is connected at the start of the app
This commit is contained in:
parent
6c858abb0a
commit
d746e95b9e
1 changed files with 23 additions and 0 deletions
23
src/main.rs
23
src/main.rs
|
|
@ -3,20 +3,43 @@ mod events;
|
||||||
|
|
||||||
use events::Bot;
|
use events::Bot;
|
||||||
use serenity::all::*;
|
use serenity::all::*;
|
||||||
|
use sqlx::postgres::PgPoolOptions;
|
||||||
|
use sqlx::{
|
||||||
|
Pool, Postgres, migrate
|
||||||
|
};
|
||||||
use std::env;
|
use std::env;
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
|
println!("\n");
|
||||||
dotenvy::dotenv().ok();
|
dotenvy::dotenv().ok();
|
||||||
|
|
||||||
let token: String =
|
let token: String =
|
||||||
env::var("DISCORD_TOKEN").expect("❌ | DISCORD_TOKEN missing (check the env file)");
|
env::var("DISCORD_TOKEN").expect("❌ | DISCORD_TOKEN missing (check the env file)");
|
||||||
|
|
||||||
|
let database_url: String =
|
||||||
|
env::var("DATABASE_URL").expect("❌ | DATABASE_URL missing (check the env file)");
|
||||||
|
|
||||||
|
let db: Pool<Postgres> = PgPoolOptions::new()
|
||||||
|
.max_connections(5)
|
||||||
|
.connect(&database_url)
|
||||||
|
.await
|
||||||
|
.expect("❌ | Failed to connect to PostgreSQL");
|
||||||
|
println!("✅ | Connected to PostgreSQL");
|
||||||
|
|
||||||
|
migrate!("./migrations")
|
||||||
|
.run(&db)
|
||||||
|
.await
|
||||||
|
.expect("❌ | Failed to run migrations");
|
||||||
|
println!("✅ | Migrations applied\n");
|
||||||
|
|
||||||
|
|
||||||
let intents: GatewayIntents = GatewayIntents::default();
|
let intents: GatewayIntents = GatewayIntents::default();
|
||||||
|
|
||||||
let bot: Bot = Bot {
|
let bot: Bot = Bot {
|
||||||
commands: commands::import(),
|
commands: commands::import(),
|
||||||
events: events::import(),
|
events: events::import(),
|
||||||
|
database: db,
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut client: Client = Client::builder(&token, intents)
|
let mut client: Client = Client::builder(&token, intents)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue