Issue with D1 types when using Rust

Issue I'm trying to query from my D1 database. Using wrangler, I know that my query is correct. It returns expected values. However, when attempting to query within my Rust code, I find that there is an issue with a specific item: total_tokens. Here is the struct that I attempt to serialize the data into:
#[derive(Deserialize, Serialize)]
struct LiquidityForward {
contract_addr: String,
token_name: String,
token_sym: String,
decimals: u32,
total_usd: f32,
total_tokens: u128, // Likes to give an error :(
number_of_transfers: u32
}
#[derive(Deserialize, Serialize)]
struct LiquidityForward {
contract_addr: String,
token_name: String,
token_sym: String,
decimals: u32,
total_usd: f32,
total_tokens: u128, // Likes to give an error :(
number_of_transfers: u32
}
Here is my request:
let d1 = ctx.env.d1("DB")?;
let statement = worker::query!(
&d1,
"
SELECT
t.contract_addr,
t.token_name,
t.token_sym,
t.decimals,
SUM(tf.usd) AS total_usd,
SUM(tf.token_count) AS total_tokens,
COUNT(tf.token_addr) AS number_of_transfers
FROM Token AS t
INNER JOIN TransfersForward AS tf ON t.contract_addr = tf.token_addr
GROUP BY t.contract_addr, t.token_name, t.token_sym, t.decimals
"
);

let result = statement.all().await?;

if !result.success() {
return Response::error(
result.error().unwrap_or("No error given".to_string()),
500,
);
}
let d1 = ctx.env.d1("DB")?;
let statement = worker::query!(
&d1,
"
SELECT
t.contract_addr,
t.token_name,
t.token_sym,
t.decimals,
SUM(tf.usd) AS total_usd,
SUM(tf.token_count) AS total_tokens,
COUNT(tf.token_addr) AS number_of_transfers
FROM Token AS t
INNER JOIN TransfersForward AS tf ON t.contract_addr = tf.token_addr
GROUP BY t.contract_addr, t.token_name, t.token_sym, t.decimals
"
);

let result = statement.all().await?;

if !result.success() {
return Response::error(
result.error().unwrap_or("No error given".to_string()),
500,
);
}
Whenever I remove the total_tokens value from the LiquidityForward struct, it returns fine with expected data. It can't seem to understand the result with either a u128, u64, u32, or String type. What should I be using? Environment - worker = { version = "0.0.18", features = ["d1"] } - Rust
No description
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server