Skip to content

Commit e2d7594

Browse files
committed
Cargo fix + cargo clippy for wundergraph_cli
1 parent 84a0c51 commit e2d7594

File tree

12 files changed

+81
-314
lines changed

12 files changed

+81
-314
lines changed

wundergraph_cli/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ readme = "../README.md"
88
keywords = ["GraphQL", "ORM", "PostgreSQL", "SQLite"]
99
categories = ["database", "web-programming"]
1010
description = "A helper tool to generate some code for using wundergraph with existing databases"
11+
edition = "2018"
1112

1213
[dependencies]
1314
structopt = "0.2"

wundergraph_cli/src/database.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ pub enum InferConnection {
6767
}
6868

6969
impl InferConnection {
70-
pub fn establish(database_url: &str) -> Result<Self, Box<Error>> {
70+
pub fn establish(database_url: &str) -> Result<Self, Box<dyn Error>> {
7171
match Backend::for_url(database_url) {
7272
#[cfg(feature = "postgres")]
7373
Backend::Pg => PgConnection::establish(database_url).map(InferConnection::Pg),

wundergraph_cli/src/infer_schema_internals/data_structures.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub struct ColumnType {
2828
use std::fmt;
2929

3030
impl fmt::Display for ColumnType {
31-
fn fmt(&self, out: &mut fmt::Formatter) -> Result<(), fmt::Error> {
31+
fn fmt(&self, out: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
3232
if self.is_nullable {
3333
write!(out, "Nullable<")?;
3434
}
Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,39 @@
1-
#![cfg_attr(feature = "cargo-clippy", allow(expect_fun_call))] // My calls are so fun
2-
31
use super::data_structures::ForeignKeyConstraint;
42
use super::inference::get_primary_keys;
53
use super::table_data::TableName;
6-
use database::InferConnection;
4+
use crate::database::InferConnection;
75

86
pub fn remove_unsafe_foreign_keys_for_codegen(
97
database_url: &str,
108
foreign_keys: &[ForeignKeyConstraint],
119
safe_tables: &[TableName],
1210
) -> Vec<ForeignKeyConstraint> {
1311
let conn = InferConnection::establish(database_url)
14-
.expect(&format!("Could not connect to `{}`", database_url));
12+
.unwrap_or_else(|_| panic!("Could not connect to `{}`", database_url));
1513

1614
let duplicates = foreign_keys
1715
.iter()
18-
.map(|fk| fk.ordered_tables())
16+
.map(ForeignKeyConstraint::ordered_tables)
1917
.filter(|tables| {
2018
let dup_count = foreign_keys
2119
.iter()
2220
.filter(|fk| tables == &fk.ordered_tables())
2321
.count();
2422
dup_count > 1
25-
}).collect::<Vec<_>>();
23+
})
24+
.collect::<Vec<_>>();
2625

2726
foreign_keys
2827
.iter()
2928
.filter(|fk| fk.parent_table != fk.child_table)
3029
.filter(|fk| safe_tables.contains(&fk.parent_table))
3130
.filter(|fk| safe_tables.contains(&fk.child_table))
3231
.filter(|fk| {
33-
let pk_columns = get_primary_keys(&conn, &fk.parent_table).expect(&format!(
34-
"Error loading primary keys for `{}`",
35-
fk.parent_table
36-
));
32+
let pk_columns = get_primary_keys(&conn, &fk.parent_table)
33+
.unwrap_or_else(|_| panic!("Error loading primary keys for `{}`", fk.parent_table));
3734
pk_columns.len() == 1 && pk_columns[0] == fk.primary_key
38-
}).filter(|fk| !duplicates.contains(&fk.ordered_tables()))
35+
})
36+
.filter(|fk| !duplicates.contains(&fk.ordered_tables()))
3937
.cloned()
4038
.collect()
4139
}

wundergraph_cli/src/infer_schema_internals/inference.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use diesel::result::Error::NotFound;
44

55
use super::data_structures::*;
66
use super::table_data::*;
7-
use database::InferConnection;
7+
use crate::database::InferConnection;
88

99
static RESERVED_NAMES: &[&str] = &[
1010
"abstract", "alignof", "as", "become", "box", "break", "const", "continue", "crate", "do",
@@ -17,8 +17,8 @@ static RESERVED_NAMES: &[&str] = &[
1717
pub fn load_table_names(
1818
database_url: &str,
1919
schema_name: Option<&str>,
20-
) -> Result<Vec<TableName>, Box<Error>> {
21-
let connection = try!(InferConnection::establish(database_url));
20+
) -> Result<Vec<TableName>, Box<dyn Error>> {
21+
let connection = r#try!(InferConnection::establish(database_url));
2222

2323
match connection {
2424
#[cfg(feature = "sqlite")]
@@ -33,7 +33,7 @@ pub fn load_table_names(
3333
fn get_column_information(
3434
conn: &InferConnection,
3535
table: &TableName,
36-
) -> Result<Vec<ColumnInformation>, Box<Error>> {
36+
) -> Result<Vec<ColumnInformation>, Box<dyn Error>> {
3737
let column_info = match *conn {
3838
#[cfg(feature = "sqlite")]
3939
InferConnection::Sqlite(ref c) => super::sqlite::get_table_data(c, table),
@@ -52,7 +52,7 @@ fn get_column_information(
5252
fn determine_column_type(
5353
attr: &ColumnInformation,
5454
conn: &InferConnection,
55-
) -> Result<ColumnType, Box<Error>> {
55+
) -> Result<ColumnType, Box<dyn Error>> {
5656
match *conn {
5757
#[cfg(feature = "sqlite")]
5858
InferConnection::Sqlite(_) => super::sqlite::determine_column_type(attr),
@@ -66,8 +66,8 @@ fn determine_column_type(
6666
pub(crate) fn get_primary_keys(
6767
conn: &InferConnection,
6868
table: &TableName,
69-
) -> Result<Vec<String>, Box<Error>> {
70-
let primary_keys: Vec<String> = try!(match *conn {
69+
) -> Result<Vec<String>, Box<dyn Error>> {
70+
let primary_keys: Vec<String> = r#try!(match *conn {
7171
#[cfg(feature = "sqlite")]
7272
InferConnection::Sqlite(ref c) => super::sqlite::get_primary_keys(c, table),
7373
#[cfg(feature = "postgres")]
@@ -89,8 +89,8 @@ pub(crate) fn get_primary_keys(
8989
pub fn load_foreign_key_constraints(
9090
database_url: &str,
9191
schema_name: Option<&str>,
92-
) -> Result<Vec<ForeignKeyConstraint>, Box<Error>> {
93-
let connection = try!(InferConnection::establish(database_url));
92+
) -> Result<Vec<ForeignKeyConstraint>, Box<dyn Error>> {
93+
let connection = r#try!(InferConnection::establish(database_url));
9494

9595
let constraints = match connection {
9696
#[cfg(feature = "sqlite")]
@@ -122,7 +122,7 @@ macro_rules! doc_comment {
122122
};
123123
}
124124

125-
pub fn load_table_data(database_url: &str, name: TableName) -> Result<TableData, Box<Error>> {
125+
pub fn load_table_data(database_url: &str, name: TableName) -> Result<TableData, Box<dyn Error>> {
126126
let connection = InferConnection::establish(database_url)?;
127127
let docs = doc_comment!(
128128
"Representation of the `{}` table.
@@ -167,7 +167,7 @@ pub fn load_table_data(database_url: &str, name: TableName) -> Result<TableData,
167167
rust_name,
168168
has_default: c.has_default,
169169
})
170-
}).collect::<Result<_, Box<Error>>>()?;
170+
}).collect::<Result<_, Box<dyn Error>>>()?;
171171

172172
Ok(TableData {
173173
name,

0 commit comments

Comments
 (0)