Skip to content

Instantly share code, notes, and snippets.

@Enigo
Created February 2, 2023 03:47
Show Gist options
  • Save Enigo/1666750e41d51c1cfdc245578086eeaa to your computer and use it in GitHub Desktop.
Save Enigo/1666750e41d51c1cfdc245578086eeaa to your computer and use it in GitHub Desktop.
pub struct MintSaver;
#[async_trait]
impl Persistable<Mint> for MintSaver {
async fn persist_one(&self, mint: &Mint, pool: &Pool<Postgres>) {
let mint_result = &mint.result;
let mut query_builder: QueryBuilder<Postgres> = QueryBuilder::new(
"insert into mint (transaction_id, status, wallet, token_type, token_id, minted_on) ",
);
query_builder.push_values(mint_result, |mut builder, res| {
builder
.push_bind(res.transaction_id)
.push_bind(res.status.clone())
.push_bind(res.wallet.clone())
.push_bind(res.token.the_type.clone())
.push_bind(res.token.data.token_id.parse::<i32>().unwrap())
.push_bind(DateTime::parse_from_rfc3339(&res.minted_on).unwrap());
});
let query = query_builder.build();
match query.execute(pool).await {
Ok(result) => {
info!("Inserted {} rows", result.rows_affected())
}
Err(e) => {
error!("Couldn't insert values due to {}", e)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment