From 777ba327cce7c4a78c04fd3512b19fd7c7f2cfd4 Mon Sep 17 00:00:00 2001 From: "NG (Graham)" Date: Sat, 20 Jun 2026 18:57:00 -0400 Subject: [PATCH] Add untested garage storage use support for postgres in debug builds; #130 --- rc_database/src/wrapper.rs | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/rc_database/src/wrapper.rs b/rc_database/src/wrapper.rs index e6ecb80..eb84534 100644 --- a/rc_database/src/wrapper.rs +++ b/rc_database/src/wrapper.rs @@ -241,10 +241,40 @@ impl Database { .await } - pub async fn garage_storage_by_user_id(&self, _user_id: i32) -> Result, sea_orm::DbErr> { + pub async fn garage_storage_by_user_id(&self, user_id: i32) -> Result, sea_orm::DbErr> { let size = match self.orm.as_ref() { // TODO implement support in other databases - //sea_orm::DatabaseConnection::SqlxPostgresPoolConnection(_) => None, + sea_orm::DatabaseConnection::SqlxPostgresPoolConnection(_) => { + + #[cfg(debug_assertions)] + { + /*let query = sea_orm::sea_query::raw_query!( + PostgresQueryBuilder, + r#"select sum(pg_column_size(g.*)) from garages g where g.user_id = $user_id;"# + );*/ + struct PgColumnSize; + impl sea_orm::sea_query::Iden for PgColumnSize { + fn unquoted(&self, s: &mut dyn std::fmt::Write) { + write!(s, "pg_column_size").unwrap(); + } + } + let result = crate::schema::garage::Entity::find() + .select_only() + .expr_as( + sea_orm::sea_query::Func::cust(PgColumnSize) + .arg(sea_orm::sea_query::Expr::col((crate::schema::garage::Entity, sea_orm::sea_query::Asterisk))) + , "column") + .filter(crate::schema::garage::Column::UserId.eq(user_id)) + .into_model::>() + .one(self.orm.as_ref()) + .await?; + result.map(|x| x.column) + } + #[cfg(not(debug_assertions))] + { + None + } + }, _ => None, }; Ok(size)