data_modelling_sdk/import/
mod.rs

1//! Import functionality
2//!
3//! Provides parsers for importing data models from various formats:
4//! - SQL (CREATE TABLE statements)
5//! - ODCS (Open Data Contract Standard) v3.1.0 YAML format (legacy ODCL formats supported for import)
6//! - JSON Schema
7//! - AVRO
8//! - Protobuf
9
10pub mod avro;
11#[cfg(feature = "bpmn")]
12pub mod bpmn;
13pub mod cads;
14#[cfg(feature = "dmn")]
15pub mod dmn;
16pub mod json_schema;
17pub mod odcl;
18pub mod odcs;
19pub mod odcs_shared;
20pub mod odps;
21#[cfg(feature = "openapi")]
22pub mod openapi;
23pub mod protobuf;
24pub mod sql;
25
26// anyhow::Result not currently used in this module
27
28/// Result of an import operation.
29///
30/// Contains extracted tables and any errors/warnings from the import process.
31#[derive(Debug, serde::Serialize, serde::Deserialize)]
32#[must_use = "import results should be processed or errors checked"]
33pub struct ImportResult {
34    /// Tables extracted from the import
35    pub tables: Vec<TableData>,
36    /// Tables that require name input (for SQL imports with unnamed tables)
37    pub tables_requiring_name: Vec<TableRequiringName>,
38    /// Parse errors/warnings
39    pub errors: Vec<ImportError>,
40    /// Whether AI suggestions are available
41    pub ai_suggestions: Option<Vec<serde_json::Value>>,
42}
43
44/// Error during import
45#[derive(Debug, thiserror::Error, serde::Serialize, serde::Deserialize)]
46pub enum ImportError {
47    #[error("Parse error: {0}")]
48    ParseError(String),
49    #[error("Validation error: {0}")]
50    ValidationError(String),
51    #[error("IO error: {0}")]
52    IoError(String),
53    #[error("BPMN validation error: {0}")]
54    BPMNValidationError(String),
55    #[error("DMN validation error: {0}")]
56    DMNValidationError(String),
57    #[error("OpenAPI validation error: {0}")]
58    OpenAPIValidationError(String),
59    #[error("BPMN parse error: {0}")]
60    BPMNParseError(String),
61    #[error("DMN parse error: {0}")]
62    DMNParseError(String),
63    #[error("OpenAPI parse error: {0}")]
64    OpenAPIParseError(String),
65}
66
67/// Table data from import
68#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
69pub struct TableData {
70    pub table_index: usize,
71    pub name: Option<String>,
72    pub columns: Vec<ColumnData>,
73    // Additional fields can be added as needed
74}
75
76/// Column data from import
77#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
78pub struct ColumnData {
79    pub name: String,
80    pub data_type: String,
81    /// Physical type - the actual database type (e.g., "DOUBLE", "VARCHAR(100)")
82    /// For ODCS this maps to physicalType. Optional as not all formats distinguish logical/physical types.
83    #[serde(skip_serializing_if = "Option::is_none")]
84    pub physical_type: Option<String>,
85    pub nullable: bool,
86    pub primary_key: bool,
87    /// Column description/documentation (from ODCS/ODCL description field)
88    #[serde(skip_serializing_if = "Option::is_none")]
89    pub description: Option<String>,
90    /// Quality rules and validation checks (from ODCS/ODCL quality array)
91    #[serde(skip_serializing_if = "Option::is_none")]
92    pub quality: Option<Vec<std::collections::HashMap<String, serde_json::Value>>>,
93    /// ODCS v3.1.0 relationships (property-level references)
94    /// All $ref values are converted to relationships on import
95    #[serde(default, skip_serializing_if = "Vec::is_empty")]
96    pub relationships: Vec<crate::models::PropertyRelationship>,
97    /// Enum values if this column is an enumeration type
98    #[serde(skip_serializing_if = "Option::is_none")]
99    pub enum_values: Option<Vec<String>>,
100}
101
102// Re-export for convenience
103pub use avro::AvroImporter;
104pub use cads::CADSImporter;
105pub use json_schema::JSONSchemaImporter;
106pub use odcl::ODCLImporter;
107pub use odcs::ODCSImporter;
108pub use odcs_shared::ParserError;
109pub use odps::ODPSImporter;
110pub use protobuf::ProtobufImporter;
111pub use sql::SQLImporter;
112
113/// Table requiring name input (for SQL imports)
114#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
115pub struct TableRequiringName {
116    pub table_index: usize,
117    pub suggested_name: Option<String>,
118}