pub mod virtuals_pool_row;
pub use self::virtuals_pool_row::*;
use super::VirtualsAccount;
pub struct VirtualsAccountsMigration;
impl sqlx_migrator::Migration<sqlx::Postgres> for VirtualsAccountsMigration {
fn app(&self) -> &str {
"virtuals"
}
fn name(&self) -> &str {
"virtuals_accounts"
}
fn operations(&self) -> Vec<Box<dyn sqlx_migrator::Operation<sqlx::Postgres>>> {
vec![Box::new(VirtualsPoolMigrationOperation)]
}
fn parents(&self) -> Vec<Box<dyn sqlx_migrator::Migration<sqlx::Postgres>>> {
vec![]
}
}
pub struct VirtualsAccountWithMetadata(
pub VirtualsAccount,
pub carbon_core::account::AccountMetadata,
);
impl From<(VirtualsAccount, carbon_core::account::AccountMetadata)>
for VirtualsAccountWithMetadata
{
fn from(value: (VirtualsAccount, carbon_core::account::AccountMetadata)) -> Self {
VirtualsAccountWithMetadata(value.0, value.1)
}
}
#[async_trait::async_trait]
impl carbon_core::postgres::operations::Insert for VirtualsAccountWithMetadata {
async fn insert(&self, pool: &sqlx::PgPool) -> carbon_core::error::CarbonResult<()> {
let VirtualsAccountWithMetadata(account, metadata) = self;
match account {
VirtualsAccount::VirtualsPool(account) => {
let row = virtuals_pool_row::VirtualsPoolRow::from_parts(
*account.clone(),
metadata.clone(),
);
row.insert(pool).await?;
Ok(())
}
}
}
}
#[async_trait::async_trait]
impl carbon_core::postgres::operations::Upsert for VirtualsAccountWithMetadata {
async fn upsert(&self, pool: &sqlx::PgPool) -> carbon_core::error::CarbonResult<()> {
let VirtualsAccountWithMetadata(account, metadata) = self;
match account {
VirtualsAccount::VirtualsPool(account) => {
let row = virtuals_pool_row::VirtualsPoolRow::from_parts(
*account.clone(),
metadata.clone(),
);
row.upsert(pool).await?;
Ok(())
}
}
}
}