Splits database into a separate crate

This commit is contained in:
2025-05-30 14:31:00 +02:00
parent 3f7ed03973
commit 597a960bf1
34 changed files with 368 additions and 402 deletions

View File

@@ -1,6 +1,4 @@
pub mod request;
pub mod schema;
pub mod util;
use actix_cors::Cors;
use actix_web::middleware::Logger;
@@ -8,31 +6,15 @@ use actix_web::HttpServer;
use actix_web::App;
use actix_web::http;
use actix_web::web;
use diesel::PgConnection;
use diesel::r2d2::{ConnectionManager, Pool};
use diesel_migrations::{embed_migrations, EmbeddedMigrations, MigrationHarness};
use request::{login, register, gamenights, gamenight_post, gamenight_get};
use util::GetConnection;
use tracing_actix_web::TracingLogger;
pub(crate) type DbPool = Pool<ConnectionManager<PgConnection>>;
pub const MIGRATIONS: EmbeddedMigrations = embed_migrations!();
fn run_migration(conn: &mut PgConnection) {
conn.run_pending_migrations(MIGRATIONS).unwrap();
}
use gamenight_database::*;
#[actix_web::main]
async fn main() -> std::io::Result<()> {
let url = "postgres://root:root@127.0.0.1/gamenight";
let manager = ConnectionManager::<PgConnection>::new(url);
// Refer to the `r2d2` documentation for more methods to use
// when building a connection pool
let pool = Pool::builder()
.test_on_check_out(true)
.build(manager)
.expect("Could not build connection pool");
let pool = get_connection_pool(url);
let mut conn = pool.get_conn();
run_migration(&mut conn);