deadpool, diesel and errors! #16

Merged
radical merged 17 commits from deadpool-diesel into main 2025-05-23 11:07:21 +00:00
Showing only changes of commit b9c7bda2b1 - Show all commits

View file

@ -3,14 +3,19 @@ use actix_web::{App, HttpServer, web};
use argon2::Argon2; use argon2::Argon2;
use clap::Parser; use clap::Parser;
use simple_logger::SimpleLogger; use simple_logger::SimpleLogger;
use sqlx::{PgPool, Pool, Postgres}; use diesel_async::pooled_connection::AsyncDieselConnectionManager;
use diesel_async::pooled_connection::deadpool::Pool;
use diesel_async::RunQueryDsl;
use std::time::SystemTime; use std::time::SystemTime;
mod config; mod config;
use config::{Config, ConfigBuilder}; use config::{Config, ConfigBuilder};
mod api; mod api;
type Conn = deadpool::managed::Object<AsyncDieselConnectionManager<diesel_async::AsyncPgConnection>>;
pub mod structs; pub mod structs;
pub mod utils; pub mod utils;
pub mod tables;
type Error = Box<dyn std::error::Error>; type Error = Box<dyn std::error::Error>;
@ -23,7 +28,7 @@ struct Args {
#[derive(Clone)] #[derive(Clone)]
pub struct Data { pub struct Data {
pub pool: Pool<Postgres>, pub pool: deadpool::managed::Pool<AsyncDieselConnectionManager<diesel_async::AsyncPgConnection>, Conn>,
pub cache_pool: redis::Client, pub cache_pool: redis::Client,
pub _config: Config, pub _config: Config,
pub argon2: Argon2<'static>, pub argon2: Argon2<'static>,
@ -44,17 +49,21 @@ async fn main() -> Result<(), Error> {
let web = config.web.clone(); let web = config.web.clone();
let pool = PgPool::connect_with(config.database.connect_options()).await?; // create a new connection pool with the default config
let pool_config = AsyncDieselConnectionManager::<diesel_async::AsyncPgConnection>::new(config.database.url());
let pool = Pool::builder(pool_config).build()?;
let cache_pool = redis::Client::open(config.cache_database.url())?; let cache_pool = redis::Client::open(config.cache_database.url())?;
let mut conn = pool.get().await?;
/* /*
TODO: Figure out if a table should be used here and if not then what. TODO: Figure out if a table should be used here and if not then what.
Also figure out if these should be different types from what they currently are and if we should add more "constraints" Also figure out if these should be different types from what they currently are and if we should add more "constraints"
TODO: References to time should be removed in favor of using the timestamp built in to UUIDv7 (apart from deleted_at in users) TODO: References to time should be removed in favor of using the timestamp built in to UUIDv7 (apart from deleted_at in users)
*/ */
sqlx::raw_sql( diesel::sql_query(
r#" r#"
CREATE TABLE IF NOT EXISTS users ( CREATE TABLE IF NOT EXISTS users (
uuid uuid PRIMARY KEY NOT NULL, uuid uuid PRIMARY KEY NOT NULL,
@ -141,7 +150,7 @@ async fn main() -> Result<(), Error> {
); );
"#, "#,
) )
.execute(&pool) .execute(&mut conn)
.await?; .await?;
/* /*