rebuild file structur + simple sqlite db endpoint

This commit is contained in:
2025-09-04 22:32:53 +02:00
parent 3db51cc805
commit 3450c216c0
20 changed files with 748 additions and 49 deletions

35
src/utils/db_pool.rs Normal file
View File

@@ -0,0 +1,35 @@
use std::sync::Arc;
use dashmap::DashMap;
use r2d2::{Pool};
use r2d2_sqlite::SqliteConnectionManager;
type HotelId = i32; // or i32 if you want numeric ids
#[derive(Clone)]
pub struct HotelPools {
pools: Arc<DashMap<HotelId, Pool<SqliteConnectionManager>>>,
}
impl HotelPools {
pub fn new() -> Self {
Self {
pools: Arc::new(DashMap::new()),
}
}
pub fn get_pool(&self, hotel_id: i32) -> Pool<SqliteConnectionManager> {
if let Some(pool) = self.pools.get(&hotel_id) {
return pool.clone();
}
let db_path = format!("db/{}.sqlite", hotel_id);
let manager = SqliteConnectionManager::file(db_path);
let pool = Pool::builder()
.max_size(5) // adjust based on load
.build(manager)
.expect("Failed to build pool");
self.pools.insert(hotel_id, pool.clone());
pool
}
}