/
rorikstr
/
multiberry-backend
Обзор
Документация
Войти
/
rorikstr
/
multiberry-backend
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
develop
src/db/balances.rs
52 строки
1 KB
Rorik Star Platinum
(feat) balance
07 ноя 2025, 21:22
07 ноя 2025, 21:22
aeb9514
Код
Авторство
О чём код?
// src/db/balances.rs use sqlx::PgPool; use chrono::{DateTime, Utc}; pub async fn store_balance( pool: &PgPool, account_id: &str, balance_type: &str, amount: &str, currency: &str, date_time: DateTime<Utc>, ) -> Result<(), sqlx::Error> { sqlx::query!( r#" INSERT INTO balances (account_id, balance_type, amount, currency, date_time) VALUES ($1, $2, $3, $4, $5) ON CONFLICT (account_id, balance_type) DO UPDATE SET amount = $3, date_time = $5 "#, account_id, balance_type, amount, currency, date_time, ) .execute(pool) .await?; Ok(()) } pub async fn get_balance( pool: &PgPool, account_id: &str, ) -> Result<Option<(String, String, String)>, sqlx::Error> { // Returns (amount, currency, balance_type) sqlx::query!( r#" SELECT amount, currency, balance_type FROM balances WHERE account_id = $1 ORDER BY date_time DESC LIMIT 1 "#, account_id ) .fetch_optional(pool) .await .map(|row| row.map(|r| (r.amount, r.currency, r.balance_type))) }