br_addon/module.rs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
use std::any::type_name;
use json::{array, object, JsonValue};
use crate::action::{Action};
/// 模型配置
pub trait Module {
/// =================基础配置=============================
/// 插件名称
fn name(&self) -> String {
type_name::<Self>().split("::").collect::<Vec<&str>>()[3].to_lowercase()
}
/// 功能标题
fn title(&self) -> String;
/// 描述
fn description(&self) -> String { "".into() }
/// =================视图配置=============================
/// 模型icon
fn icon(&self) -> String {
String::new()
}
/// =================数据库配置=============================
/// 是否数据表
fn table(&self) -> bool { false }
/// 数据库表名称
fn table_name(&self) -> String {
let t = type_name::<Self>().split("::").collect::<Vec<&str>>();
format!("{}_{}", t[2], t[3])
}
/// 主键
fn table_key(&mut self) -> String {
"id".into()
}
/// 唯一索引
fn table_unique(&self) -> Vec<String> { vec![] }
/// 查询索引
fn table_index(&mut self) -> Vec<Vec<String>> {
vec![]
}
/// 是否分区
fn table_partition(&mut self) -> bool {
false
}
/// 分区配置
/// *列名
/// *分区key
/// *实例 array![str, array![range1, range2, range3...]]
/// *如果在已有分区的情况下想要修改分区的参照列,先要将当前分区代码删除后刷库,然后写新的分区规则再刷库
fn table_partition_columns(&mut self) -> JsonValue {
array![]
}
/// =================功能配置=============================
/// 加载功能
/// * name 功能名称
fn action(&mut self, name: &str) -> Result<Box<dyn Action>, String>;
/// 模型字段
fn fields(&mut self) -> JsonValue {
object! {}
}
}