Skip to content

Commit

Permalink
add list capabilities
Browse files Browse the repository at this point in the history
  • Loading branch information
siscia committed Apr 18, 2020
1 parent e4124b9 commit 6d9da5e
Showing 1 changed file with 24 additions and 8 deletions.
32 changes: 24 additions & 8 deletions parser/src/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ pub enum Action {
Update,
New,
Show,
List,
}

#[derive(Debug, PartialEq, Clone)]
pub struct Statement<'s> {
database: &'s str,
action: Action,
stmt_name: &'s str,
stmt_name: Option<&'s str>,
stmt_query: Option<&'s str>,
now: bool,
can_update: bool,
Expand All @@ -27,22 +28,23 @@ impl Statement<'static> {
pub fn get_command(self, client: BlockedClient) -> Command {
match self.action {
Action::Delete => Command::DeleteStatement {
identifier: self.stmt_name,
identifier: self.stmt_name.unwrap(),
client,
},
Action::Update => Command::UpdateStatement {
identifier: self.stmt_name,
identifier: self.stmt_name.unwrap(),
statement: self.stmt_query.unwrap(),
can_create: self.can_create,
client,
},
Action::New => Command::CompileStatement {
identifier: self.stmt_name,
identifier: self.stmt_name.unwrap(),
statement: self.stmt_query.unwrap(),
can_update: self.can_update,
client,
},
Action::Show => todo!(),
Action::List => todo!(),
}
}
pub fn is_now(&self) -> bool {
Expand All @@ -52,7 +54,7 @@ impl Statement<'static> {
self.action
}
pub fn identifier(&self) -> &'static str {
self.stmt_name
self.stmt_name.unwrap()
}
pub fn statement(&self) -> &'static str {
self.stmt_query.unwrap()
Expand Down Expand Up @@ -83,15 +85,29 @@ impl<'s> CommandV2<'s> for Statement<'s> {
"UPDATE" => Action::Update,
"NEW" => Action::New,
"SHOW" => Action::Show,
"LIST" => Action::List,
_ => return Err(RediSQLError::with_code(23,
"You provide a command for the statement that is not supported".to_string(),
"Statement command unknow".to_string()))
}
}
};
let stmt_name = match args_iter.next() {
Some(s) => s,
None => return Err(RediSQLError::with_code(19, "You should provide the name of the statement to operate with".to_string(), "Statement command with statement name".to_string())),
let stmt_name = match action {
Action::List => {
if args_iter.next().is_some() {
return Err(RediSQLError::with_code(25, "You should not provide the name of the statement to list".to_string(), "Statement LIST command with statement name".to_string()));
}
None
}
Action::New
| Action::Update
| Action::Delete
| Action::Show => match args_iter.next() {
Some(s) => Some(*s),
None => {
return Err(RediSQLError::with_code(19, "You should provide the name of the statement to operate with".to_string(), "Statement command with statement name".to_string()));
}
},
};
let stmt_query = match action {
Action::Update | Action::New => match args_iter.next() {
Expand Down

0 comments on commit 6d9da5e

Please sign in to comment.