Skip to content

Commit

Permalink
feat: refactor transfer handling to use ImportHandlers for database n…
Browse files Browse the repository at this point in the history
…ame validation
  • Loading branch information
Kremilly committed Dec 7, 2024
1 parent 8706d32 commit 2ac5074
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
3 changes: 3 additions & 0 deletions src/engine/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use std::{

use crate::{
engine::connection::Connection,
helpers::import_handlers::ImportHandlers,

ui::{
errors_alerts::ErrorsAlerts,
Expand Down Expand Up @@ -95,6 +96,8 @@ impl Import {
content
};

let dump_content = ImportHandlers::new(&self.dbname, &dump_content).check_db_name();

let create_table_regex = Regex::new(r"(?i)CREATE TABLE\s+`?(\w+)`?").unwrap();

for statement in dump_content.split(';') {
Expand Down
5 changes: 2 additions & 3 deletions src/engine/transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use std::{

use crate::{
engine::connection::Connection,
helpers::transfer_handlers::TransferHandlers,
helpers::import_handlers::ImportHandlers,

ui::{
errors_alerts::ErrorsAlerts,
Expand Down Expand Up @@ -104,8 +104,7 @@ impl Transfer {
content
};

let transfer_handlers = TransferHandlers::new(&self.dbname, &dump_content);
let dump_content = transfer_handlers.check_db_name();
let dump_content = ImportHandlers::new(&self.dbname, &dump_content).check_db_name();

let create_table_regex = Regex::new(r"(?i)CREATE TABLE\s+`?(\w+)`?").unwrap();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use regex::Regex;

pub struct TransferHandlers {
pub struct ImportHandlers {
dbname: String,
dump_content: String,
}

impl TransferHandlers {
impl ImportHandlers {

pub fn new(dbname: &str, dump_content: &str) -> Self {
Self {
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ pub mod env;
pub mod configs;
pub mod dump_handlers;
pub mod export_handlers;
pub mod transfer_handlers;
pub mod import_handlers;

0 comments on commit 2ac5074

Please sign in to comment.