Skip to content

Commit

Permalink
fix m2m support and make basic ordering + pagination work
Browse files Browse the repository at this point in the history
  • Loading branch information
Weakky committed Oct 31, 2023
1 parent 7d40c79 commit 3f9d851
Show file tree
Hide file tree
Showing 11 changed files with 220 additions and 121 deletions.
2 changes: 1 addition & 1 deletion quaint/src/ast/join.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ impl<'a> JoinData<'a> {
}
}

pub fn as_lateral(mut self) -> Self {
pub fn lateral(mut self) -> Self {
self.lateral = true;
self
}
Expand Down
2 changes: 1 addition & 1 deletion quaint/src/ast/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ impl<'a> Select<'a> {
{
let join_data: JoinData = join.into();

self.left_join(join_data.as_lateral())
self.left_join(join_data.lateral())
}

/// Adds `RIGHT JOIN` clause to the query.
Expand Down
2 changes: 1 addition & 1 deletion quaint/src/ast/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ impl<'a> Table<'a> {
{
let join_data: JoinData = join.into();

self.left_join(join_data.as_lateral())
self.left_join(join_data.lateral())
}

/// Adds an `INNER JOIN` clause to the query, specifically for that table.
Expand Down
1 change: 1 addition & 0 deletions query-engine/connectors/query-connector/src/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ impl RelAggregationSelection {
}
}

// TODO: rename this
#[derive(Debug, Clone)]
pub struct RelatedQuery {
pub name: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub(crate) fn coerce_record_with_join(record: &mut Record, rq_indexes: Vec<(usiz
// TODO: find better name
pub(crate) fn coerce_json_relation_to_pv(value: serde_json::Value, q: &RelatedQuery) -> PrismaValue {
match value {
// to-many
// one-to-many
serde_json::Value::Array(values) if q.parent_field.is_list() => PrismaValue::List(
values
.into_iter()
Expand Down
11 changes: 9 additions & 2 deletions query-engine/connectors/sql-query-connector/src/ordering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,23 @@ pub(crate) struct OrderByDefinition {

#[derive(Debug, Default)]
pub(crate) struct OrderByBuilder {
parent_alias: Option<String>,
// Used to generate unique join alias
join_counter: usize,
}

impl OrderByBuilder {
pub(crate) fn with_parent_alias(mut self, alias: Option<String>) -> Self {
self.parent_alias = alias;
self
}
}

impl OrderByBuilder {
/// Builds all expressions for an `ORDER BY` clause based on the query arguments.
pub(crate) fn build(&mut self, query_arguments: &QueryArguments, ctx: &Context<'_>) -> Vec<OrderByDefinition> {
let needs_reversed_order = query_arguments.needs_reversed_order();

// The index is used to differentiate potentially separate relations to the same model.
query_arguments
.order_by
.iter()
Expand Down Expand Up @@ -202,7 +209,7 @@ impl OrderByBuilder {
let order_by_column = if let Some(last_join) = joins.last() {
Column::from((last_join.alias.to_owned(), order_by.field.db_name().to_owned()))
} else {
order_by.field.as_column(ctx)
order_by.field.as_column(ctx).opt_table(self.parent_alias.clone())
};

(joins, order_by_column)
Expand Down
Loading

0 comments on commit 3f9d851

Please sign in to comment.