Skip to content

Commit

Permalink
First pass at quick schema representation
Browse files Browse the repository at this point in the history
  • Loading branch information
codedmart committed Dec 12, 2024
1 parent 915b1a6 commit 8b71c9b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
28 changes: 28 additions & 0 deletions crates/configuration/src/introspection.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! Configuration and state for our connector.

Check warning on line 1 in crates/configuration/src/introspection.rs

View workflow job for this annotation

GitHub Actions / cargo fmt

Diff in /home/runner/work/ndc-sqlserver/ndc-sqlserver/crates/configuration/src/introspection.rs
use serde::Deserialize;
use ndc_models::TypeRepresentation;

#[derive(Deserialize, Debug)]
pub struct IntrospectStoredProcedureArgument {
Expand Down Expand Up @@ -64,3 +65,30 @@ pub struct IntrospectionForeignKeyColumn {
pub struct IntrospectionSchema {
pub name: String,
}

pub fn map_type_representation(sql_type: &str) -> Option<TypeRepresentation> {
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),

Check warning on line 77 in crates/configuration/src/introspection.rs

View workflow job for this annotation

GitHub Actions / cargo fmt

Diff in /home/runner/work/ndc-sqlserver/ndc-sqlserver/crates/configuration/src/introspection.rs
"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,
}
}
8 changes: 4 additions & 4 deletions crates/ndc-sqlserver/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 8b71c9b

Please sign in to comment.