/
rorikstr
/
multiberry-backend
Обзор
Документация
Войти
/
rorikstr
/
multiberry-backend
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
develop
src/db/accounts.rs
62 строки
1 KB
Rorik Star Platinum
finish 30% lol
09 ноя 2025, 21:03
09 ноя 2025, 21:03
ea863ad
Код
Авторство
О чём код?
// src/db/accounts.rs use sqlx::PgPool; use chrono::NaiveDate; pub async fn store_account( pool: &PgPool, account_id: &str, user_id: &str, bank_code: &str, status: &str, currency: &str, account_type: &str, account_sub_type: Option<&str>, nickname: &str, description: Option<&str>, opening_date: Option<NaiveDate>, ) -> Result<(), sqlx::Error> { sqlx::query!( r#" INSERT INTO accounts (account_id, user_id, bank_code, status, currency, account_type, account_sub_type, nickname, description, opening_date) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10) ON CONFLICT (account_id, bank_code) DO UPDATE SET updated_at = NOW() "#, account_id, user_id, bank_code, status, currency, account_type, account_sub_type, nickname, description, opening_date ) .execute(pool) .await?; Ok(()) } pub async fn get_accounts_for_user( pool: &PgPool, user_id: &str, bank_code: &str, ) -> Result<Vec<(String, String)>, sqlx::Error> { sqlx::query!( r#" SELECT account_id, nickname FROM accounts WHERE user_id = $1 AND bank_code = $2 "#, user_id, bank_code ) .fetch_all(pool) .await .map(|rows| rows.into_iter().map(|r| (r.account_id, r.nickname)).collect()) }