Skip to content

Instantly share code, notes, and snippets.

@Enigo
Created January 23, 2023 11:00
Show Gist options
  • Save Enigo/9fef50b4fbcd28ccec54bf66cc3a0360 to your computer and use it in GitHub Desktop.
Save Enigo/9fef50b4fbcd28ccec54bf66cc3a0360 to your computer and use it in GitHub Desktop.
pub async fn save_mints(mint_result: Vec<TheResult>, connection: &Pool<Postgres>) {
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.clone())
.push_bind(DateTime::parse_from_rfc3339(&res.minted_on).unwrap());
});
let query = query_builder.build();
match query.execute(connection)
.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