Skip to content

Commit

Permalink
qe: fix all infractions to clippy::needless_borrow (prisma#3926)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomhoule authored Apr 26, 2023
1 parent 885141b commit 03571f8
Show file tree
Hide file tree
Showing 16 changed files with 27 additions and 33 deletions.
2 changes: 1 addition & 1 deletion query-engine/black-box-tests/tests/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub(crate) fn query_engine_cmd(dml: &str, port: &str) -> process::Command {
pub(crate) fn query_engine_bin_path() -> path::PathBuf {
let name = "query-engine";
let env_var = format!("CARGO_BIN_EXE_{}", name);
std::env::var_os(&env_var)
std::env::var_os(env_var)
.map(|p| p.into())
.unwrap_or_else(|| target_dir().join(format!("{}{}", name, env::consts::EXE_SUFFIX)))
}
Expand Down
4 changes: 2 additions & 2 deletions query-engine/black-box-tests/tests/protocols/mismatched.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::helpers::*;
use query_engine_tests::*;

const JSON_QUERY: &'static str = r###"
const JSON_QUERY: &str = r###"
{
"action": "findMany",
"modelName": "Person",
Expand All @@ -15,7 +15,7 @@ const JSON_QUERY: &'static str = r###"
}
"###;

const GRAPHQL_QUERY: &'static str = r###"
const GRAPHQL_QUERY: &str = r###"
{
"operationName": null,
"variables": {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,6 @@ impl<T> DecorateErrorWithFieldInformationExtension for crate::Result<T> {
}

fn decorate_with_composite_field_info(self, cf: &CompositeFieldRef) -> Self {
self.map_err(|err| err.decorate_with_field_name(&cf.name()))
self.map_err(|err| err.decorate_with_field_name(cf.name()))
}
}
2 changes: 1 addition & 1 deletion query-engine/connectors/mongodb-query-connector/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![allow(clippy::vec_init_then_push, clippy::branches_sharing_code, clippy::needless_borrow)]
#![allow(clippy::vec_init_then_push, clippy::branches_sharing_code)]

mod constants;
mod cursor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub async fn aggregate<'conn>(
having: Option<Filter>,
) -> crate::Result<Vec<AggregationRow>> {
let is_group_by = !group_by.is_empty();
let coll = database.collection(&model.db_name());
let coll = database.collection(model.db_name());

let query = MongoReadQueryBuilder::from_args(query_arguments)?
.with_groupings(group_by, &selections, having)?
Expand Down Expand Up @@ -88,7 +88,7 @@ fn to_aggregation_rows(
let mut id_key_doc = doc.remove(group_by::UNDERSCORE_ID).unwrap();

for selection in selections.iter() {
let selection_meta = output_meta::from_aggregation_selection(&selection);
let selection_meta = output_meta::from_aggregation_selection(selection);

match selection {
// All flat selection can only be in the _id part of the result doc.
Expand All @@ -101,15 +101,15 @@ fn to_aggregation_rows(
AggregationSelection::Count { all, fields } => {
if *all {
let meta = selection_meta.get("all").unwrap();
let field_val = value_from_bson(doc.remove("count_all").unwrap(), &meta)?;
let field_val = value_from_bson(doc.remove("count_all").unwrap(), meta)?;

row.push(AggregationResult::Count(None, field_val));
}

for field in fields {
let meta = selection_meta.get(field.db_name()).unwrap();
let bson = doc.remove(&format!("count_{}", field.db_name())).unwrap();
let field_val = value_from_bson(bson, &meta)?;
let field_val = value_from_bson(bson, meta)?;

row.push(AggregationResult::Count(Some(field.clone()), field_val));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ pub async fn create_records<'conn>(
.try_into()
.expect("Create calls can only use PrismaValue write expressions (right now).");

let bson = (field, value).into_bson().decorate_with_field_info(&field)?;
let bson = (field, value).into_bson().decorate_with_field_info(field)?;

doc.insert(field_name.to_string(), bson);
}
Expand Down Expand Up @@ -342,7 +342,7 @@ pub async fn m2m_connect<'conn>(

(selection, value.clone())
.into_bson()
.decorate_with_selected_field_info(&selection)
.decorate_with_selected_field_info(selection)
})
.collect::<crate::Result<Vec<_>>>()?;

Expand Down Expand Up @@ -408,7 +408,7 @@ pub async fn m2m_disconnect<'conn>(

(field, value.clone())
.into_bson()
.decorate_with_selected_field_info(&field)
.decorate_with_selected_field_info(field)
})
.collect::<crate::Result<Vec<_>>>()?;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ impl IntoBson for (&MongoDbType, PrismaValue) {
fn into_bson(self) -> crate::Result<Bson> {
Ok(match self {
// ObjectId
(MongoDbType::ObjectId, PrismaValue::String(s)) => Bson::ObjectId(ObjectId::parse_str(&s)?),
(MongoDbType::ObjectId, PrismaValue::String(s)) => Bson::ObjectId(ObjectId::parse_str(s)?),
(MongoDbType::ObjectId, PrismaValue::Bytes(b)) => {
if b.len() != 12 {
return Err(MongoError::MalformedObjectId(format!(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ pub(crate) fn build(
let cursor_condition = cursor_row.clone().equals(cursor_values.clone());

// Orderings for this query. Influences which fields we need to fetch for comparing order fields.
let mut definitions = order_definitions(query_arguments, model, &order_by_defs, ctx);
let mut definitions = order_definitions(query_arguments, model, order_by_defs, ctx);

// Subquery to find the value of the order field(s) that we need for comparison.
let order_subquery = Select::from_table(model.as_table(ctx)).so_that(cursor_condition);
Expand Down Expand Up @@ -247,7 +247,7 @@ pub(crate) fn build(
let mut and_conditions = Vec::with_capacity(head.len() + 1);

for order_definition in head {
and_conditions.push(map_equality_condition(&order_subquery, &order_definition));
and_conditions.push(map_equality_condition(&order_subquery, order_definition));
}

let order_definition = tail.first().unwrap();
Expand Down Expand Up @@ -279,15 +279,15 @@ pub(crate) fn build(
// but everything else must come strictly "after" the cursor.
and_conditions.push(map_orderby_condition(
&order_subquery,
&order_definition,
order_definition,
reverse,
true,
ctx,
));
} else {
and_conditions.push(map_orderby_condition(
&order_subquery,
&order_definition,
order_definition,
reverse,
false,
ctx,
Expand Down Expand Up @@ -519,7 +519,7 @@ fn cursor_order_def_relevance(order_by: &OrderByRelevance, order_by_def: &OrderB
}

fn foreign_keys_from_order_path(path: &[OrderByHop], joins: &[AliasedJoin]) -> Option<Vec<CursorOrderForeignKey>> {
let (before_last_hop, last_hop) = take_last_two_elem(&path);
let (before_last_hop, last_hop) = take_last_two_elem(path);

last_hop.map(|hop| {
match hop {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ where
Some(level) => {
let transformed = IsolationLevel::from_str(&level)
.map_err(SqlError::from)
.map_err(|err| err.into_connector_error(&connection_info))?;
.map_err(|err| err.into_connector_error(connection_info))?;

Some(transformed)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub(crate) async fn native_upsert(
let where_condition = upsert.filter().aliased_condition_from(None, false, ctx);
let update = build_update_and_set_query(upsert.model(), upsert.update().clone(), ctx).so_that(where_condition);

let insert = create_record(&upsert.model(), upsert.create().clone(), ctx);
let insert = create_record(upsert.model(), upsert.create().clone(), ctx);

let constraints: Vec<_> = upsert.unique_constraints().as_columns(ctx).collect();
let query: Query = insert
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ fn invalid_file_path_error(file_path: &str, connection_info: &ConnectionInfo) ->
SqlError::ConnectionError(QuaintKind::DatabaseUrlIsInvalid(format!(
"\"{file_path}\" is not a valid sqlite file path"
)))
.into_connector_error(&connection_info)
.into_connector_error(connection_info)
}

#[async_trait]
Expand Down
7 changes: 1 addition & 6 deletions query-engine/connectors/sql-query-connector/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
#![allow(
clippy::wrong_self_convention,
clippy::branches_sharing_code,
clippy::needless_borrow,
clippy::needless_collect
)]
#![allow(clippy::wrong_self_convention)]
#![deny(unsafe_code)]

mod column_metadata;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl SelectDefinition for QueryArguments {
ctx: &Context<'_>,
) -> (Select<'static>, Vec<Expression<'static>>) {
let order_by_definitions = OrderByBuilder::default().build(&self, ctx);
let cursor_condition = cursor_condition::build(&self, &model, &order_by_definitions, ctx);
let cursor_condition = cursor_condition::build(&self, model, &order_by_definitions, ctx);
let aggregation_joins = nested_aggregations::build(aggr_selections, ctx);

let limit = if self.ignore_take { None } else { self.take_abs() };
Expand Down Expand Up @@ -157,7 +157,7 @@ pub(crate) fn aggregate(
args: QueryArguments,
ctx: &Context<'_>,
) -> Select<'static> {
let columns = extract_columns(model, &selections, ctx);
let columns = extract_columns(model, selections, ctx);
let sub_query = get_records(model, columns.into_iter(), &[], args, ctx);
let sub_table = Table::from(sub_query).alias("sub");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub(crate) fn create_record(model: &ModelRef, mut args: WriteArgs, ctx: &Context
.fields()
.scalar()
.into_iter()
.filter(|field| args.has_arg_for(&field.db_name()))
.filter(|field| args.has_arg_for(field.db_name()))
.collect();

let insert = fields
Expand Down
3 changes: 1 addition & 2 deletions query-engine/query-engine-node-api/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
#![allow(clippy::needless_borrow)]

pub mod engine;
pub mod error;
pub mod functions;
pub mod log_callback;
pub mod logger;

mod tracer;

pub(crate) type Result<T> = std::result::Result<T, error::ApiError>;
Expand Down
2 changes: 1 addition & 1 deletion query-engine/query-engine/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![allow(clippy::upper_case_acronyms, clippy::needless_borrow)]
#![allow(clippy::upper_case_acronyms)]

#[macro_use]
extern crate tracing;
Expand Down

0 comments on commit 03571f8

Please sign in to comment.