From f337f6878e80f6e582e7f66f53534c4c83f79b19 Mon Sep 17 00:00:00 2001 From: Daniel Harvey Date: Mon, 2 Dec 2024 10:15:43 +0000 Subject: [PATCH] Bump to Rust 1.83, fix clippy suggestions --- crates/query-engine/sql/src/sql/convert.rs | 5 ++-- .../translation/src/translation/helpers.rs | 21 ++++++++-------- .../src/translation/mutation/generate.rs | 2 +- .../src/translation/mutation/translate.rs | 4 ++-- .../src/translation/mutation/v2/common.rs | 11 +++++---- .../src/translation/mutation/v2/delete.rs | 2 +- .../src/translation/mutation/v2/generate.rs | 2 +- .../src/translation/mutation/v2/insert.rs | 2 +- .../src/translation/mutation/v2/translate.rs | 4 ++-- .../src/translation/mutation/v2/update.rs | 2 +- .../translation/src/translation/query/mod.rs | 2 +- .../src/translation/query/relationships.rs | 5 ++-- .../translation/src/translation/query/root.rs | 16 ++++++++----- .../src/translation/query/sorting.rs | 6 ++--- flake.lock | 24 +++++++++---------- flake.nix | 1 + rust-toolchain.toml | 2 +- 17 files changed, 59 insertions(+), 52 deletions(-) diff --git a/crates/query-engine/sql/src/sql/convert.rs b/crates/query-engine/sql/src/sql/convert.rs index 6683b0ad8..91c09784e 100644 --- a/crates/query-engine/sql/src/sql/convert.rs +++ b/crates/query-engine/sql/src/sql/convert.rs @@ -127,9 +127,8 @@ impl Select { sql.append_syntax(" "); - match &self.from { - Some(from) => from.to_sql(sql), - None => (), + if let Some(from) = &self.from { + from.to_sql(sql); } for join in &self.joins { diff --git a/crates/query-engine/translation/src/translation/helpers.rs b/crates/query-engine/translation/src/translation/helpers.rs index e5a710e4b..f5f8aec07 100644 --- a/crates/query-engine/translation/src/translation/helpers.rs +++ b/crates/query-engine/translation/src/translation/helpers.rs @@ -548,17 +548,16 @@ impl State { &mut self, variables: &Option>>, ) -> Option<(sql::ast::From, sql::ast::TableReference)> { - match variables { - None => None, - Some(_) => { - let variables_table_alias = self.make_table_alias("%variables_table".to_string()); - let table_reference = - sql::ast::TableReference::AliasedTable(variables_table_alias.clone()); - Some(( - sql::helpers::from_variables(variables_table_alias), - table_reference, - )) - } + if variables.is_none() { + None + } else { + let variables_table_alias = self.make_table_alias("%variables_table".to_string()); + let table_reference = + sql::ast::TableReference::AliasedTable(variables_table_alias.clone()); + Some(( + sql::helpers::from_variables(variables_table_alias), + table_reference, + )) } } diff --git a/crates/query-engine/translation/src/translation/mutation/generate.rs b/crates/query-engine/translation/src/translation/mutation/generate.rs index 43ba73bda..4a8482b75 100644 --- a/crates/query-engine/translation/src/translation/mutation/generate.rs +++ b/crates/query-engine/translation/src/translation/mutation/generate.rs @@ -23,7 +23,7 @@ pub fn generate(env: &Env) -> BTreeMap { .map(|(name, mutation)| (name, Mutation::V1(mutation))) .collect(), Some(mutations::MutationsVersion::V2) => { - v2::generate(&env.metadata.tables, &env.mutations_prefix) + v2::generate(&env.metadata.tables, env.mutations_prefix.as_ref()) .into_iter() .map(|(name, mutation)| (name, Mutation::V2(mutation))) .collect() diff --git a/crates/query-engine/translation/src/translation/mutation/translate.rs b/crates/query-engine/translation/src/translation/mutation/translate.rs index a1673c29b..240925f74 100644 --- a/crates/query-engine/translation/src/translation/mutation/translate.rs +++ b/crates/query-engine/translation/src/translation/mutation/translate.rs @@ -86,7 +86,7 @@ fn translate_mutation( name: return_collection, reference: sql::ast::TableReference::AliasedTable(cte_table_alias.clone()), }, - &None, + None, &query, )?; @@ -227,7 +227,7 @@ fn translate_native_query( name: procedure_name.to_string().into(), reference: table_reference, }, - &None, + None, &query, )?; diff --git a/crates/query-engine/translation/src/translation/mutation/v2/common.rs b/crates/query-engine/translation/src/translation/mutation/v2/common.rs index b48abd875..f44481d9e 100644 --- a/crates/query-engine/translation/src/translation/mutation/v2/common.rs +++ b/crates/query-engine/translation/src/translation/mutation/v2/common.rs @@ -110,7 +110,7 @@ pub fn default_constraint() -> serde_json::Value { // the old default was to prefix generated mutations with `v2_` or `v1_` // but now we are able to override this -pub fn get_version_prefix(mutations_prefix: &Option) -> String { +pub fn get_version_prefix(mutations_prefix: Option<&String>) -> String { match mutations_prefix { None => format!("{}_", super::VERSION), Some(str) => match str.as_str() { @@ -122,10 +122,13 @@ pub fn get_version_prefix(mutations_prefix: &Option) -> String { #[test] fn test_version_prefix() { - assert_eq!(get_version_prefix(&None), "v2_".to_string()); + assert_eq!(get_version_prefix(None), "v2_".to_string()); assert_eq!( - get_version_prefix(&Some("horse".into())), + get_version_prefix(Some("horse".into()).as_ref()), "horse_".to_string() ); - assert_eq!(get_version_prefix(&Some(String::new())), String::new()); + assert_eq!( + get_version_prefix(Some(String::new()).as_ref()), + String::new() + ); } diff --git a/crates/query-engine/translation/src/translation/mutation/v2/delete.rs b/crates/query-engine/translation/src/translation/mutation/v2/delete.rs index f2973220f..b7d9516e3 100644 --- a/crates/query-engine/translation/src/translation/mutation/v2/delete.rs +++ b/crates/query-engine/translation/src/translation/mutation/v2/delete.rs @@ -37,7 +37,7 @@ pub struct DeleteByKey { pub fn generate_delete_by_unique( collection_name: &models::CollectionName, table_info: &database::TableInfo, - mutations_prefix: &Option, + mutations_prefix: Option<&String>, ) -> Vec<(models::ProcedureName, DeleteMutation)> { table_info .uniqueness_constraints diff --git a/crates/query-engine/translation/src/translation/mutation/v2/generate.rs b/crates/query-engine/translation/src/translation/mutation/v2/generate.rs index 32133c17c..401c8246d 100644 --- a/crates/query-engine/translation/src/translation/mutation/v2/generate.rs +++ b/crates/query-engine/translation/src/translation/mutation/v2/generate.rs @@ -18,7 +18,7 @@ pub enum Mutation { /// Given our introspection data, work out all the mutations we can generate pub fn generate( tables_info: &database::TablesInfo, - mutations_prefix: &Option, + mutations_prefix: Option<&String>, ) -> BTreeMap { let mut mutations = BTreeMap::new(); for (collection_name, table_info) in &tables_info.0 { diff --git a/crates/query-engine/translation/src/translation/mutation/v2/insert.rs b/crates/query-engine/translation/src/translation/mutation/v2/insert.rs index 5250053f8..e264290e6 100644 --- a/crates/query-engine/translation/src/translation/mutation/v2/insert.rs +++ b/crates/query-engine/translation/src/translation/mutation/v2/insert.rs @@ -31,7 +31,7 @@ pub struct InsertMutation { pub fn generate( collection_name: &models::CollectionName, table_info: &database::TableInfo, - mutations_prefix: &Option, + mutations_prefix: Option<&String>, ) -> (models::ProcedureName, InsertMutation) { let name = format!( "{}insert_{collection_name}", diff --git a/crates/query-engine/translation/src/translation/mutation/v2/translate.rs b/crates/query-engine/translation/src/translation/mutation/v2/translate.rs index 00056613f..bdd364450 100644 --- a/crates/query-engine/translation/src/translation/mutation/v2/translate.rs +++ b/crates/query-engine/translation/src/translation/mutation/v2/translate.rs @@ -25,7 +25,7 @@ pub fn translate( ), Error, > { - let mutation = lookup_generated_mutation(env, procedure_name, &env.mutations_prefix)?; + let mutation = lookup_generated_mutation(env, procedure_name, env.mutations_prefix.as_ref())?; Ok(match mutation { super::generate::Mutation::DeleteMutation(delete) => { @@ -79,7 +79,7 @@ pub fn translate( fn lookup_generated_mutation( env: &Env<'_>, procedure_name: &models::ProcedureName, - mutations_prefix: &Option, + mutations_prefix: Option<&String>, ) -> Result { // this means we generate them on every mutation request // i don't think this is optimal but I'd like to get this working before working out diff --git a/crates/query-engine/translation/src/translation/mutation/v2/update.rs b/crates/query-engine/translation/src/translation/mutation/v2/update.rs index bb453b18e..970d62958 100644 --- a/crates/query-engine/translation/src/translation/mutation/v2/update.rs +++ b/crates/query-engine/translation/src/translation/mutation/v2/update.rs @@ -41,7 +41,7 @@ pub struct UpdateByKey { pub fn generate_update_by_unique( collection_name: &models::CollectionName, table_info: &database::TableInfo, - mutations_prefix: &Option, + mutations_prefix: Option<&String>, ) -> Vec<(models::ProcedureName, UpdateMutation)> { table_info .uniqueness_constraints diff --git a/crates/query-engine/translation/src/translation/query/mod.rs b/crates/query-engine/translation/src/translation/query/mod.rs index b87485bb0..806b91c51 100644 --- a/crates/query-engine/translation/src/translation/query/mod.rs +++ b/crates/query-engine/translation/src/translation/query/mod.rs @@ -40,7 +40,7 @@ pub fn translate( name: query_request.collection.clone(), arguments: query_request.arguments.clone(), }, - &None, + None, &query_request.query, )?; diff --git a/crates/query-engine/translation/src/translation/query/relationships.rs b/crates/query-engine/translation/src/translation/query/relationships.rs index 56598da3f..eab8c54b7 100644 --- a/crates/query-engine/translation/src/translation/query/relationships.rs +++ b/crates/query-engine/translation/src/translation/query/relationships.rs @@ -45,10 +45,11 @@ pub fn translate( arguments, }, // We ask to inject the join predicate into the where clause. - &Some(root::JoinPredicate { + Some(root::JoinPredicate { join_with: current_table, relationship, - }), + }) + .as_ref(), &join_field.query, )?; diff --git a/crates/query-engine/translation/src/translation/query/root.rs b/crates/query-engine/translation/src/translation/query/root.rs index 925bc201e..debbb53ae 100644 --- a/crates/query-engine/translation/src/translation/query/root.rs +++ b/crates/query-engine/translation/src/translation/query/root.rs @@ -24,7 +24,7 @@ pub fn translate_query( env: &Env, state: &mut State, make_from: &MakeFrom, - join_predicate: &Option>, + join_predicate: Option<&JoinPredicate<'_, '_>>, query_request: &models::Query, ) -> Result { // translate rows selection. @@ -59,7 +59,7 @@ fn translate_aggregates( env: &Env, state: &mut State, make_from: &MakeFrom, - join_predicate: &Option>, + join_predicate: Option<&JoinPredicate<'_, '_>>, query: &models::Query, ) -> Result, Error> { // fail if no aggregates defined at all @@ -111,7 +111,7 @@ fn translate_rows( env: &Env, state: &mut State, make_from: &MakeFrom, - join_predicate: &Option>, + join_predicate: Option<&JoinPredicate<'_, '_>>, query: &models::Query, ) -> Result<(ReturnsFields, sql::ast::Select), Error> { let (current_table, from_clause) = make_reference_and_from_clause(env, state, make_from)?; @@ -169,7 +169,7 @@ pub fn translate_query_part( env: &Env, state: &mut State, current_table: &TableSourceAndReference, - join_predicate: &Option>, + join_predicate: Option<&JoinPredicate<'_, '_>>, query: &models::Query, select: &mut sql::ast::Select, ) -> Result<(), Error> { @@ -180,8 +180,12 @@ pub fn translate_query_part( }; // translate order_by - let (order_by, order_by_joins) = - sorting::translate(env, state, &root_and_current_tables, &query.order_by)?; + let (order_by, order_by_joins) = sorting::translate( + env, + state, + &root_and_current_tables, + query.order_by.as_ref(), + )?; select.joins.extend(order_by_joins); diff --git a/crates/query-engine/translation/src/translation/query/sorting.rs b/crates/query-engine/translation/src/translation/query/sorting.rs index 92d41615d..cf272ec6a 100644 --- a/crates/query-engine/translation/src/translation/query/sorting.rs +++ b/crates/query-engine/translation/src/translation/query/sorting.rs @@ -23,7 +23,7 @@ pub fn translate( env: &Env, state: &mut State, root_and_current_tables: &RootAndCurrentTables, - order_by: &Option, + order_by: Option<&models::OrderBy>, ) -> Result<(sql::ast::OrderBy, Vec), Error> { let mut joins: Vec = vec![]; // skip if there's no order by clause. @@ -632,7 +632,7 @@ fn process_path_element_for_order_by_targets( current_table: last_table, }, relationship, - &path_element.predicate, + path_element.predicate.as_deref(), sql::ast::SelectList::SelectList(select_cols.aliases_and_expressions()), (table.clone(), from_clause), )?; @@ -767,7 +767,7 @@ fn select_for_path_element( state: &mut State, root_and_current_tables: &RootAndCurrentTables, relationship: &models::Relationship, - predicate: &Option>, + predicate: Option<&models::Expression>, select_list: sql::ast::SelectList, (join_table, from_clause): (TableSourceAndReference, sql::ast::From), ) -> Result { diff --git a/flake.lock b/flake.lock index 5c941ce69..0d37290f3 100644 --- a/flake.lock +++ b/flake.lock @@ -2,11 +2,11 @@ "nodes": { "crane": { "locked": { - "lastModified": 1725409566, - "narHash": "sha256-PrtLmqhM6UtJP7v7IGyzjBFhbG4eOAHT6LPYOFmYfbk=", + "lastModified": 1733016477, + "narHash": "sha256-Hh0khbqBeCtiNS0SJgqdWrQDem9WlPEc2KF5pAY+st0=", "owner": "ipetkov", "repo": "crane", - "rev": "7e4586bad4e3f8f97a9271def747cf58c4b68f3c", + "rev": "76d64e779e2fbaf172110038492343a8c4e29b55", "type": "github" }, "original": { @@ -20,11 +20,11 @@ "systems": "systems" }, "locked": { - "lastModified": 1726560853, - "narHash": "sha256-X6rJYSESBVr3hBoH0WbKE5KvhPU5bloyZ2L4K60/fPQ=", + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", "owner": "numtide", "repo": "flake-utils", - "rev": "c1dfcf08411b08f6b8615f7d8971a2bfa81d5e8a", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", "type": "github" }, "original": { @@ -35,11 +35,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1726585183, - "narHash": "sha256-bZZIY8qD5y+jEE8XeNzflvPlUpkOUlJ6RA4+wN7Xwfg=", + "lastModified": 1733131523, + "narHash": "sha256-YRNSo8DG0QFm3tITM2LR4Iqfzeh6Sw5EvbLSRZ35dag=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "45b95421fdaf52d38ad3c04ae29ad1de260bbcaf", + "rev": "ad8c9282b5b7fb0a7070d620cc33575bb0b5fc01", "type": "github" }, "original": { @@ -63,11 +63,11 @@ ] }, "locked": { - "lastModified": 1726539203, - "narHash": "sha256-u1tAteb4qkH2gGjDY3mN/4Qxa6y798t4G0jNKDyTwv8=", + "lastModified": 1733106880, + "narHash": "sha256-aJmAIjZfWfPSWSExwrYBLRgXVvgF5LP1vaeUGOOIQ98=", "owner": "oxalica", "repo": "rust-overlay", - "rev": "20c8461785d8f5af32d8d4d5c128589e23d7f033", + "rev": "e66c0d43abf5bdefb664c3583ca8994983c332ae", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index 8b3a03206..ffab1edcb 100644 --- a/flake.nix +++ b/flake.nix @@ -106,6 +106,7 @@ pkgs.nixpkgs-fmt pkgs.nodePackages.prettier pkgs.moreutils + pkgs.git # Rust pkgs.bacon diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 1612f132d..4f2ecc353 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,4 +1,4 @@ [toolchain] -channel = "1.81.0" +channel = "1.83.0" profile = "default" # see https://rust-lang.github.io/rustup/concepts/profiles.html components = ["rust-analyzer", "rust-src"] # see https://rust-lang.github.io/rustup/concepts/components.html