taler-rust

GNU Taler code in Rust. Largely core banking integrations.
Log | Files | Refs | Submodules | README | LICENSE

commit d8e5f800f6adcb43822c779d71f8187003841217
parent 49ab96d9442c6f4f619e65381a3941c860f70a1a
Author: Antoine A <>
Date:   Wed,  4 Dec 2024 16:22:35 +0100

utils: db get amount using column index

Diffstat:
Mtaler-api/src/db/type_helper.rs | 8++++++++
1 file changed, 8 insertions(+), 0 deletions(-)

diff --git a/taler-api/src/db/type_helper.rs b/taler-api/src/db/type_helper.rs @@ -50,6 +50,7 @@ pub trait SqlTypeHelper { self.try_get_map(index, Url::parse) } fn try_get_amount(&self, index: &str, currency: &str) -> sqlx::Result<Amount>; + fn try_get_amount_i(&self, index: usize, currency: &str) -> sqlx::Result<Amount>; } impl SqlTypeHelper for PgRow { @@ -82,4 +83,11 @@ impl SqlTypeHelper for PgRow { Ok(Amount::new(currency, val as u64, frac as u32)) } + + fn try_get_amount_i(&self, index: usize, currency: &str) -> sqlx::Result<Amount> { + let val: i64 = self.try_get(index)?; + let frac: i32 = self.try_get(index + 1)?; + + Ok(Amount::new(currency, val as u64, frac as u32)) + } }