Skip to content

Commit

Permalink
qe/prisma-models: delete more dead codes, unused dependencies (#3776)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomhoule authored Mar 16, 2023
1 parent ab90baf commit 1c2b092
Show file tree
Hide file tree
Showing 12 changed files with 9 additions and 47 deletions.
3 changes: 0 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions query-engine/prisma-models/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,11 @@ name = "prisma-models"
version = "0.0.0"

[dependencies]
chrono = { version = "0.4", features = ["serde"] }
psl.workspace = true
dml = { path = "../dml" }
itertools = "0.10"
prisma-value = { path = "../../libs/prisma-value" }
bigdecimal = "0.3"
serde.workspace = true
serde_json = { version = "1.0", features = ["float_roundtrip"] }
thiserror = "1.0"

[features]
Expand Down
16 changes: 0 additions & 16 deletions query-engine/prisma-models/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use prisma_value::ConversionFailure;
use thiserror::Error;

#[derive(Debug, Error, PartialEq)]
Expand All @@ -13,9 +12,6 @@ pub enum DomainError {
container_name: String,
},

#[error("Relation `{}` not found", name)]
RelationNotFound { name: String },

#[error("ScalarField `{}` on {} `{}` not found", name, container_type, container_name)]
ScalarFieldNotFound {
name: String,
Expand All @@ -33,21 +29,9 @@ pub enum DomainError {
#[error("RelationField `{}` on model `{}` not found", name, model)]
RelationFieldNotFound { name: String, model: String },

#[error("Relation field `{}` on model `{}` not found", relation, model)]
FieldForRelationNotFound { relation: String, model: String },

#[error("Model id `{}` for relation `{}` not found", model_id, relation)]
ModelForRelationNotFound { model_id: String, relation: String },

#[error("Enum `{}` not found", name)]
EnumNotFound { name: String },

#[error("Conversion from `{}` to `{}` failed.", _0, _1)]
ConversionFailure(String, String),
}

impl From<super::ConversionFailure> for DomainError {
fn from(err: ConversionFailure) -> Self {
Self::ConversionFailure(err.from.into_owned(), err.to.into_owned())
}
}
1 change: 0 additions & 1 deletion query-engine/prisma-models/src/field/composite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ pub enum CompositeFieldId {

pub type CompositeField = crate::Zipper<CompositeFieldId>;
pub type CompositeFieldRef = CompositeField;
pub type CompositeFieldWeak = CompositeField;

impl CompositeField {
fn arity(&self) -> FieldArity {
Expand Down
2 changes: 0 additions & 2 deletions query-engine/prisma-models/src/field/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ use crate::{ast, ModelRef};
use psl::parser_database::{walkers, ScalarType};
use std::{borrow::Cow, hash::Hash};

pub type FieldWeak = Field;

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum Field {
Relation(RelationFieldRef),
Expand Down
1 change: 0 additions & 1 deletion query-engine/prisma-models/src/field/relation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use std::fmt::Display;

pub type RelationField = crate::Zipper<RelationFieldId>;
pub type RelationFieldRef = RelationField;
pub type RelationFieldWeak = RelationField;

impl RelationField {
pub fn name(&self) -> &str {
Expand Down
1 change: 0 additions & 1 deletion query-engine/prisma-models/src/field/scalar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use std::fmt::{Debug, Display};

pub type ScalarField = crate::Zipper<ScalarFieldId>;
pub type ScalarFieldRef = ScalarField;
pub type ScalarFieldWeak = ScalarField;

#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq)]
pub enum ScalarFieldId {
Expand Down
8 changes: 4 additions & 4 deletions query-engine/prisma-models/src/field_selection.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
parent_container::ParentContainer, CompositeFieldRef, DomainError, Field, PrismaValueExtensions, ScalarFieldRef,
SelectionResult,
parent_container::ParentContainer, prisma_value_ext::PrismaValueExtensions, CompositeFieldRef, DomainError, Field,
ScalarFieldRef, SelectionResult,
};
use itertools::Itertools;
use prisma_value::PrismaValue;
Expand Down Expand Up @@ -77,7 +77,7 @@ impl FieldSelection {
SelectedField::Scalar(sf) => Some(sf.clone()),
SelectedField::Composite(_) => None,
})
.collect_vec();
.collect::<Vec<_>>();

if scalar_fields.len() == self.selections.len() {
Some(scalar_fields)
Expand Down Expand Up @@ -179,7 +179,7 @@ impl SelectedField {
}

/// Coerces a value to fit the selection. If the conversion is not possible, an error will be thrown.
pub fn coerce_value(&self, value: PrismaValue) -> crate::Result<PrismaValue> {
pub(crate) fn coerce_value(&self, value: PrismaValue) -> crate::Result<PrismaValue> {
match self {
SelectedField::Scalar(sf) => value.coerce(&sf.type_identifier()),
SelectedField::Composite(cs) => cs.coerce_value(value),
Expand Down
1 change: 0 additions & 1 deletion query-engine/prisma-models/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ pub use fields::*;
pub use internal_data_model::*;
pub use model::*;
pub use order_by::*;
pub use prisma_value_ext::*;
pub use projections::*;
pub use record::*;
pub use relation::*;
Expand Down
12 changes: 2 additions & 10 deletions query-engine/prisma-models/src/parent_container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,6 @@ impl ParentContainer {
}
}

pub fn as_model_weak(&self) -> Option<Model> {
match self {
ParentContainer::Model(m) => Some(m.clone()),
ParentContainer::CompositeType(_) => None,
}
}

pub fn as_composite(&self) -> Option<CompositeType> {
match self {
ParentContainer::Model(_) => None,
Expand All @@ -53,11 +46,10 @@ impl ParentContainer {
}

pub fn find_field(&self, prisma_name: &str) -> Option<Field> {
// Unwraps are safe: This can never fail, the models and composites are always available in memory.
match self {
ParentContainer::Model(weak) => weak.fields().find_from_all(prisma_name).ok(),
ParentContainer::Model(model) => model.fields().find_from_all(prisma_name).ok(),

ParentContainer::CompositeType(weak) => weak.fields().find(|field| field.name() == prisma_name),
ParentContainer::CompositeType(ct) => ct.fields().find(|field| field.name() == prisma_name),
}
}

Expand Down
6 changes: 2 additions & 4 deletions query-engine/prisma-models/src/pk.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
use crate::{ScalarFieldRef, ScalarFieldWeak};

#[derive(Debug, Clone)]
pub struct PrimaryKey {
pub alias: Option<String>,
pub(crate) fields: Vec<ScalarFieldWeak>,
pub(crate) fields: Vec<crate::ScalarField>,
}

impl PrimaryKey {
pub fn fields(&self) -> Vec<ScalarFieldRef> {
pub fn fields(&self) -> Vec<crate::ScalarField> {
self.fields.clone()
}
}
2 changes: 1 addition & 1 deletion query-engine/prisma-models/src/prisma_value_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use super::{PrismaValue, TypeIdentifier};
use crate::DomainError;
use bigdecimal::ToPrimitive;

pub trait PrismaValueExtensions {
pub(crate) trait PrismaValueExtensions {
fn coerce(self, to_type: &TypeIdentifier) -> crate::Result<PrismaValue>;
}

Expand Down

0 comments on commit 1c2b092

Please sign in to comment.