diff --git a/crates/configuration/src/introspection.rs b/crates/configuration/src/introspection.rs index 0f6550cc..734dcfa0 100644 --- a/crates/configuration/src/introspection.rs +++ b/crates/configuration/src/introspection.rs @@ -1,5 +1,6 @@ //! Configuration and state for our connector. use serde::Deserialize; +use ndc_models::TypeRepresentation; #[derive(Deserialize, Debug)] pub struct IntrospectStoredProcedureArgument { @@ -64,3 +65,30 @@ pub struct IntrospectionForeignKeyColumn { pub struct IntrospectionSchema { pub name: String, } + +pub fn map_type_representation(sql_type: &str) -> Option { + match sql_type.to_lowercase().as_str() { + "bigint" => Some(TypeRepresentation::Int64), + "bit" => Some(TypeRepresentation::Boolean), + "decimal" | "numeric" | "money" | "smallmoney" => Some(TypeRepresentation::BigDecimal), + "int" => Some(TypeRepresentation::Int32), + "smallint" => Some(TypeRepresentation::Int16), + "tinyint" => Some(TypeRepresentation::Int16), + "float" => Some(TypeRepresentation::Float64), + "real" => Some(TypeRepresentation::Float32), + "date" => Some(TypeRepresentation::Date), + "datetime" | "datetime2" | "smalldatetime" | "timestamp" => Some(TypeRepresentation::Timestamp), + "datetimeoffset" => Some(TypeRepresentation::TimestampTZ), + "time" => Some(TypeRepresentation::String), + "char" | "varchar" | "text" | "nchar" | "nvarchar" | "ntext" => Some(TypeRepresentation::String), + "binary" | "varbinary" | "image" => Some(TypeRepresentation::String), + "uniqueidentifier" => Some(TypeRepresentation::UUID), + "xml" => Some(TypeRepresentation::String), + "geometry" => Some(TypeRepresentation::Geometry), + "geography" => Some(TypeRepresentation::Geography), + "json" => Some(TypeRepresentation::JSON), + // TODO: Add support for hierarchyid and sql_variant + // "hierarchyid" | "sql_variant" => XXX, + _ => None, + } +} diff --git a/crates/ndc-sqlserver/src/schema.rs b/crates/ndc-sqlserver/src/schema.rs index 8d8ecab7..612a7a98 100644 --- a/crates/ndc-sqlserver/src/schema.rs +++ b/crates/ndc-sqlserver/src/schema.rs @@ -12,9 +12,8 @@ use ndc_sdk::models::ObjectTypeName; use ndc_sdk::models::ProcedureName; use ndc_sdk::models::ScalarTypeName; use ndc_sdk::models::TypeRepresentation; -use query_engine_metadata::metadata; - use ndc_sqlserver_configuration as configuration; +use query_engine_metadata::metadata; use query_engine_metadata::metadata::stored_procedures::{ StoredProcedureArgumentInfo, StoredProcedures, }; @@ -308,8 +307,9 @@ pub fn get_schema( ( scalar_type.0.clone().into(), models::ScalarType { - // TODO(PY): Add representation for beta - representation: None, + representation: configuration::introspection::map_type_representation( + scalar_type.0.as_str(), + ), aggregate_functions: metadata .aggregate_functions .0