openauth_core/plugin/
schema.rs1use crate::db::{DbField, DbSchema, DbTable};
4use crate::error::OpenAuthError;
5
6#[derive(Debug, Clone, PartialEq, Eq)]
8pub enum PluginSchemaContribution {
9 Table {
10 logical_name: String,
11 table: DbTable,
12 },
13 Field {
14 table: String,
15 logical_name: String,
16 field: DbField,
17 },
18}
19
20impl PluginSchemaContribution {
21 pub fn table(logical_name: impl Into<String>, table: DbTable) -> Self {
22 Self::Table {
23 logical_name: logical_name.into(),
24 table,
25 }
26 }
27
28 pub fn field(
29 table: impl Into<String>,
30 logical_name: impl Into<String>,
31 field: DbField,
32 ) -> Self {
33 Self::Field {
34 table: table.into(),
35 logical_name: logical_name.into(),
36 field,
37 }
38 }
39
40 pub fn apply(&self, schema: &mut DbSchema) -> Result<(), OpenAuthError> {
41 match self {
42 Self::Table {
43 logical_name,
44 table,
45 } => schema.insert_plugin_table(logical_name.clone(), table.clone()),
46 Self::Field {
47 table,
48 logical_name,
49 field,
50 } => schema.insert_plugin_field(table, logical_name.clone(), field.clone()),
51 }
52 }
53}