Skip to content

Commit

Permalink
Merge pull request prisma#2810 from ever0de/apply-clippy-lint
Browse files Browse the repository at this point in the history
  • Loading branch information
tomhoule authored Mar 30, 2022
2 parents 0f6048e + a98c7e6 commit ecca909
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 22 deletions.
10 changes: 4 additions & 6 deletions libs/datamodel/core/tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,12 +274,10 @@ impl RelationFieldAsserts for dml::RelationField {

impl DatamodelAsserts for dml::Datamodel {
fn assert_has_model(&self, t: &str) -> &dml::Model {
self.find_model(&t.to_owned())
.unwrap_or_else(|| panic!("Model {} not found", t))
self.find_model(t).unwrap_or_else(|| panic!("Model {} not found", t))
}
fn assert_has_enum(&self, t: &str) -> &dml::Enum {
self.find_enum(&t.to_owned())
.unwrap_or_else(|| panic!("Enum {} not found", t))
self.find_enum(t).unwrap_or_else(|| panic!("Enum {} not found", t))
}

fn assert_has_composite_type(&self, t: &str) -> &dml::CompositeType {
Expand All @@ -290,12 +288,12 @@ impl DatamodelAsserts for dml::Datamodel {

impl ModelAsserts for dml::Model {
fn assert_has_scalar_field(&self, t: &str) -> &dml::ScalarField {
self.find_scalar_field(&t.to_owned())
self.find_scalar_field(t)
.unwrap_or_else(|| panic!("Field {} not found", t))
}

fn assert_has_relation_field(&self, t: &str) -> &dml::RelationField {
self.find_relation_field(&t.to_owned())
self.find_relation_field(t)
.unwrap_or_else(|| panic!("Field {} not found", t))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ fn escaped_characters_in_string_defaults(api: TestApi) {
"sideNames" TEXT DEFAULT E'top\ndown'
);
"#;
api.raw_cmd(&init);
api.raw_cmd(init);
let schema = api.describe();
let table = schema.table_bang("Fruit");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ fn advisory_locking_works(mut api: TestApi) {
);

let output = first_me
.create_migration("01initial".into(), &dm, &migrations_directory)
.create_migration("01initial", &dm, &migrations_directory)
.draft(true)
.send_sync();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ fn soft_resets_work_on_cockroachdb(mut api: TestApi) {
CREATE VIEW "catcat" AS SELECT name, meowmeow FROM "Cat" LIMIT 2;
"#;

api.raw_cmd(&initial);
api.raw_cmd(initial);
api.assert_schema().assert_tables_count(1).assert_has_table("Cat");
api.reset().soft(true).send_sync();
api.assert_schema().assert_tables_count(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ fn foreign_key_renaming_to_default_works(api: TestApi) {
}
"#;

let migration = api.connector_diff(DiffTarget::Database, DiffTarget::Datamodel(target_schema.into()));
let migration = api.connector_diff(DiffTarget::Database, DiffTarget::Datamodel(target_schema));
let expected = expect![[r#"
BEGIN TRY
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ fn foreign_key_renaming_to_default_works(api: TestApi) {
}
"#;

let migration = api.connector_diff(DiffTarget::Database, DiffTarget::Datamodel(target_schema.into()));
let migration = api.connector_diff(DiffTarget::Database, DiffTarget::Datamodel(target_schema));
let expected = expect![[r#"
-- RenameForeignKey
ALTER TABLE "Dog" RENAME CONSTRAINT "favouriteFood" TO "Dog_favourite_food_id_fkey";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ mod mongo_incorrect_fields {
}

fn run_command_raw(command: serde_json::Value) -> String {
let command = command.to_string().replace("\"", "\\\"");
let command = command.to_string().replace('\"', "\\\"");

format!(r#"mutation {{ runCommandRaw(command: "{}") }}"#, command)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,16 +233,16 @@ mod raw_mongo {
}

fn find_raw(filter: Option<serde_json::Value>, options: Option<serde_json::Value>) -> String {
let filter = filter.map(|q| format!(r#"filter: "{}""#, q.to_string().replace("\"", "\\\"")));
let options = options.map(|o| format!(r#"options: "{}""#, o.to_string().replace("\"", "\\\"")));
let filter = filter.map(|q| format!(r#"filter: "{}""#, q.to_string().replace('\"', "\\\"")));
let options = options.map(|o| format!(r#"options: "{}""#, o.to_string().replace('\"', "\\\"")));

match (filter, options) {
(None, None) => r#"query { findTestModelRaw }"#.to_string(),
(q, o) => {
format!(
r#"query {{ findTestModelRaw({} {}) }}"#,
q.unwrap_or("".to_string()),
o.unwrap_or("".to_string())
q.unwrap_or_else(|| "".to_string()),
o.unwrap_or_else(|| "".to_string())
)
}
}
Expand All @@ -251,26 +251,26 @@ mod raw_mongo {
fn aggregate_raw(pipeline: Option<Vec<serde_json::Value>>, options: Option<serde_json::Value>) -> String {
let pipeline = pipeline.map(|p| {
p.into_iter()
.map(|stage| format!(r#""{}""#, stage.to_string().replace("\"", "\\\"")))
.map(|stage| format!(r#""{}""#, stage.to_string().replace('\"', "\\\"")))
.collect::<Vec<_>>()
});
let pipeline = pipeline.map(|p| format!(r#"pipeline: [{}]"#, p.join(", ")));
let options = options.map(|o| format!(r#"options: "{}""#, o.to_string().replace("\"", "\\\"")));
let options = options.map(|o| format!(r#"options: "{}""#, o.to_string().replace('\"', "\\\"")));

match (pipeline, options) {
(None, None) => r#"query { aggregateTestModelRaw }"#.to_string(),
(p, o) => {
format!(
r#"query {{ aggregateTestModelRaw({} {}) }}"#,
p.unwrap_or("".to_string()),
o.unwrap_or("".to_string())
p.unwrap_or_else(|| "".to_string()),
o.unwrap_or_else(|| "".to_string())
)
}
}
}

fn run_command_raw(command: serde_json::Value) -> String {
let command = command.to_string().replace("\"", "\\\"");
let command = command.to_string().replace('\"', "\\\"");

format!(r#"mutation {{ runCommandRaw(command: "{}") }}"#, command)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ pub(crate) fn composite_equality_object(ctx: &mut BuilderContext, cf: &Composite

let mut fields = vec![];

let input_fields = cf.typ.fields().into_iter().map(|f| match f {
let input_fields = cf.typ.fields().iter().map(|f| match f {
ModelField::Scalar(sf) => input_field(sf.name.clone(), map_scalar_input_type_for_field(ctx, &sf), None)
.optional_if(!sf.is_required())
.nullable_if(!sf.is_required() && !sf.is_list()),
Expand Down

0 comments on commit ecca909

Please sign in to comment.