drasi_bootstrap_sqlite/
descriptor.rs1use crate::{SqliteBootstrapProvider, TableKeyConfig};
18use drasi_plugin_sdk::prelude::*;
19use utoipa::OpenApi;
20
21#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, utoipa::ToSchema)]
25#[schema(as = bootstrap::sqlite::SqliteBootstrapConfig)]
26#[serde(rename_all = "camelCase", deny_unknown_fields)]
27pub struct SqliteBootstrapConfigDto {
28 #[serde(default)]
30 #[schema(value_type = Option<ConfigValueString>)]
31 pub path: Option<ConfigValue<String>>,
32
33 #[serde(default)]
35 pub tables: Option<Vec<String>>,
36
37 #[serde(default)]
39 #[schema(value_type = Vec<bootstrap::sqlite::TableKeyConfig>)]
40 pub table_keys: Vec<TableKeyConfigDto>,
41}
42
43#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, utoipa::ToSchema)]
45#[schema(as = bootstrap::sqlite::TableKeyConfig)]
46#[serde(rename_all = "camelCase", deny_unknown_fields)]
47pub struct TableKeyConfigDto {
48 pub table: String,
49 pub key_columns: Vec<String>,
50}
51
52#[derive(OpenApi)]
55#[openapi(components(schemas(SqliteBootstrapConfigDto, TableKeyConfigDto,)))]
56struct SqliteBootstrapSchemas;
57
58pub struct SqliteBootstrapDescriptor;
62
63#[async_trait]
64impl BootstrapPluginDescriptor for SqliteBootstrapDescriptor {
65 fn kind(&self) -> &str {
66 "sqlite"
67 }
68
69 fn config_version(&self) -> &str {
70 "1.0.0"
71 }
72
73 fn config_schema_name(&self) -> &str {
74 "bootstrap.sqlite.SqliteBootstrapConfig"
75 }
76
77 fn config_schema_json(&self) -> String {
78 let api = SqliteBootstrapSchemas::openapi();
79 serde_json::to_string(
80 &api.components
81 .as_ref()
82 .expect("OpenAPI components missing")
83 .schemas,
84 )
85 .expect("Failed to serialize config schema")
86 }
87
88 async fn create_bootstrap_provider(
89 &self,
90 config_json: &serde_json::Value,
91 _source_config_json: &serde_json::Value,
92 ) -> anyhow::Result<Box<dyn drasi_lib::bootstrap::BootstrapProvider>> {
93 let dto: SqliteBootstrapConfigDto = serde_json::from_value(config_json.clone())?;
94 let mapper = DtoMapper::new();
95
96 let mut builder = SqliteBootstrapProvider::builder();
97
98 if let Some(path_cv) = &dto.path {
99 builder = builder.with_path(mapper.resolve_string(path_cv).await?);
100 }
101
102 if let Some(tables) = dto.tables {
103 builder = builder.with_tables(tables);
104 }
105
106 let table_keys = dto
107 .table_keys
108 .into_iter()
109 .map(|tk| TableKeyConfig {
110 table: tk.table,
111 key_columns: tk.key_columns,
112 })
113 .collect::<Vec<_>>();
114
115 if !table_keys.is_empty() {
116 builder = builder.with_table_keys(table_keys);
117 }
118
119 Ok(Box::new(builder.build()))
120 }
121}