Skip to main content

openauth_core/db/adapter/
capabilities.rs

1use serde::{Deserialize, Serialize};
2
3/// Database adapter capability metadata.
4#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
5pub struct AdapterCapabilities {
6    pub adapter_id: String,
7    pub adapter_name: Option<String>,
8    pub supports_numeric_ids: bool,
9    pub supports_uuid_ids: bool,
10    pub supports_json: bool,
11    pub supports_dates: bool,
12    pub supports_booleans: bool,
13    pub supports_arrays: bool,
14    pub supports_joins: bool,
15    pub supports_transactions: bool,
16    pub disable_id_generation: bool,
17}
18
19impl AdapterCapabilities {
20    pub fn new(adapter_id: impl Into<String>) -> Self {
21        Self {
22            adapter_id: adapter_id.into(),
23            adapter_name: None,
24            supports_numeric_ids: true,
25            supports_uuid_ids: false,
26            supports_json: false,
27            supports_dates: true,
28            supports_booleans: true,
29            supports_arrays: false,
30            supports_joins: false,
31            supports_transactions: false,
32            disable_id_generation: false,
33        }
34    }
35
36    pub fn named(mut self, adapter_name: impl Into<String>) -> Self {
37        self.adapter_name = Some(adapter_name.into());
38        self
39    }
40
41    pub fn without_numeric_ids(mut self) -> Self {
42        self.supports_numeric_ids = false;
43        self
44    }
45
46    pub fn with_uuid_ids(mut self) -> Self {
47        self.supports_uuid_ids = true;
48        self
49    }
50
51    pub fn with_json(mut self) -> Self {
52        self.supports_json = true;
53        self
54    }
55
56    pub fn without_dates(mut self) -> Self {
57        self.supports_dates = false;
58        self
59    }
60
61    pub fn without_booleans(mut self) -> Self {
62        self.supports_booleans = false;
63        self
64    }
65
66    pub fn with_arrays(mut self) -> Self {
67        self.supports_arrays = true;
68        self
69    }
70
71    pub fn with_joins(mut self) -> Self {
72        self.supports_joins = true;
73        self
74    }
75
76    pub fn with_transactions(mut self) -> Self {
77        self.supports_transactions = true;
78        self
79    }
80
81    pub fn without_id_generation(mut self) -> Self {
82        self.disable_id_generation = true;
83        self
84    }
85}
86
87/// Schema file content produced by an adapter or migration generator.
88#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
89pub struct SchemaCreation {
90    pub path: String,
91    pub code: String,
92    pub append: bool,
93    pub overwrite: bool,
94}
95
96impl SchemaCreation {
97    pub fn new(path: impl Into<String>, code: impl Into<String>) -> Self {
98        Self {
99            path: path.into(),
100            code: code.into(),
101            append: false,
102            overwrite: false,
103        }
104    }
105
106    pub fn append(mut self) -> Self {
107        self.append = true;
108        self
109    }
110
111    pub fn overwrite(mut self) -> Self {
112        self.overwrite = true;
113        self
114    }
115}