Skip to content

Commit

Permalink
chore: fix clippy (#4625)
Browse files Browse the repository at this point in the history
* chore(query-engine-wasm): fix clippy

* chore(query-engine-wasm): fix clippy

* chore(query-engine-wasm): fix clippy

* chore(query-engine-wasm): fix clippy

* chore(query-engine-wasm): fix clippy

* chore(query-engine-wasm): fix clippy
  • Loading branch information
jkomyno authored Jan 3, 2024
1 parent 01382e5 commit 0ac27a9
Show file tree
Hide file tree
Showing 21 changed files with 28 additions and 29 deletions.
4 changes: 2 additions & 2 deletions psl/parser-database/src/attributes/default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ fn validate_dbgenerated_args(args: &[ast::Argument], accept: AcceptFn<'_>, ctx:
bail()
}

match args.get(0).map(|arg| &arg.value) {
match args.first().map(|arg| &arg.value) {
Some(ast::Expression::StringValue(val, _)) if val.is_empty() => {
ctx.push_attribute_validation_error(
"dbgenerated() takes either no argument, or a single nonempty string argument.",
Expand All @@ -382,7 +382,7 @@ fn validate_nanoid_args(args: &[ast::Argument], accept: AcceptFn<'_>, ctx: &mut
bail()
}

match args.get(0).map(|arg| &arg.value) {
match args.first().map(|arg| &arg.value) {
Some(ast::Expression::NumericValue(val, _)) if val.parse::<u8>().unwrap() < 2 => {
ctx.push_attribute_validation_error(
"`nanoid()` takes either no argument, or a single integer argument >= 2.",
Expand Down
2 changes: 1 addition & 1 deletion quaint/src/connector/mssql/native/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ impl Queryable for Mssql {
let rows = self.query_raw(query, &[]).await?;

let version_string = rows
.get(0)
.first()
.and_then(|row| row.get("version").and_then(|version| version.to_string()));

Ok(version_string)
Expand Down
2 changes: 1 addition & 1 deletion quaint/src/connector/mysql/native/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ impl Queryable for Mysql {
let rows = timeout::socket(self.socket_timeout, self.query_raw(query, &[])).await?;

let version_string = rows
.get(0)
.first()
.and_then(|row| row.get("version").and_then(|version| version.typed.to_string()));

Ok(version_string)
Expand Down
2 changes: 1 addition & 1 deletion quaint/src/connector/postgres/native/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ impl Queryable for PostgreSql {
let rows = self.query_raw(query, &[]).await?;

let version_string = rows
.get(0)
.first()
.and_then(|row| row.get("version").and_then(|version| version.to_string()));

Ok(version_string)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ mod string;
mod time;

pub use bytes::*;
pub use json::*;
pub use querying::*;
pub use raw::*;
pub use string::*;
pub use time::*;
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ impl QueryParams {
pub fn parse_many_first(&self, json: serde_json::Value, path: &[&str]) -> Result<String, TestError> {
let val = self.where_many.parse(&json, path)?;

Ok(val.get(0).unwrap().to_owned())
Ok(val.first().unwrap().to_owned())
}

/// Parses the JSON _array_ result of a mutation sent to the Query Engine in order to extract the generated id(s).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ impl OrderByPrefix {
}

pub(crate) fn first(&self) -> Option<&String> {
self.parts.get(0)
self.parts.first()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ pub async fn m2m_connect<'conn>(
let child_ids = child_ids
.iter()
.map(|child_id| {
let (selection, value) = child_id.pairs.get(0).unwrap();
let (selection, value) = child_id.pairs.first().unwrap();

(selection, value.clone())
.into_bson()
Expand Down Expand Up @@ -404,7 +404,7 @@ pub async fn m2m_disconnect<'conn>(
let child_ids = child_ids
.iter()
.map(|child_id| {
let (field, value) = child_id.pairs.get(0).unwrap();
let (field, value) = child_id.pairs.first().unwrap();

(field, value.clone())
.into_bson()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ fn take_last_two_elem<T>(slice: &[T]) -> (Option<&T>, Option<&T>) {

match len {
0 => (None, None),
1 => (None, slice.get(0)),
1 => (None, slice.first()),
_ => (slice.get(len - 2), slice.get(len - 1)),
}
}
2 changes: 1 addition & 1 deletion query-engine/core/src/executor/execute_operation.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![cfg_attr(target_arch = "wasm32", allow(unused_variables))]
#![allow(unused_variables)]
#![cfg_attr(not(feature = "metrics"), allow(clippy::let_and_return))]

use super::pipeline::QueryPipeline;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::borrow::Cow;
use std::str::FromStr;

pub use crate::types::{ColumnType, JSResultSet, Query, TransactionOptions};
pub use crate::types::{ColumnType, JSResultSet};
use quaint::bigdecimal::{BigDecimal, FromPrimitive};
use quaint::chrono::{DateTime, NaiveDate, NaiveTime, Utc};
use quaint::{
Expand Down
1 change: 0 additions & 1 deletion query-engine/driver-adapters/src/conversion/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,3 @@ pub(crate) mod postgres;
pub(crate) mod sqlite;

pub use js_arg::JSArg;
pub use js_to_quaint::*;
2 changes: 1 addition & 1 deletion query-engine/driver-adapters/src/proxy.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::send_future::UnsafeFuture;
use crate::types::JsConnectionInfo;
pub use crate::types::{ColumnType, JSResultSet, Query, TransactionOptions};
pub use crate::types::{JSResultSet, Query, TransactionOptions};
use crate::{
from_js_value, get_named_property, get_optional_named_property, to_rust_str, AdapterMethod, JsObject, JsResult,
JsString, JsTransaction,
Expand Down
1 change: 1 addition & 0 deletions query-engine/query-engine-wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ mod arch {
pub(crate) type Result<T> = std::result::Result<T, error::ApiError>;
}

#[cfg_attr(not(target_arch = "wasm32"), allow(unused_imports))]
pub use arch::*;
6 changes: 4 additions & 2 deletions query-engine/query-structure/src/default_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ impl DefaultKind {
// intended for primary key values!
pub fn to_dbgenerated_func(&self) -> Option<String> {
match self {
DefaultKind::Expression(ref expr) if expr.is_dbgenerated() => expr.args.get(0).map(|val| val.1.to_string()),
DefaultKind::Expression(ref expr) if expr.is_dbgenerated() => {
expr.args.first().map(|val| val.1.to_string())
}
_ => None,
}
}
Expand Down Expand Up @@ -217,7 +219,7 @@ impl ValueGenerator {
return None;
}

self.args.get(0).and_then(|v| v.1.as_string())
self.args.first().and_then(|v| v.1.as_string())
}

#[cfg(feature = "default_generators")]
Expand Down
4 changes: 2 additions & 2 deletions query-engine/query-structure/src/field/scalar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ pub fn dml_default_kind(default_value: &ast::Expression, scalar_type: Option<Sca
ast::Expression::Function(funcname, args, _) if funcname == "dbgenerated" => {
DefaultKind::Expression(ValueGenerator::new_dbgenerated(
args.arguments
.get(0)
.first()
.and_then(|arg| arg.value.as_string_value())
.map(|(val, _)| val.to_owned())
.unwrap_or_else(String::new),
Expand All @@ -231,7 +231,7 @@ pub fn dml_default_kind(default_value: &ast::Expression, scalar_type: Option<Sca
ast::Expression::Function(funcname, args, _) if funcname == "nanoid" => {
DefaultKind::Expression(ValueGenerator::new_nanoid(
args.arguments
.get(0)
.first()
.and_then(|arg| arg.value.as_numeric_value())
.map(|(val, _)| val.parse::<u8>().unwrap()),
))
Expand Down
1 change: 0 additions & 1 deletion query-engine/query-structure/src/filter/scalar/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ mod compare;
mod condition;
mod projection;

pub use compare::*;
pub use condition::*;
pub use projection::*;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ where

let version =
schema_exists_result
.get(0)
.first()
.and_then(|row| row.at(1).and_then(|ver_str| row.at(2).map(|ver_num| (ver_str, ver_num))))
.and_then(|(ver_str,ver_num)| ver_str.to_string().and_then(|version| ver_num.as_integer().map(|version_number| (version, version_number))));

Expand Down Expand Up @@ -625,7 +625,7 @@ where
}

if let Some(true) = schema_exists_result
.get(0)
.first()
.and_then(|row| row.at(0).and_then(|value| value.as_bool()))
{
return Ok((circumstances, connection))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ impl<'a> DefaultValuePair<'a> {
Some(previous) if previous.is_nanoid() => {
let length = previous.value().as_function().and_then(|(_, args, _)| {
args.arguments
.get(0)
.first()
.map(|arg| arg.value.as_numeric_value().unwrap().0.parse::<u8>().unwrap())
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub(crate) fn calculate_sql_schema(datamodel: &ValidatedSchema, flavour: &dyn Sq
schemas: Default::default(),
};

if let Some(ds) = context.datamodel.configuration.datasources.get(0) {
if let Some(ds) = context.datamodel.configuration.datasources.first() {
for (schema, _) in &ds.namespaces {
context
.schemas
Expand Down Expand Up @@ -608,6 +608,6 @@ fn unwrap_dbgenerated(expr: &ast::Expression) -> Option<String> {
.unwrap()
.1
.arguments
.get(0)
.first()
.map(|arg| arg.value.as_string_value().unwrap().0.to_owned())
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub(super) enum Token {
Identifier,
UnterminatedStringLiteral,
Whitespace,
BadToken,
Unknown,
}

pub(super) fn tokenize(default_string: &str) -> Vec<(Token, u32)> {
Expand All @@ -43,7 +43,7 @@ pub(super) fn tokenize(default_string: &str) -> Vec<(Token, u32)> {
out.push((Token::CastOperator, start))
}
None | Some(_) => {
out.push((Token::BadToken, start));
out.push((Token::Unknown, start));
return out;
}
},
Expand Down Expand Up @@ -164,7 +164,7 @@ pub(super) fn tokenize(default_string: &str) -> Vec<(Token, u32)> {
}
}
},
Some((start, _)) => out.push((Token::BadToken, start)),
Some((start, _)) => out.push((Token::Unknown, start)),
}
}
}

0 comments on commit 0ac27a9

Please sign in to comment.