risingwave_meta_model/
connection.rsuse risingwave_pb::catalog::connection::PbInfo;
use risingwave_pb::catalog::PbConnection;
use sea_orm::entity::prelude::*;
use sea_orm::ActiveValue::Set;
use serde::{Deserialize, Serialize};
use crate::{ConnectionId, PrivateLinkService};
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
#[sea_orm(table_name = "connection")]
pub struct Model {
#[sea_orm(primary_key, auto_increment = false)]
pub connection_id: ConnectionId,
pub name: String,
pub info: PrivateLinkService,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
#[sea_orm(
belongs_to = "super::object::Entity",
from = "Column::ConnectionId",
to = "super::object::Column::Oid",
on_update = "NoAction",
on_delete = "Cascade"
)]
Object,
#[sea_orm(has_many = "super::sink::Entity")]
Sink,
#[sea_orm(has_many = "super::source::Entity")]
Source,
}
impl Related<super::object::Entity> for Entity {
fn to() -> RelationDef {
Relation::Object.def()
}
}
impl Related<super::sink::Entity> for Entity {
fn to() -> RelationDef {
Relation::Sink.def()
}
}
impl Related<super::source::Entity> for Entity {
fn to() -> RelationDef {
Relation::Source.def()
}
}
impl ActiveModelBehavior for ActiveModel {}
impl From<PbConnection> for ActiveModel {
fn from(conn: PbConnection) -> Self {
let Some(PbInfo::PrivateLinkService(private_link_srv)) = conn.info else {
unreachable!("private link not provided.")
};
Self {
connection_id: Set(conn.id as _),
name: Set(conn.name),
info: Set(PrivateLinkService::from(&private_link_srv)),
}
}
}