Skip to content

Commit

Permalink
chore: rename prisma-models to query-structure
Browse files Browse the repository at this point in the history
  • Loading branch information
Weakky committed Nov 27, 2023
1 parent 31deaad commit 739ba4d
Show file tree
Hide file tree
Showing 188 changed files with 286 additions and 334 deletions.
52 changes: 26 additions & 26 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ members = [
"query-engine/dmmf",
"query-engine/driver-adapters",
"query-engine/metrics",
"query-engine/prisma-models",
"query-engine/query-structure",
"query-engine/query-engine",
"query-engine/query-engine-node-api",
"query-engine/query-engine-wasm",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ edition = "2021"

[dependencies]
serde_json.workspace = true
prisma-models = { path = "../../prisma-models" }
query-structure = { path = "../../query-structure" }
once_cell = "1"
qe-setup = { path = "../qe-setup" }
request-handlers = { path = "../../request-handlers" }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::{TestError, TestResult};
use indexmap::IndexMap;
use itertools::Itertools;
use prisma_models::PrismaValue;
use query_core::{
constants::custom_types,
schema::{
Expand All @@ -10,6 +9,7 @@ use query_core::{
},
ArgumentValue, ArgumentValueObject, Selection,
};
use query_structure::PrismaValue;
use request_handlers::{Action, FieldQuery, GraphQLProtocolAdapter, JsonSingleQuery, SelectionSet, SelectionSetValue};
use serde_json::{json, Value as JsonValue};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use prisma_models::PrismaValue;
use query_core::{
constants::custom_types,
response_ir::{Item, ItemRef, Map},
};
use query_structure::PrismaValue;
use request_handlers::{GQLBatchResponse, GQLResponse, PrismaResponse};

pub struct JsonResponse;
Expand Down
4 changes: 2 additions & 2 deletions query-engine/connectors/mongodb-query-connector/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ indexmap = "1.7"
query-engine-metrics = {path = "../../metrics"}
cuid = { git = "https://github.com/prisma/cuid-rust", branch = "wasm32-support" }

[dependencies.prisma-models]
path = "../../prisma-models"
[dependencies.query-structure]
path = "../../query-structure"

[dependencies.mongodb-client]
path = "../../../libs/mongodb-client"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{orderby::OrderByData, IntoBson};
use mongodb::bson::{doc, Document};
use prisma_models::{OrderBy, SelectionResult, SortOrder};
use query_structure::{OrderBy, SelectionResult, SortOrder};

#[derive(Debug, Clone)]
pub(crate) struct CursorData {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use mongodb::{
bson::{self, extjson},
error::{CommandError, Error as DriverError, TRANSIENT_TRANSACTION_ERROR},
};
use prisma_models::{CompositeFieldRef, Field, ScalarFieldRef, SelectedField};
use query_structure::{CompositeFieldRef, Field, ScalarFieldRef, SelectedField};
use regex::Regex;
use thiserror::Error;
use user_facing_errors::query_engine::DatabaseConstraint;
Expand Down
65 changes: 28 additions & 37 deletions query-engine/connectors/mongodb-query-connector/src/filter.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
use crate::{constants::group_by, error::MongoError, join::JoinStage, query_builder::AggregationType, IntoBson};
use connector_interface::{
AggregationFilter, CompositeCondition, CompositeFilter, ConditionListValue, ConditionValue, Filter,
OneRelationIsNullFilter, QueryMode, RelationFilter, ScalarCompare, ScalarCondition, ScalarFilter, ScalarListFilter,
ScalarProjection,
};
use mongodb::bson::{doc, Bson, Document};
use prisma_models::{CompositeFieldRef, PrismaValue, ScalarFieldRef, TypeIdentifier};
use query_structure::*;

#[derive(Debug, Clone)]
pub(crate) enum MongoFilter {
Expand Down Expand Up @@ -132,9 +127,9 @@ impl MongoFilterVisitor {

fn visit_scalar_filter(&self, filter: ScalarFilter) -> crate::Result<MongoFilter> {
let field = match filter.projection {
connector_interface::ScalarProjection::Single(sf) => sf,
connector_interface::ScalarProjection::Compound(mut c) if c.len() == 1 => c.pop().unwrap(),
connector_interface::ScalarProjection::Compound(_) => {
ScalarProjection::Single(sf) => sf,
ScalarProjection::Compound(mut c) if c.len() == 1 => c.pop().unwrap(),
ScalarProjection::Compound(_) => {
unreachable!(
"Multi-field compound filter case hit when it should have been folded into normal filters previously."
)
Expand Down Expand Up @@ -417,7 +412,7 @@ impl MongoFilterVisitor {
let field_ref = filter.as_field_ref().cloned();

let filter_doc = match filter.condition {
connector_interface::ScalarListCondition::Contains(val) => {
ScalarListCondition::Contains(val) => {
let bson = match val {
ConditionValue::Value(value) => (field, value).into_bson()?,
ConditionValue::FieldRef(field_ref) => self.prefixed_field_ref(&field_ref)?,
Expand All @@ -426,11 +421,11 @@ impl MongoFilterVisitor {
doc! { "$in": [bson, coerce_as_array(&field_name)] }
}

connector_interface::ScalarListCondition::ContainsEvery(vals) if vals.is_empty() => {
ScalarListCondition::ContainsEvery(vals) if vals.is_empty() => {
// Empty hasEvery: Return all records.
render_stub_condition(true)
}
connector_interface::ScalarListCondition::ContainsEvery(ConditionListValue::List(vals)) => {
ScalarListCondition::ContainsEvery(ConditionListValue::List(vals)) => {
let ins = vals
.into_iter()
.map(|val| {
Expand All @@ -442,20 +437,18 @@ impl MongoFilterVisitor {

doc! { "$and": ins }
}
connector_interface::ScalarListCondition::ContainsEvery(ConditionListValue::FieldRef(field_ref)) => {
render_every(
&field_name,
"elem",
doc! { "$in": ["$$elem", coerce_as_array((self.prefix(), &field_ref).into_bson()?)] },
true,
)
}
ScalarListCondition::ContainsEvery(ConditionListValue::FieldRef(field_ref)) => render_every(
&field_name,
"elem",
doc! { "$in": ["$$elem", coerce_as_array((self.prefix(), &field_ref).into_bson()?)] },
true,
),

connector_interface::ScalarListCondition::ContainsSome(vals) if vals.is_empty() => {
ScalarListCondition::ContainsSome(vals) if vals.is_empty() => {
// Empty hasSome: Return no records.
render_stub_condition(false)
}
connector_interface::ScalarListCondition::ContainsSome(ConditionListValue::List(vals)) => {
ScalarListCondition::ContainsSome(ConditionListValue::List(vals)) => {
let ins = vals
.into_iter()
.map(|val| {
Expand All @@ -467,19 +460,17 @@ impl MongoFilterVisitor {

doc! { "$or": ins }
}
connector_interface::ScalarListCondition::ContainsSome(ConditionListValue::FieldRef(field_ref)) => {
render_some(
&field_name,
"elem",
doc! { "$in": ["$$elem", coerce_as_array((self.prefix(), &field_ref).into_bson()?)] },
true,
)
}
ScalarListCondition::ContainsSome(ConditionListValue::FieldRef(field_ref)) => render_some(
&field_name,
"elem",
doc! { "$in": ["$$elem", coerce_as_array((self.prefix(), &field_ref).into_bson()?)] },
true,
),

connector_interface::ScalarListCondition::IsEmpty(true) => {
ScalarListCondition::IsEmpty(true) => {
doc! { "$eq": [render_size(&field_name, true), 0] }
}
connector_interface::ScalarListCondition::IsEmpty(false) => {
ScalarListCondition::IsEmpty(false) => {
doc! { "$gt": [render_size(&field_name, true), 0] }
}
};
Expand Down Expand Up @@ -653,21 +644,21 @@ impl MongoFilterVisitor {
let mut join_stage = JoinStage::new(from_field);

let filter_doc = match filter.condition {
connector_interface::RelationCondition::EveryRelatedRecord => {
RelationCondition::EveryRelatedRecord => {
let (every, nested_joins) = render_every_from_filter(&field_name, nested_filter, false, false)?;

join_stage.extend_nested(nested_joins);

every
}
connector_interface::RelationCondition::AtLeastOneRelatedRecord => {
RelationCondition::AtLeastOneRelatedRecord => {
let (some, nested_joins) = render_some_from_filter(&field_name, nested_filter, false, false)?;

join_stage.extend_nested(nested_joins);

some
}
connector_interface::RelationCondition::NoRelatedRecord if is_to_one => {
RelationCondition::NoRelatedRecord if is_to_one => {
if is_empty_filter {
// Doesn't need coercing the array since joins always return arrays
doc! { "$eq": [render_size(&field_name, false), 0] }
Expand All @@ -688,7 +679,7 @@ impl MongoFilterVisitor {
}
}
}
connector_interface::RelationCondition::NoRelatedRecord => {
RelationCondition::NoRelatedRecord => {
if is_empty_filter {
// Doesn't need coercing the array since joins always return arrays
doc! { "$eq": [render_size(&field_name, false), 0] }
Expand All @@ -700,7 +691,7 @@ impl MongoFilterVisitor {
none
}
}
connector_interface::RelationCondition::ToOneRelatedRecord => {
RelationCondition::ToOneRelatedRecord => {
// To-ones are coerced to single-element arrays via the join.
// We render an "every" expression on that array to ensure that the predicate is matched.
let (every, nested_joins) = render_every_from_filter(&field_name, nested_filter, false, false)?;
Expand Down
Loading

0 comments on commit 739ba4d

Please sign in to comment.