Skip to content

Commit

Permalink
fix: truncate and linting
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielHe4rt committed Aug 21, 2024
1 parent 1665d24 commit f442ac7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 19 deletions.
4 changes: 2 additions & 2 deletions src/commands/setup_multi_dc_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub async fn handle(
rf.push_str(dc.as_str());
}
rf.pop();
rf.push_str("}");
rf.push('}');

let keyspace = keyspace.as_str();
let keyspace_query = format!("ALTER KEYSPACE {} WITH replication = ", keyspace);
Expand All @@ -23,7 +23,7 @@ pub async fn handle(
("system_auth", "ALTER KEYSPACE system_auth WITH replication = "),
("system_distributed", "ALTER KEYSPACE system_distributed WITH replication = "),
("system_traces", "ALTER KEYSPACE system_traces WITH replication = "),
(&keyspace, keyspace_query.as_str()),
(keyspace, keyspace_query.as_str()),
];

for (table, query) in queries {
Expand Down
26 changes: 12 additions & 14 deletions src/commands/table_actions_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,12 @@ pub async fn handle(

let keyspace_specs = keyspace_info.get(&keyspace).expect("Keyspace not found");

println!("Keyspace: {}", keyspace);
for table in keyspace_specs.tables.iter() {
println!(" - T: {}", table.0);
}
for table in keyspace_specs.views.iter() {
println!(" - MV: {}", table.0);
}

if action.is_some() || suffix.is_some() {
list_actions();
execute_actions(session, keyspace, keyspace_specs, action.unwrap(), suffix.unwrap().as_str()).await?;
return Ok(());
}

list_actions();

list_actions(keyspace.clone(), keyspace_specs);
stdin.read_line(&mut buffer)?;

let choice = buffer.trim().parse::<u8>()?;
Expand All @@ -48,7 +38,15 @@ pub async fn handle(
Ok(())
}

fn list_actions() {
fn list_actions(keyspace: String, keyspace_specs: &Keyspace) {
println!("Keyspace: {}", keyspace);
for table in keyspace_specs.tables.iter() {
println!(" - T: {}", table.0);
}
for table in keyspace_specs.views.iter() {
println!(" - MV: {}", table.0);
}

println!("What do you want to do?");
println!(" > 1. Truncate Tables");
println!(" > 2. Drop Tables");
Expand All @@ -66,9 +64,9 @@ async fn execute_actions(session: Session, keyspace: String, keyspace_specs: &Ke

match choice {
1 => {
for (operation, table_name) in tables {
for (_, table_name) in tables {
if table_name.ends_with(suffix) {
let query = format!("TRUNCATE {} {}.{};", operation, keyspace, table_name);
let query = format!("TRUNCATE {}.{};", keyspace, table_name);
println!(" > Truncating table: {}", table_name);
session.query(query, []).await?;
} else {
Expand Down
6 changes: 3 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@ async fn main() -> anyhow::Result<()> {
match args.command {
Some(Commands::Keyspace { keyspace, replication_factor, drop, without_tablets, connection }) => {
let connection = connection::setup_connection(&connection).await;
println!("{} {}", "Action: ".cyan(), "New Keyspace");
println!("{} New Keyspace", "Action: ".cyan());
keyspace_command::handle(connection, keyspace, replication_factor, without_tablets, drop).await;
},
Some(Commands::MultiDC { replication_factor, dcs, keyspace, connection}) => {
let connection = connection::setup_connection(&connection).await;
println!("{} {}", "Action: ".cyan(), "Multi DC Setup");
println!("{} Multi DC Setup", "Action: ".cyan(), );
setup_multi_dc_command::handle(connection, keyspace, dcs, replication_factor).await;
},
Some(Commands::TableActions { connection, keyspace, suffix, action }) => {
let connection = connection::setup_connection(&connection).await;
println!("{} {}", "Action: ".cyan(), "Table Actions");
println!("{} Table Actions", "Action: ".cyan());
table_actions_command::handle(connection, keyspace, action, suffix).await?;
},
_ => {
Expand Down

0 comments on commit f442ac7

Please sign in to comment.