Skip to content

Commit

Permalink
Remove DML from MongoDB intro (#3557)
Browse files Browse the repository at this point in the history
  • Loading branch information
Julius de Bruijn authored Jan 6, 2023
1 parent addca8b commit 52d588a
Show file tree
Hide file tree
Showing 13 changed files with 586 additions and 1,149 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,19 @@ pub(super) async fn sample(
}
}

let data_model = statistics.into_datamodel(&mut warnings);
let is_empty = data_model.is_empty();
let mut data_model = render::Datamodel::default();
statistics.render(ctx.datasource(), &mut data_model, &mut warnings);

let mut rendered = render::Datamodel::default();
rendered.push_dml(ctx.datasource(), &data_model);
let config = if ctx.render_config {
render::Configuration::from_psl(ctx.configuration()).to_string()
let psl_string = if ctx.render_config {
let config = render::Configuration::from_psl(ctx.configuration());
format!("{config}\n{data_model}")
} else {
String::new()
data_model.to_string()
};

let data_model = format!("{config}\n{rendered}");

Ok(IntrospectionResult {
data_model: psl::reformat(&data_model, 2).unwrap(),
is_empty,
data_model: psl::reformat(&psl_string, 2).unwrap(),
is_empty: data_model.is_empty(),
warnings,
version: Version::NonPrisma,
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,48 @@ impl FieldType {
pub(super) fn is_array(&self) -> bool {
matches!(self, Self::Array(_))
}

pub(super) fn is_unsupported(&self) -> bool {
matches!(self, Self::Unsupported(_))
}

pub(super) fn is_document(&self) -> bool {
matches!(self, Self::Document(_))
}

pub(super) fn has_documents(&self) -> bool {
match self {
Self::Document(_) | Self::Json => true,
Self::Array(typ) => typ.is_document(),
_ => false,
}
}

pub(super) fn prisma_type(&self) -> &str {
match self {
FieldType::String => "String",
FieldType::Double => "Float",
FieldType::BinData => "Bytes",
FieldType::ObjectId => "String",
FieldType::Bool => "Boolean",
FieldType::Date => "DateTime",
FieldType::Int32 => "Int",
FieldType::Timestamp => "DateTime",
FieldType::Int64 => "BigInt",
FieldType::Json => "Json",
FieldType::Document(ref s) => s,
FieldType::Array(ref r#type) => r#type.prisma_type(),
FieldType::Unsupported(r#type) => r#type,
}
}

pub(super) fn native_type(&self) -> Option<&str> {
match self {
Self::ObjectId => Some("ObjectId"),
FieldType::Date => Some("Date"),
_ => None,
}
}
}

impl fmt::Display for FieldType {
Expand Down
Loading

0 comments on commit 52d588a

Please sign in to comment.