use sea_orm::entity::prelude::*;
use crate::database::enums::AssetSchema;
#[derive(Copy, Clone, Default, Debug, DeriveEntity)]
pub struct Entity;
impl EntityName for Entity {
fn table_name(&self) -> &str {
"asset"
}
}
#[derive(Clone, Debug, PartialEq, DeriveModel, DeriveActiveModel, Eq)]
pub struct Model {
pub idx: i32,
pub asset_id: String,
pub schema: AssetSchema,
pub added_at: i64,
pub description: Option<String>,
pub issued_supply: String,
pub name: String,
pub precision: u8,
pub ticker: Option<String>,
pub timestamp: i64,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)]
pub enum Column {
Idx,
AssetId,
Schema,
AddedAt,
Description,
IssuedSupply,
Name,
Precision,
Ticker,
Timestamp,
}
#[derive(Copy, Clone, Debug, EnumIter, DerivePrimaryKey)]
pub enum PrimaryKey {
Idx,
}
impl PrimaryKeyTrait for PrimaryKey {
type ValueType = i32;
fn auto_increment() -> bool {
true
}
}
#[derive(Copy, Clone, Debug, EnumIter)]
pub enum Relation {
AssetTransfer,
}
impl ColumnTrait for Column {
type EntityName = Entity;
fn def(&self) -> ColumnDef {
match self {
Self::Idx => ColumnType::Integer.def(),
Self::AssetId => ColumnType::String(None).def().unique(),
Self::Schema => ColumnType::SmallInteger.def(),
Self::AddedAt => ColumnType::BigInteger.def(),
Self::Description => ColumnType::String(None).def().null(),
Self::IssuedSupply => ColumnType::String(None).def(),
Self::Name => ColumnType::String(None).def(),
Self::Precision => ColumnType::SmallInteger.def(),
Self::Ticker => ColumnType::String(None).def().null(),
Self::Timestamp => ColumnType::BigInteger.def(),
}
}
}
impl RelationTrait for Relation {
fn def(&self) -> RelationDef {
match self {
Self::AssetTransfer => Entity::has_many(super::asset_transfer::Entity).into(),
}
}
}
impl Related<super::asset_transfer::Entity> for Entity {
fn to() -> RelationDef {
Relation::AssetTransfer.def()
}
}
impl ActiveModelBehavior for ActiveModel {}