risingwave_meta_model/
view.rs1use risingwave_pb::catalog::PbView;
16use sea_orm::ActiveValue::Set;
17use sea_orm::entity::prelude::*;
18use serde::{Deserialize, Serialize};
19
20use crate::{FieldArray, Property, ViewId};
21
22#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
23#[sea_orm(table_name = "view")]
24pub struct Model {
25 #[sea_orm(primary_key, auto_increment = false)]
26 pub view_id: ViewId,
27 pub name: String,
28 pub properties: Property,
29 pub definition: String,
30 pub columns: FieldArray,
31}
32
33#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
34pub enum Relation {
35 #[sea_orm(
36 belongs_to = "super::object::Entity",
37 from = "Column::ViewId",
38 to = "super::object::Column::Oid",
39 on_update = "NoAction",
40 on_delete = "Cascade"
41 )]
42 Object,
43}
44
45impl Related<super::object::Entity> for Entity {
46 fn to() -> RelationDef {
47 Relation::Object.def()
48 }
49}
50
51impl ActiveModelBehavior for ActiveModel {}
52
53impl From<PbView> for ActiveModel {
54 fn from(view: PbView) -> Self {
55 Self {
56 view_id: Set(view.id as _),
57 name: Set(view.name),
58 properties: Set(Property(view.properties)),
59 definition: Set(view.sql),
60 columns: Set(view.columns.into()),
61 }
62 }
63}