Fix some of the clippy errors
This commit is contained in:
parent
e53650d02e
commit
8eec9c6759
6 changed files with 23 additions and 25 deletions
|
|
@ -41,7 +41,7 @@ impl Table {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn table_name(&self) -> &TableName {
|
pub fn table_name(&self) -> &TableName {
|
||||||
&self.schema.table_name()
|
self.schema.table_name()
|
||||||
}
|
}
|
||||||
|
|
||||||
// ======Selection======
|
// ======Selection======
|
||||||
|
|
@ -69,18 +69,18 @@ impl Table {
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn select_all_rows<'a>(&'a self, selected_columns: Vec<Column>) -> impl Iterator<Item=RestrictedRow> + 'a {
|
pub fn select_all_rows(&self, selected_columns: Vec<Column>) -> impl Iterator<Item=RestrictedRow> + '_ {
|
||||||
self.rows
|
self.rows
|
||||||
.values()
|
.values()
|
||||||
.map(move |row| row.restrict_columns(&selected_columns))
|
.map(move |row| row.restrict_columns(&selected_columns))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn select_rows_where_eq<'a>(
|
pub fn select_rows_where_eq(
|
||||||
&'a self,
|
&self,
|
||||||
selected_columns: Vec<Column>,
|
selected_columns: Vec<Column>,
|
||||||
column: Column,
|
column: Column,
|
||||||
value: Value,
|
value: Value,
|
||||||
) -> DbResult<impl Iterator<Item=RestrictedRow> + 'a> {
|
) -> DbResult<impl Iterator<Item=RestrictedRow> + '_> {
|
||||||
let restrict_columns_of_row = move |row: Row| row.restrict_columns(&selected_columns);
|
let restrict_columns_of_row = move |row: Row| row.restrict_columns(&selected_columns);
|
||||||
match value {
|
match value {
|
||||||
Value::Indexable(value) => match self.fetch_ids_from_index(column, &value)? {
|
Value::Indexable(value) => match self.fetch_ids_from_index(column, &value)? {
|
||||||
|
|
@ -116,10 +116,7 @@ impl Table {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (column, column_index) in &mut self.indexes {
|
for (column, column_index) in &mut self.indexes {
|
||||||
match &row[*column] {
|
if let Value::Indexable(val) = &row[*column] { column_index.add(val.clone(), id) }
|
||||||
Value::Indexable(val) => column_index.add(val.clone(), id),
|
|
||||||
_ => {},
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let _ = self.rows.insert(id, row);
|
let _ = self.rows.insert(id, row);
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,7 @@ impl State {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn db_schema<'a>(&'a self) -> DbSchema {
|
pub fn db_schema(&self) -> DbSchema {
|
||||||
let mut schema: DbSchema = Vec::new();
|
let mut schema: DbSchema = Vec::new();
|
||||||
for (table_name, &table_position) in &self.table_name_position_mapping {
|
for (table_name, &table_position) in &self.table_name_position_mapping {
|
||||||
let table_schema = self.tables[table_position].schema();
|
let table_schema = self.tables[table_position].schema();
|
||||||
|
|
@ -64,11 +64,11 @@ impl State {
|
||||||
schema
|
schema
|
||||||
}
|
}
|
||||||
|
|
||||||
fn table_at<'a>(&'a self, table_position: TablePosition) -> &'a Table {
|
fn table_at(&self, table_position: TablePosition) -> &Table {
|
||||||
&self.tables[table_position]
|
&self.tables[table_position]
|
||||||
}
|
}
|
||||||
|
|
||||||
fn table_at_mut<'a>(&'a mut self, table_position: TablePosition) -> &'a mut Table {
|
fn table_at_mut(&mut self, table_position: TablePosition) -> &mut Table {
|
||||||
&mut self.tables[table_position]
|
&mut self.tables[table_position]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,10 @@ impl RestrictedRow {
|
||||||
self.0.len()
|
self.0.len()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn is_empty(&self) -> bool {
|
||||||
|
self.0.is_empty()
|
||||||
|
}
|
||||||
|
|
||||||
pub fn iter(&self) -> impl Iterator<Item=&(Column, Value)> {
|
pub fn iter(&self) -> impl Iterator<Item=&(Column, Value)> {
|
||||||
self.0.iter()
|
self.0.iter()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
use minisql::{operation::Operation, interpreter::DbSchema};
|
use minisql::{operation::Operation, interpreter::DbSchema};
|
||||||
use crate::syntax::RawQuerySyntax;
|
use crate::syntax::RawQuerySyntax;
|
||||||
use nom::{branch::alt, multi::many0, IResult};
|
use nom::{branch::alt, IResult};
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
use crate::{parsing::{create::parse_create, delete::parse_delete, index::parse_create_index, insert::parse_insert, select::parse_select}, validation::{validate_operation, ValidationError}};
|
use crate::{parsing::{create::parse_create, delete::parse_delete, index::parse_create_index, insert::parse_insert, select::parse_select}, validation::{validate_operation, ValidationError}};
|
||||||
|
|
@ -13,7 +13,7 @@ pub enum Error {
|
||||||
ValidationError(#[from] ValidationError)
|
ValidationError(#[from] ValidationError)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse_statement<'a>(input: &'a str) -> IResult<&str, RawQuerySyntax> {
|
fn parse_statement<'a>(input: &'a str) -> IResult<&str, RawQuerySyntax> {
|
||||||
alt((
|
alt((
|
||||||
parse_insert,
|
parse_insert,
|
||||||
parse_create,
|
parse_create,
|
||||||
|
|
@ -25,10 +25,6 @@ pub fn parse_statement<'a>(input: &'a str) -> IResult<&str, RawQuerySyntax> {
|
||||||
))(input)
|
))(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse_statements<'a>(input: &'a str) -> IResult<&str, Vec<RawQuerySyntax>> {
|
|
||||||
many0(parse_statement)(input)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn parse_and_validate(str_query: String, db_schema: &DbSchema) -> Result<Operation, Error> {
|
pub fn parse_and_validate(str_query: String, db_schema: &DbSchema) -> Result<Operation, Error> {
|
||||||
let (_, op) = parse_statement(str_query.as_str())
|
let (_, op) = parse_statement(str_query.as_str())
|
||||||
.map_err(|err| {
|
.map_err(|err| {
|
||||||
|
|
|
||||||
|
|
@ -24,15 +24,15 @@ where
|
||||||
R: AsyncBufRead + Unpin + Send,
|
R: AsyncBufRead + Unpin + Send,
|
||||||
{
|
{
|
||||||
async fn peek_special_message(&mut self) -> Result<Option<SpecialMessage>, ProtoPeekError> {
|
async fn peek_special_message(&mut self) -> Result<Option<SpecialMessage>, ProtoPeekError> {
|
||||||
if let Some(cancel) = try_get_cancel_request(&mut self).await? {
|
if let Some(cancel) = try_get_cancel_request(self).await? {
|
||||||
return Ok(Some(cancel));
|
return Ok(Some(cancel));
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(ssl) = try_get_ssl_request(&mut self).await? {
|
if let Some(ssl) = try_get_ssl_request(self).await? {
|
||||||
return Ok(Some(ssl));
|
return Ok(Some(ssl));
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(startup) = try_get_startup_message(&mut self).await? {
|
if let Some(startup) = try_get_startup_message(self).await? {
|
||||||
return Ok(Some(startup));
|
return Ok(Some(startup));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -43,11 +43,12 @@ where
|
||||||
&mut self,
|
&mut self,
|
||||||
msg: &SpecialMessage,
|
msg: &SpecialMessage,
|
||||||
) -> Result<(), ProtoConsumeError> {
|
) -> Result<(), ProtoConsumeError> {
|
||||||
Ok(match msg {
|
match msg {
|
||||||
SpecialMessage::CancelRequest(_) => consume_cancel_request(self),
|
SpecialMessage::CancelRequest(_) => consume_cancel_request(self),
|
||||||
SpecialMessage::SSLRequest => consume_ssl_request(self),
|
SpecialMessage::SSLRequest => consume_ssl_request(self),
|
||||||
SpecialMessage::StartupMessage(_) => consume_startup_message(self).await?,
|
SpecialMessage::StartupMessage(_) => consume_startup_message(self).await?,
|
||||||
})
|
};
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,12 +20,12 @@ where
|
||||||
{
|
{
|
||||||
async fn write_proto(&mut self, message: T) -> Result<(), ProtoWriteError> {
|
async fn write_proto(&mut self, message: T) -> Result<(), ProtoWriteError> {
|
||||||
let variant = message.variant();
|
let variant = message.variant();
|
||||||
let mut data = message.serialize()?;
|
let data = message.serialize()?;
|
||||||
let length = data.len() as i32 + 4;
|
let length = data.len() as i32 + 4;
|
||||||
|
|
||||||
self.inner.write_u8(variant).await?;
|
self.inner.write_u8(variant).await?;
|
||||||
self.inner.write_i32(length).await?;
|
self.inner.write_i32(length).await?;
|
||||||
self.inner.write_all(&mut data).await?;
|
self.inner.write_all(&data).await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue