Clippy
This commit is contained in:
parent
8eec9c6759
commit
2ba158a0d4
7 changed files with 41 additions and 18 deletions
|
|
@ -7,6 +7,13 @@ pub struct ColumnIndex {
|
|||
index: BTreeMap<IndexableValue, HashSet<Uuid>>,
|
||||
}
|
||||
|
||||
// To satisfy clippy.
|
||||
impl Default for ColumnIndex {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl ColumnIndex {
|
||||
pub fn new() -> Self {
|
||||
let index = BTreeMap::new();
|
||||
|
|
|
|||
|
|
@ -39,6 +39,13 @@ impl FromIterator<Value> for Row {
|
|||
}
|
||||
}
|
||||
|
||||
// To satisfy clippy.
|
||||
impl Default for Row {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl Row {
|
||||
pub fn new() -> Self {
|
||||
Self(vec![])
|
||||
|
|
|
|||
|
|
@ -47,6 +47,13 @@ impl std::fmt::Debug for Response<'_> {
|
|||
}
|
||||
}
|
||||
|
||||
// To satisfy clippy.
|
||||
impl Default for State {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl State {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ pub enum Error {
|
|||
ValidationError(#[from] ValidationError)
|
||||
}
|
||||
|
||||
fn parse_statement<'a>(input: &'a str) -> IResult<&str, RawQuerySyntax> {
|
||||
fn parse_statement(input: &str) -> IResult<&str, RawQuerySyntax> {
|
||||
alt((
|
||||
parse_insert,
|
||||
parse_create,
|
||||
|
|
|
|||
|
|
@ -28,9 +28,10 @@ pub fn parse_number(input: &str) -> IResult<&str, Value> {
|
|||
Some((_fsign, fdigits)) => {
|
||||
// Combine integer and fractional parts
|
||||
let combined_parts = format!(
|
||||
"{}{}",
|
||||
format!("{}{}", sign.unwrap_or('+'), digits),
|
||||
format!(".{}", fdigits)
|
||||
"{}{}.{}",
|
||||
sign.unwrap_or('+'),
|
||||
digits,
|
||||
fdigits
|
||||
);
|
||||
// Parse the combined parts as a floating-point number
|
||||
let value = combined_parts.parse::<f64>()
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ pub fn try_parse_column_selection(input: &str) -> IResult<&str, ColumnSelection>
|
|||
});
|
||||
let columns_parser = map(
|
||||
separated_list0(terminated(char(','), multispace0), parse_column_name),
|
||||
|names| ColumnSelection::Columns(names),
|
||||
ColumnSelection::Columns,
|
||||
);
|
||||
alt((all_parser, columns_parser))(input)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ fn validate_table_exists<'a>(db_schema: &DbSchema<'a>, table_name: &'a TableName
|
|||
|
||||
fn validate_create_table(raw_table_schema: RawTableSchema, db_schema: &DbSchema) -> Result<Operation, ValidationError> {
|
||||
let table_name: &TableName = &raw_table_schema.table_name;
|
||||
if let Some(_) = get_table_schema(db_schema, &table_name) {
|
||||
if get_table_schema(db_schema, table_name).is_some() {
|
||||
return Err(ValidationError::TableAlreadyExists(table_name.to_string()));
|
||||
}
|
||||
|
||||
|
|
@ -89,10 +89,11 @@ fn validate_table_schema(raw_table_schema: RawTableSchema) -> Result<TableSchema
|
|||
}
|
||||
|
||||
// Ensure it has exactly one primary key that has correct type.
|
||||
if primary_keys.len() == 0 {
|
||||
return Err(ValidationError::PrimaryKeyMissing(raw_table_schema.table_name.clone()))
|
||||
} else if primary_keys.len() > 1 {
|
||||
return Err(ValidationError::MultiplePrimaryKeysFound(raw_table_schema.table_name.clone()))
|
||||
let number_of_primary_keys = primary_keys.len();
|
||||
if number_of_primary_keys == 0 {
|
||||
Err(ValidationError::PrimaryKeyMissing(raw_table_schema.table_name.clone()))
|
||||
} else if number_of_primary_keys > 1 {
|
||||
Err(ValidationError::MultiplePrimaryKeysFound(raw_table_schema.table_name.clone()))
|
||||
} else {
|
||||
let (primary_column_name, primary_key_type) = primary_keys[0].clone();
|
||||
if primary_key_type == DbType::Uuid {
|
||||
|
|
@ -113,18 +114,18 @@ fn validate_select(table_name: TableName, column_selection: syntax::ColumnSelect
|
|||
syntax::ColumnSelection::Columns(columns) => {
|
||||
let non_existant_columns: Vec<ColumnName> =
|
||||
columns.iter().filter_map(|column|
|
||||
if schema.does_column_exist(&column) {
|
||||
if schema.does_column_exist(column) {
|
||||
None
|
||||
} else {
|
||||
Some(column.clone())
|
||||
}).collect();
|
||||
if non_existant_columns.len() > 0 {
|
||||
Err(ValidationError::ColumnsDoNotExist(non_existant_columns))
|
||||
} else {
|
||||
if non_existant_columns.is_empty() {
|
||||
let selection: operation::ColumnSelection =
|
||||
columns.iter().filter_map(|column_name| schema.get_column(column_name)).collect();
|
||||
let validated_condition = validate_condition(condition, schema)?;
|
||||
Ok(Operation::Select(table_position, selection, validated_condition))
|
||||
} else {
|
||||
Err(ValidationError::ColumnsDoNotExist(non_existant_columns))
|
||||
}
|
||||
}
|
||||
syntax::ColumnSelection::All => {
|
||||
|
|
@ -149,11 +150,11 @@ fn validate_insert(table_name: TableName, insertion_values: syntax::InsertionVal
|
|||
let columns_in_query: HashSet<&ColumnName> = HashSet::from_iter(columns_in_query_vec);
|
||||
let columns_in_schema: HashSet<&ColumnName> = HashSet::from_iter(schema.get_columns());
|
||||
let non_existant_columns = Vec::from_iter(columns_in_query.difference(&columns_in_schema));
|
||||
if non_existant_columns.len() > 0 {
|
||||
if !non_existant_columns.is_empty() {
|
||||
return Err(ValidationError::ColumnsDoNotExist(non_existant_columns.iter().map(|column_name| column_name.to_string()).collect()));
|
||||
}
|
||||
let missing_required_columns = Vec::from_iter(columns_in_schema.difference(&columns_in_query));
|
||||
if missing_required_columns.len() > 0 {
|
||||
if !missing_required_columns.is_empty() {
|
||||
return Err(ValidationError::RequiredColumnsAreMissing(missing_required_columns.iter().map(|str| str.to_string()).collect()));
|
||||
}
|
||||
|
||||
|
|
@ -194,7 +195,7 @@ fn validate_condition(condition: Option<syntax::Condition>, schema: &TableSchema
|
|||
if expected_type.eq(&value_type) {
|
||||
Ok(Some(operation::Condition::Eq(column, value)))
|
||||
} else {
|
||||
return Err(ValidationError::TypeMismatch { column_name: column_name.to_string(), received_type: value_type, expected_type });
|
||||
Err(ValidationError::TypeMismatch { column_name: column_name.to_string(), received_type: value_type, expected_type })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -228,7 +229,7 @@ where T: Eq + std::hash::Hash
|
|||
if already_seen_elements.contains(t) {
|
||||
return Some(t);
|
||||
} else {
|
||||
already_seen_elements.insert(&t);
|
||||
already_seen_elements.insert(t);
|
||||
}
|
||||
}
|
||||
None
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue