Created
February 2, 2023 03:47
-
-
Save Enigo/63466720ba875d21d5c4ce94816509e8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pub struct AssetSaver; | |
#[async_trait] | |
impl Persistable<Asset> for AssetSaver { | |
async fn persist_one(&self, asset: &Asset, pool: &Pool<Postgres>) { | |
let asset_result = &asset.result; | |
let mut query_builder: QueryBuilder<Postgres> = QueryBuilder::new( | |
"insert into asset (token_id, token_address, name, tier, solon, carbon, crypton, silicon, hydrogen, hyperion, landmark) ", | |
); | |
query_builder.push_values(asset_result, |mut builder, res| { | |
builder | |
.push_bind(res.token_id.parse::<i32>().unwrap()) | |
.push_bind(res.token_address.clone()) | |
.push_bind(res.metadata.name.clone()) | |
.push_bind(res.metadata.tier) | |
.push_bind(res.metadata.solon) | |
.push_bind(res.metadata.carbon) | |
.push_bind(res.metadata.crypton) | |
.push_bind(res.metadata.silicon) | |
.push_bind(res.metadata.hydrogen) | |
.push_bind(res.metadata.hyperion) | |
.push_bind(res.metadata.landmark.clone()); | |
}); | |
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