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
use crate::env_utils; | |
use sqlx::postgres::{PgConnectOptions, PgPoolOptions}; | |
use sqlx::{ConnectOptions, Pool, Postgres}; | |
pub async fn open_connection() -> Pool<Postgres> { | |
let options = PgConnectOptions::new() | |
.host(env_utils::as_string("DB_HOST").as_str()) | |
.port(env_utils::as_u16("DB_PORT")) | |
.database(env_utils::as_string("DB_DATABASE").as_str()) | |
.username(env_utils::as_string("DB_USERNAME").as_str()) |
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
use std::env; | |
pub fn as_string(key: &str) -> String { | |
String::from( | |
env::var(key) | |
.expect(format!("{} should be set", key).as_str()) | |
.as_str(), | |
) | |
} |
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 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()) |
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 async fn open_connection() -> Pool<Postgres> { | |
let options = PgConnectOptions::new() | |
.host(env::var("DB_HOST").expect("DB_HOST should be set").as_str()) | |
.port(env::var("DB_PORT").expect("DB_PORT should be set").parse().expect("DB_PORT should be a valid u16 value")) | |
.database(env::var("DB_DATABASE").expect("DB_DATABASE should be set").as_str()) | |
.username(env::var("DB_USERNAME").expect("DB_USERNAME should be set").as_str()) | |
.password(env::var("DB_PASSWORD").expect("DB_PASSWORD should be set").as_str()) | |
.disable_statement_logging() | |
.clone(); |
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
... | |
#[tokio::main] | |
pub async fn read() { | |
let pool = db_handler::open_connection().await; | |
let mut cursor = None; | |
loop { | |
cursor = execute_and_get_cursor(cursor, &pool).await; | |
if cursor.is_none() { | |
break; |
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
CREATE table mint | |
( | |
transaction_id integer PRIMARY KEY, | |
status varchar(50), | |
wallet varchar(255), | |
token_type varchar(15), | |
token_id varchar(15), | |
minted_on timestamp | |
); |
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
use log::{error, info}; | |
use serde::de::DeserializeOwned; | |
use crate::model::mint::Mint; | |
const MINTS_URL: &str = "https://api.x.immutable.com/v1/mints?token_address=0x9e0d99b864e1ac12565125c5a82b59adea5a09cd&page_size=200"; | |
#[tokio::main] | |
pub async fn read() { | |
let mut cursor = None; |
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
use serde::{Deserialize}; | |
#[derive(Deserialize, Debug)] | |
pub struct Mint { | |
pub result: Vec<TheResult>, | |
pub cursor: String, | |
} | |
#[derive(Deserialize, Debug)] | |
pub struct TheResult { |
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
services: | |
db: | |
image: postgres:15.3 | |
restart: 'no' | |
environment: | |
POSTGRES_PASSWORD: notsecure | |
POSTGRES_USER: data-loader-local | |
POSTGRES_DB: illuvium-land | |
ports: | |
- '5432:5432' |
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
#!/bin/bash | |
SCRIPT_PATH=$(dirname $(realpath -s $0)) | |
echo "Stopping environment..." | |
docker-compose -p data-loader -f $SCRIPT_PATH/docker-compose.yaml down |