use rs_orm::{ model::{ field::{Field, FieldType, FkNo}, relation::ForeignKey, Meta, Model, }, query, }; //#[orm_meta(table_name = "core_user", table_pref = "core")] struct Author { //#[orm_field(name = "uid", pk = "true", db_type = "int unsign")] id: Option, //#[orm_field(db_type = "varchar", max_lenth = "60")] name: String, } impl Model for Author { /// 表主键字段类型 type PkType = u32; /// 表定义信息 const META: Meta = Meta { table_name: "core_author", field_list: &[ Field { name: "id", date_type: FieldType::Number, max_length: None, pk: true, auto_increment: true, remark: Some("作者编号"), fk_model_no: None, null: false, }, Field { name: "name", date_type: FieldType::Text, max_length: None, pk: false, auto_increment: false, remark: Some("作者姓名"), fk_model_no: None, null: false, }, ], }; // 无外键1 type FkModel1=(); // 无外键2 type FkModel2=(); // 无外键3 type FkModel3=(); // 无外键4 type FkModel4=(); // 无外键5 type FkModel5=(); // 无外键6 type FkModel6=(); // 无外键7 type FkModel7=(); // 无外键8 type FkModel8=(); // 无外键9 type FkModel9=(); // 无外键10 type FkModel10=(); } struct Book { //#[orm_field(pk = true)] id: Option, //#[orm_field(db_type = "varchar", max_lenth = "60")] name: String, //#[orm_foreign(name = "author", null = "true", related_name = "book_authors")] author: Option>, } impl Model for Book { /// 表主键字段类型 type PkType = u32; /// 表定义信息 const META: Meta = Meta { table_name: "core_book", field_list: &[ Field { name: "id", date_type: FieldType::Number, max_length: None, pk: true, auto_increment: true, remark: Some("图书编号"), fk_model_no: None, null: false, }, Field { name: "name", date_type: FieldType::Text, max_length: Some(30), pk: false, auto_increment: false, remark: Some("图书名称"), fk_model_no: None, null: false, }, Field { name: "author_id", date_type: FieldType::Number, max_length: None, pk: true, auto_increment: false, remark: Some("图书作者"), fk_model_no: Some(FkNo::One), null: true, }, ], }; // 外键1,为作者 type FkModel1=Author; // 无外键2 type FkModel2=(); // 无外键3 type FkModel3=(); // 无外键4 type FkModel4=(); // 无外键5 type FkModel5=(); // 无外键6 type FkModel6=(); // 无外键7 type FkModel7=(); // 无外键8 type FkModel8=(); // 无外键9 type FkModel9=(); // 无外键10 type FkModel10=(); } #[test] fn test_author() { //let authors:Vec = Author::META::filter(&conn,query!(name__like="hy"))?; }