Skip to main content

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