Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract sql query builder #5123

Merged
merged 14 commits into from
Jan 15, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -28,6 +28,7 @@ members = [
"query-engine/query-engine-c-abi",
"query-engine/request-handlers",
"query-engine/schema",
"query-engine/query-builders/*",
"libs/*",
"prisma-fmt",
"prisma-schema-wasm",
Original file line number Diff line number Diff line change
@@ -5,9 +5,7 @@ use crate::{
MongoDbTransaction,
};
use async_trait::async_trait;
use connector_interface::{
Connection, ConnectionLike, ReadOperations, Transaction, UpdateType, WriteArgs, WriteOperations,
};
use connector_interface::{Connection, ConnectionLike, ReadOperations, Transaction, UpdateType, WriteOperations};
use mongodb::{ClientSession, Database};
use query_structure::{prelude::*, RelationLoadStrategy, SelectionResult};
use std::collections::HashMap;
@@ -55,7 +53,7 @@ impl WriteOperations for MongoDbConnection {
async fn create_record(
&mut self,
model: &Model,
args: WriteArgs,
args: query_structure::WriteArgs,
// The field selection on a create is never used on MongoDB as it cannot return more than the ID.
_selected_fields: FieldSelection,
_traceparent: Option<TraceParent>,
@@ -66,7 +64,7 @@ impl WriteOperations for MongoDbConnection {
async fn create_records(
&mut self,
model: &Model,
args: Vec<WriteArgs>,
args: Vec<query_structure::WriteArgs>,
skip_duplicates: bool,
_traceparent: Option<TraceParent>,
) -> connector_interface::Result<usize> {
@@ -83,7 +81,7 @@ impl WriteOperations for MongoDbConnection {
async fn create_records_returning(
&mut self,
_model: &Model,
_args: Vec<WriteArgs>,
_args: Vec<query_structure::WriteArgs>,
_skip_duplicates: bool,
_selected_fields: FieldSelection,
_traceparent: Option<TraceParent>,
@@ -94,8 +92,8 @@ impl WriteOperations for MongoDbConnection {
async fn update_records(
&mut self,
model: &Model,
record_filter: connector_interface::RecordFilter,
args: WriteArgs,
record_filter: query_structure::RecordFilter,
args: query_structure::WriteArgs,
limit: Option<usize>,
_traceparent: Option<TraceParent>,
) -> connector_interface::Result<usize> {
@@ -118,8 +116,8 @@ impl WriteOperations for MongoDbConnection {
async fn update_records_returning(
&mut self,
_model: &Model,
_record_filter: connector_interface::RecordFilter,
_args: WriteArgs,
_record_filter: query_structure::RecordFilter,
_args: query_structure::WriteArgs,
_selected_fields: FieldSelection,
_limit: Option<usize>,
_traceparent: Option<TraceParent>,
@@ -130,8 +128,8 @@ impl WriteOperations for MongoDbConnection {
async fn update_record(
&mut self,
model: &Model,
record_filter: connector_interface::RecordFilter,
args: WriteArgs,
record_filter: query_structure::RecordFilter,
args: query_structure::WriteArgs,
selected_fields: Option<FieldSelection>,
_traceparent: Option<TraceParent>,
) -> connector_interface::Result<Option<SingleRecord>> {
@@ -163,7 +161,7 @@ impl WriteOperations for MongoDbConnection {
async fn delete_records(
&mut self,
model: &Model,
record_filter: connector_interface::RecordFilter,
record_filter: query_structure::RecordFilter,
limit: Option<usize>,
_traceparent: Option<TraceParent>,
) -> connector_interface::Result<usize> {
@@ -180,7 +178,7 @@ impl WriteOperations for MongoDbConnection {
async fn delete_record(
&mut self,
model: &Model,
record_filter: connector_interface::RecordFilter,
record_filter: query_structure::RecordFilter,
selected_fields: FieldSelection,
_traceparent: Option<TraceParent>,
) -> connector_interface::Result<SingleRecord> {
@@ -314,7 +312,7 @@ impl ReadOperations for MongoDbConnection {
&mut self,
model: &Model,
query_arguments: query_structure::QueryArguments,
selections: Vec<connector_interface::AggregationSelection>,
selections: Vec<query_structure::AggregationSelection>,
group_by: Vec<ScalarFieldRef>,
having: Option<query_structure::Filter>,
_traceparent: Option<TraceParent>,
Original file line number Diff line number Diff line change
@@ -80,7 +80,7 @@ impl WriteOperations for MongoDbTransaction<'_> {
async fn create_record(
&mut self,
model: &Model,
args: connector_interface::WriteArgs,
args: query_structure::WriteArgs,
// The field selection on a create is never used on MongoDB as it cannot return more than the ID.
_selected_fields: FieldSelection,
_traceparent: Option<TraceParent>,
@@ -97,7 +97,7 @@ impl WriteOperations for MongoDbTransaction<'_> {
async fn create_records(
&mut self,
model: &Model,
args: Vec<connector_interface::WriteArgs>,
args: Vec<query_structure::WriteArgs>,
skip_duplicates: bool,
_traceparent: Option<TraceParent>,
) -> connector_interface::Result<usize> {
@@ -114,7 +114,7 @@ impl WriteOperations for MongoDbTransaction<'_> {
async fn create_records_returning(
&mut self,
_model: &Model,
_args: Vec<connector_interface::WriteArgs>,
_args: Vec<query_structure::WriteArgs>,
_skip_duplicates: bool,
_selected_fields: FieldSelection,
_traceparent: Option<TraceParent>,
@@ -125,8 +125,8 @@ impl WriteOperations for MongoDbTransaction<'_> {
async fn update_records(
&mut self,
model: &Model,
record_filter: connector_interface::RecordFilter,
args: connector_interface::WriteArgs,
record_filter: query_structure::RecordFilter,
args: query_structure::WriteArgs,
limit: Option<usize>,
_traceparent: Option<TraceParent>,
) -> connector_interface::Result<usize> {
@@ -148,8 +148,8 @@ impl WriteOperations for MongoDbTransaction<'_> {
async fn update_records_returning(
&mut self,
_model: &Model,
_record_filter: connector_interface::RecordFilter,
_args: connector_interface::WriteArgs,
_record_filter: query_structure::RecordFilter,
_args: query_structure::WriteArgs,
_selected_fields: FieldSelection,
_limit: Option<usize>,
_traceparent: Option<TraceParent>,
@@ -160,8 +160,8 @@ impl WriteOperations for MongoDbTransaction<'_> {
async fn update_record(
&mut self,
model: &Model,
record_filter: connector_interface::RecordFilter,
args: connector_interface::WriteArgs,
record_filter: query_structure::RecordFilter,
args: query_structure::WriteArgs,
selected_fields: Option<FieldSelection>,
_traceparent: Option<TraceParent>,
) -> connector_interface::Result<Option<SingleRecord>> {
@@ -192,7 +192,7 @@ impl WriteOperations for MongoDbTransaction<'_> {
async fn delete_records(
&mut self,
model: &Model,
record_filter: connector_interface::RecordFilter,
record_filter: query_structure::RecordFilter,
limit: Option<usize>,
_traceparent: Option<TraceParent>,
) -> connector_interface::Result<usize> {
@@ -209,7 +209,7 @@ impl WriteOperations for MongoDbTransaction<'_> {
async fn delete_record(
&mut self,
model: &Model,
record_filter: connector_interface::RecordFilter,
record_filter: query_structure::RecordFilter,
selected_fields: FieldSelection,
_traceparent: Option<TraceParent>,
) -> connector_interface::Result<SingleRecord> {
@@ -348,7 +348,7 @@ impl ReadOperations for MongoDbTransaction<'_> {
&mut self,
model: &Model,
query_arguments: query_structure::QueryArguments,
selections: Vec<connector_interface::AggregationSelection>,
selections: Vec<query_structure::AggregationSelection>,
group_by: Vec<ScalarFieldRef>,
having: Option<query_structure::Filter>,
_traceparent: Option<TraceParent>,
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use connector_interface::AggregationSelection;
use indexmap::IndexMap;
use query_structure::{
ast::FieldArity, DefaultKind, FieldSelection, PrismaValue, ScalarFieldRef, SelectedField, TypeIdentifier,
ast::FieldArity, AggregationSelection, DefaultKind, FieldSelection, PrismaValue, ScalarFieldRef, SelectedField,
TypeIdentifier,
};

/// Maps field db field names to their meta information.
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use crate::constants::*;

use bson::{doc, Bson, Document};
use connector_interface::AggregationSelection;
use query_structure::{AggregationFilter, Filter, ScalarFieldRef};
use query_structure::{AggregationFilter, AggregationSelection, Filter, ScalarFieldRef};
use std::collections::HashSet;

/// Represents a `$group` aggregation stage.
Original file line number Diff line number Diff line change
@@ -11,10 +11,11 @@ use crate::{
vacuum_cursor, BsonTransform, IntoBson,
};
use bson::{doc, Document};
use connector_interface::AggregationSelection;
use itertools::Itertools;
use mongodb::{options::AggregateOptions, ClientSession, Collection};
use query_structure::{FieldSelection, Filter, Model, QueryArguments, ScalarFieldRef, VirtualSelection};
use query_structure::{
AggregationSelection, FieldSelection, Filter, Model, QueryArguments, ScalarFieldRef, VirtualSelection,
};
use std::convert::TryFrom;
use std::future::IntoFuture;

Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@ use crate::{constants::*, output_meta, query_builder::MongoReadQueryBuilder, val

use connector_interface::*;
use mongodb::{bson::Document, ClientSession, Database};
use query_structure::{prelude::*, Filter, QueryArguments};
use query_structure::{prelude::*, AggregationSelection, Filter, QueryArguments};

pub async fn aggregate<'conn>(
database: &Database,
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use super::{into_expression::IntoUpdateExpression, operation};

use bson::{doc, Bson, Document};
use connector_interface::FieldPath;
use indexmap::IndexMap;
use query_structure::FieldPath;

/// `UpdateExpression` is an intermediary AST that's used to represent MongoDB expressions.
/// It is meant to be transformed into `BSON`.
Original file line number Diff line number Diff line change
@@ -2,8 +2,7 @@ use super::operation::*;
use crate::*;

use bson::doc;
use connector_interface::{CompositeWriteOperation, FieldPath, ScalarWriteOperation, WriteOperation};
use query_structure::{Field, PrismaValue};
use query_structure::{CompositeWriteOperation, Field, FieldPath, PrismaValue, ScalarWriteOperation, WriteOperation};

pub(crate) trait IntoUpdateOperation {
fn into_update_operations(self, field: &Field, path: FieldPath) -> crate::Result<Vec<UpdateOperation>>;
Original file line number Diff line number Diff line change
@@ -8,9 +8,9 @@ use super::*;
use crate::*;

use bson::Document;
use connector_interface::{FieldPath, WriteOperation};
use into_expression::IntoUpdateExpressions;
use into_operation::IntoUpdateOperation;
use query_structure::{FieldPath, WriteOperation};

pub(crate) trait IntoUpdateDocumentExtension {
fn into_update_docs(self, field: &Field, path: FieldPath) -> crate::Result<Vec<Document>>;
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use super::{expression, into_expression::IntoUpdateExpression};
use bson::{doc, Document};
use connector_interface::FieldPath;
use query_structure::Filter;
use query_structure::{FieldPath, Filter};

/// `UpdateOperation` is an intermediary AST used to perform preliminary transformations from a `WriteOperation`.
/// It is meant to be transformed into an `UpdateExpression`.
Loading
Loading