Slightly more expressive expressions.

This commit is contained in:
2026-10-13 12:11:13 +02:00
parent f0d4a35290
commit 4343959c74
8 changed files with 55 additions and 54 deletions
+7 -7
View File
@@ -5,7 +5,7 @@ use super::{
RepositoryError, dtos::Upsert,
};
use crate::{
database::{Constraint, DatabaseError, account_members as db, dtos::AccountMemberRow},
database::{self, Constraint, DatabaseError, dtos::AccountMemberRow},
domain::AccountMember,
};
@@ -23,7 +23,7 @@ pub async fn list<'e, E>(
where
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
{
let query = db::Query {
let query = database::account_members::Query {
limit: query
.limit
.map(|limit| i64::try_from(limit).map_err(|_| QueryConversionError::Limit(limit)))
@@ -34,7 +34,7 @@ where
.transpose()?,
};
let members = db::list(executor, user_id, account_id, query)
let members = database::account_members::list(executor, user_id, account_id, query)
.await?
.into_iter()
.map(decode)
@@ -52,7 +52,7 @@ pub async fn get_by_id<'e, E>(
where
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
{
let member = db::get_by_id(executor, user_id, account_id, id)
let member = database::account_members::get_by_id(executor, user_id, account_id, id)
.await?
.map(decode)
.transpose()?;
@@ -68,7 +68,7 @@ pub async fn upsert<'e, E>(
where
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
{
let member = db::upsert(executor, user_id, encode(member))
let member = database::account_members::upsert(executor, user_id, encode(member))
.await
.map_err(classify_upsert_error)?
.map(|upserted| upserted.try_map(decode))
@@ -88,7 +88,7 @@ pub async fn insert_initial<'e, E>(
where
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
{
let row = db::insert_initial(executor, encode(member))
let row = database::account_members::insert_initial(executor, encode(member))
.await
.map_err(classify_upsert_error)?;
@@ -133,7 +133,7 @@ pub async fn delete_by_id<'e, E>(
where
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
{
let member = db::delete_by_id(executor, user_id, account_id, id)
let member = database::account_members::delete_by_id(executor, user_id, account_id, id)
.await
.map_err(classify_delete_error)?
.map(decode)
+7 -7
View File
@@ -7,7 +7,7 @@ use super::{
dtos::Upsert,
};
use crate::{
database::{Constraint, DatabaseError, accounts as db, dtos::AccountRow},
database::{self, Constraint, DatabaseError, dtos::AccountRow},
domain::Account,
};
@@ -25,7 +25,7 @@ pub async fn list<'e, E>(
where
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
{
let query = db::Query {
let query = database::accounts::Query {
name: query.name,
limit: query
.limit
@@ -37,7 +37,7 @@ where
.transpose()?,
};
let accounts = db::list(executor, user_id, query)
let accounts = database::accounts::list(executor, user_id, query)
.await?
.into_iter()
.map(decode)
@@ -54,7 +54,7 @@ pub async fn get_by_id<'e, E>(
where
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
{
let account = db::get_by_id(executor, user_id, id)
let account = database::accounts::get_by_id(executor, user_id, id)
.await?
.map(decode)
.transpose()?;
@@ -74,7 +74,7 @@ where
return Ok(HashMap::new());
}
let accounts = db::get_by_ids(executor, user_id, ids)
let accounts = database::accounts::get_by_ids(executor, user_id, ids)
.await?
.into_iter()
.map(decode)
@@ -96,7 +96,7 @@ pub async fn upsert<'e, E>(
where
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
{
let upserted = db::upsert(executor, user_id, encode(account))
let upserted = database::accounts::upsert(executor, user_id, encode(account))
.await?
.map(|upserted| upserted.try_map(decode))
.transpose()?
@@ -113,7 +113,7 @@ pub async fn delete_by_id<'e, E>(
where
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
{
let account = db::delete_by_id(executor, user_id, id)
let account = database::accounts::delete_by_id(executor, user_id, id)
.await
.map_err(classify_delete_error)?
.map(decode)
@@ -9,9 +9,7 @@ use super::{
},
};
use crate::{
database::{
Constraint, DatabaseError, dtos::RecurringTransactionRow, recurring_transactions as db,
},
database::{self, Constraint, DatabaseError, dtos::RecurringTransactionRow},
domain::{Cents, Recurrence, RecurrenceInterval, RecurringTransaction, Schedule},
};
@@ -28,7 +26,7 @@ pub async fn list<'e, E>(
where
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
{
let query = db::Query {
let query = database::recurring_transactions::Query {
limit: query
.limit
.map(|l| i64::try_from(l).map_err(|_| QueryConversionError::Limit(l)))
@@ -39,7 +37,7 @@ where
.transpose()?,
};
let transactions = db::list(executor, user_id, query)
let transactions = database::recurring_transactions::list(executor, user_id, query)
.await?
.into_iter()
.map(decode)
@@ -56,7 +54,7 @@ pub async fn get_by_id<'e, E>(
where
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
{
let transaction = db::get_by_id(executor, user_id, id)
let transaction = database::recurring_transactions::get_by_id(executor, user_id, id)
.await?
.map(decode)
.transpose()?;
@@ -72,7 +70,7 @@ pub async fn upsert<'e, E>(
where
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
{
let upserted = db::upsert(executor, user_id, encode(transaction))
let upserted = database::recurring_transactions::upsert(executor, user_id, encode(transaction))
.await
.map_err(classify_upsert_error)?
.map(|upserted| upserted.try_map(decode))
@@ -109,7 +107,7 @@ pub async fn delete_by_id<'e, E>(
where
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
{
let transaction = db::delete_by_id(executor, user_id, id)
let transaction = database::recurring_transactions::delete_by_id(executor, user_id, id)
.await?
.map(decode)
.transpose()?;
+5 -5
View File
@@ -2,7 +2,7 @@ use chrono::{DateTime, Utc};
use super::RepositoryError;
use crate::{
database::{dtos::TokenRow, tokens as db},
database::{self, dtos::TokenRow},
domain::Token,
};
@@ -13,7 +13,7 @@ pub async fn get_by_access_token_hash<'e, E>(
where
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
{
let token = db::get_by_access_token_hash(executor, access_token_hash)
let token = database::tokens::get_by_access_token_hash(executor, access_token_hash)
.await?
.map(decode)
.transpose()?;
@@ -25,7 +25,7 @@ pub async fn issue<'e, E>(executor: E, token: Token) -> Result<(), RepositoryErr
where
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
{
db::issue(executor, encode(token)).await?;
database::tokens::issue(executor, encode(token)).await?;
Ok(())
}
@@ -41,7 +41,7 @@ pub async fn rotate_refresh_token<'e, E>(
where
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
{
let rotated = db::rotate_refresh_token(
let rotated = database::tokens::rotate_refresh_token(
executor,
old_refresh_hash,
access_token_hash,
@@ -58,7 +58,7 @@ pub async fn revoke<'e, E>(executor: E, token_hash: &[u8]) -> Result<(), Reposit
where
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
{
db::revoke(executor, token_hash).await?;
database::tokens::revoke(executor, token_hash).await?;
Ok(())
}
+6 -6
View File
@@ -6,7 +6,7 @@ use super::{
encoding::{decode_direction, encode_direction},
};
use crate::{
database::{Constraint, DatabaseError, dtos::TransactionRow, transactions as db},
database::{self, Constraint, DatabaseError, dtos::TransactionRow},
domain::{Cents, Transaction},
};
@@ -23,7 +23,7 @@ pub async fn list<'e, E>(
where
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
{
let query = db::Query {
let query = database::transactions::Query {
limit: query
.limit
.map(|l| i64::try_from(l).map_err(|_| QueryConversionError::Limit(l)))
@@ -34,7 +34,7 @@ where
.transpose()?,
};
let transactions = db::list(executor, user_id, query)
let transactions = database::transactions::list(executor, user_id, query)
.await?
.into_iter()
.map(decode)
@@ -51,7 +51,7 @@ pub async fn get_by_id<'e, E>(
where
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
{
let transaction = db::get_by_id(executor, user_id, id)
let transaction = database::transactions::get_by_id(executor, user_id, id)
.await?
.map(decode)
.transpose()?;
@@ -67,7 +67,7 @@ pub async fn upsert<'e, E>(
where
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
{
let upserted = db::upsert(executor, user_id, encode(transaction))
let upserted = database::transactions::upsert(executor, user_id, encode(transaction))
.await
.map_err(classify_upsert_error)?
.map(|upserted| upserted.try_map(decode))
@@ -99,7 +99,7 @@ pub async fn delete_by_id<'e, E>(
where
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
{
let transaction = db::delete_by_id(executor, user_id, id)
let transaction = database::transactions::delete_by_id(executor, user_id, id)
.await?
.map(decode)
.transpose()?;
+7 -7
View File
@@ -4,7 +4,7 @@ use super::{
QueryConversionError, ReferenceRelation, ReferenceViolationKind, RepositoryError, dtos::Upsert,
};
use crate::{
database::{Constraint, DatabaseError, dtos::UserAppSecretRow, user_app_secrets as db},
database::{self, Constraint, DatabaseError, dtos::UserAppSecretRow},
domain::UserAppSecret,
repository::DecodeError,
};
@@ -23,7 +23,7 @@ pub async fn list<'e, E>(
where
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
{
let query = db::Query {
let query = database::user_app_secrets::Query {
limit: query
.limit
.map(|limit| i64::try_from(limit).map_err(|_| QueryConversionError::Limit(limit)))
@@ -34,7 +34,7 @@ where
.transpose()?,
};
let secrets = db::list(executor, user_id, app_id, query)
let secrets = database::user_app_secrets::list(executor, user_id, app_id, query)
.await?
.into_iter()
.map(decode)
@@ -52,7 +52,7 @@ pub async fn get_by_id<'e, E>(
where
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
{
let secret = db::get_by_id(executor, user_id, app_id, id)
let secret = database::user_app_secrets::get_by_id(executor, user_id, app_id, id)
.await?
.map(decode)
.transpose()?;
@@ -68,7 +68,7 @@ pub async fn upsert<'e, E>(
where
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
{
let secret = db::upsert(executor, user_id, encode(secret))
let secret = database::user_app_secrets::upsert(executor, user_id, encode(secret))
.await
.map_err(classify_upsert_error)?
.map(|upserted| upserted.try_map(decode))
@@ -100,7 +100,7 @@ pub async fn verify<'e, E>(
where
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
{
let is_valid = db::verify(executor, app_id, secret_hash).await?;
let is_valid = database::user_app_secrets::verify(executor, app_id, secret_hash).await?;
Ok(is_valid)
}
@@ -114,7 +114,7 @@ pub async fn delete_by_id<'e, E>(
where
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
{
let secret = db::delete_by_id(executor, user_id, app_id, id)
let secret = database::user_app_secrets::delete_by_id(executor, user_id, app_id, id)
.await?
.map(decode)
.transpose()?;
+7 -7
View File
@@ -2,7 +2,7 @@ use uuid::Uuid;
use super::{QueryConversionError, RepositoryError, dtos::Upsert};
use crate::{
database::{Constraint, DatabaseError, dtos::UserAppRow, user_apps as db},
database::{self, Constraint, DatabaseError, dtos::UserAppRow},
domain::UserApp,
repository::DecodeError,
};
@@ -20,7 +20,7 @@ pub async fn list<'e, E>(
where
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
{
let query = db::Query {
let query = database::user_apps::Query {
limit: query
.limit
.map(|limit| i64::try_from(limit).map_err(|_| QueryConversionError::Limit(limit)))
@@ -31,7 +31,7 @@ where
.transpose()?,
};
let apps = db::list(executor, user_id, query)
let apps = database::user_apps::list(executor, user_id, query)
.await?
.into_iter()
.map(decode)
@@ -48,7 +48,7 @@ pub async fn get_by_id<'e, E>(
where
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
{
let app = db::get_by_id(executor, user_id, id)
let app = database::user_apps::get_by_id(executor, user_id, id)
.await?
.map(decode)
.transpose()?;
@@ -63,7 +63,7 @@ pub async fn get_by_id_unscoped<'e, E>(
where
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
{
let app = db::get_by_id_unscoped(executor, id)
let app = database::user_apps::get_by_id_unscoped(executor, id)
.await?
.map(decode)
.transpose()?;
@@ -78,7 +78,7 @@ pub async fn upsert<'e, E>(
where
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
{
let app = db::upsert(executor, encode(app))
let app = database::user_apps::upsert(executor, encode(app))
.await
.map_err(classify_upsert_error)?
.map(|upserted| upserted.try_map(decode))
@@ -110,7 +110,7 @@ pub async fn delete_by_id<'e, E>(
where
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
{
let app = db::delete_by_id(executor, user_id, id)
let app = database::user_apps::delete_by_id(executor, user_id, id)
.await?
.map(decode)
.transpose()?;
+10 -7
View File
@@ -7,7 +7,7 @@ use super::{
dtos::Upsert,
};
use crate::{
database::{Constraint, DatabaseError, dtos::UserRow, users as db},
database::{self, Constraint, DatabaseError, dtos::UserRow},
domain::User,
};
@@ -20,7 +20,7 @@ pub async fn list<'e, E>(executor: E, query: Query) -> Result<Vec<User>, Reposit
where
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
{
let query = db::Query {
let query = database::users::Query {
limit: query
.limit
.map(|l| i64::try_from(l).map_err(|_| QueryConversionError::Limit(l)))
@@ -31,7 +31,7 @@ where
.transpose()?,
};
let users = db::list(executor, query)
let users = database::users::list(executor, query)
.await?
.into_iter()
.map(decode)
@@ -44,7 +44,10 @@ pub async fn get_by_id<'e, E>(executor: E, id: Uuid) -> Result<Option<User>, Rep
where
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
{
let user = db::get_by_id(executor, id).await?.map(decode).transpose()?;
let user = database::users::get_by_id(executor, id)
.await?
.map(decode)
.transpose()?;
Ok(user)
}
@@ -60,7 +63,7 @@ where
return Ok(HashMap::new());
}
let users = db::get_by_ids(executor, ids)
let users = database::users::get_by_ids(executor, ids)
.await?
.into_iter()
.map(decode)
@@ -75,7 +78,7 @@ pub async fn upsert<'e, E>(executor: E, user: User) -> Result<Upsert<User>, Repo
where
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
{
let user = db::upsert(executor, encode(user))
let user = database::users::upsert(executor, encode(user))
.await?
.try_map(decode)?
.into();
@@ -87,7 +90,7 @@ pub async fn delete_by_id<'e, E>(executor: E, id: Uuid) -> Result<Option<User>,
where
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
{
let user = db::delete_by_id(executor, id)
let user = database::users::delete_by_id(executor, id)
.await
.map_err(classify_delete_error)?
.map(decode)