schema added
parent
20c183b163
commit
178ea238a3
|
@ -20,4 +20,8 @@ pub enum Commands {
|
||||||
#[arg(short = 's', long = "search")]
|
#[arg(short = 's', long = "search")]
|
||||||
search: Option<String>,
|
search: Option<String>,
|
||||||
},
|
},
|
||||||
|
Schema {
|
||||||
|
#[arg(short = 's', long = "search")]
|
||||||
|
search: Option<String>,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1 +1,2 @@
|
||||||
pub mod merchant;
|
pub mod merchant;
|
||||||
|
pub mod schema;
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
|
||||||
|
#[derive(Debug, PartialEq, Eq)]
|
||||||
|
pub struct Schema {
|
||||||
|
pub table_name: String,
|
||||||
|
pub column_name: String,
|
||||||
|
pub column_type: String,
|
||||||
|
}
|
||||||
|
|
12
src/main.rs
12
src/main.rs
|
@ -2,12 +2,13 @@ use clap::Parser;
|
||||||
use cli::cli::{Cli, Commands};
|
use cli::cli::{Cli, Commands};
|
||||||
use database::database::Db;
|
use database::database::Db;
|
||||||
use mysql::PooledConn;
|
use mysql::PooledConn;
|
||||||
use repository::merchant_repo;
|
use service::{merchant_service, schema_service};
|
||||||
|
|
||||||
pub mod cli;
|
pub mod cli;
|
||||||
pub mod database;
|
pub mod database;
|
||||||
pub mod entity;
|
pub mod entity;
|
||||||
pub mod repository;
|
pub mod repository;
|
||||||
|
pub mod service;
|
||||||
|
|
||||||
fn main() -> std::result::Result<(), Box<dyn std::error::Error>> {
|
fn main() -> std::result::Result<(), Box<dyn std::error::Error>> {
|
||||||
let args = Cli::parse();
|
let args = Cli::parse();
|
||||||
|
@ -16,12 +17,11 @@ fn main() -> std::result::Result<(), Box<dyn std::error::Error>> {
|
||||||
|
|
||||||
match args.mode {
|
match args.mode {
|
||||||
Commands::Merch { search } => {
|
Commands::Merch { search } => {
|
||||||
let selected_payments = merchant_repo::find_by_name_or_id(&search.unwrap(), &mut conn);
|
merchant_service::get_merchant(&search.unwrap(), &mut conn);
|
||||||
|
|
||||||
selected_payments.into_iter().for_each(|payment| {
|
|
||||||
println!("{:?}", payment);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
Commands::Schema { search } => {
|
||||||
|
schema_service::get_columns(&search.unwrap(), &mut conn)
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
@ -1 +1,2 @@
|
||||||
pub mod merchant_repo;
|
pub mod merchant_repo;
|
||||||
|
pub mod schema_repo;
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
use mysql::{params, prelude::Queryable, PooledConn};
|
||||||
|
|
||||||
|
use crate::entity::schema::Schema;
|
||||||
|
|
||||||
|
pub fn find_by_column(
|
||||||
|
column_name: &str,
|
||||||
|
conn: &mut PooledConn,
|
||||||
|
) -> Result<Vec<Schema>, mysql::Error> {
|
||||||
|
let stat = conn
|
||||||
|
.prep("SELECT TABLE_NAME, COLUMN_NAME, COLUMN_TYPE FROM INFORMATION_SCHEMA.COLUMNS WHERE column_name LIKE :c_name")
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
conn.exec_map(
|
||||||
|
stat,
|
||||||
|
params! {"c_name" => column_name},
|
||||||
|
|(table_name, column_name, column_type)| Schema {
|
||||||
|
table_name,
|
||||||
|
column_name,
|
||||||
|
column_type,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
|
@ -0,0 +1,19 @@
|
||||||
|
use mysql::PooledConn;
|
||||||
|
|
||||||
|
use crate::repository::merchant_repo;
|
||||||
|
|
||||||
|
pub fn get_merchant(search: &str, conn: &mut PooledConn) {
|
||||||
|
let merchants = merchant_repo::find_by_name_or_id(search, conn);
|
||||||
|
|
||||||
|
match merchants {
|
||||||
|
Ok(merchants) => {
|
||||||
|
if merchants.is_empty() {
|
||||||
|
println!("Merchant not found!");
|
||||||
|
}
|
||||||
|
merchants.into_iter().for_each(|merchant| {
|
||||||
|
println!("Merchant: {}", merchant.m_name);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
Err(err) => panic!("{}", err),
|
||||||
|
};
|
||||||
|
}
|
|
@ -0,0 +1,2 @@
|
||||||
|
pub mod merchant_service;
|
||||||
|
pub mod schema_service;
|
|
@ -0,0 +1,23 @@
|
||||||
|
use mysql::PooledConn;
|
||||||
|
|
||||||
|
use crate::repository::schema_repo;
|
||||||
|
|
||||||
|
|
||||||
|
pub fn get_columns(column: &str, conn: &mut PooledConn) {
|
||||||
|
let columns = schema_repo::find_by_column(column, conn);
|
||||||
|
|
||||||
|
match columns {
|
||||||
|
Ok(columns) => {
|
||||||
|
if columns.is_empty() {
|
||||||
|
println!("No column found!");
|
||||||
|
}
|
||||||
|
columns.into_iter().for_each(|column| {
|
||||||
|
println!("{}", "-".repeat(100));
|
||||||
|
println!("Table name: {}", column.table_name);
|
||||||
|
println!("Column name: {}", column.column_name);
|
||||||
|
println!("Type: {}", column.column_type);
|
||||||
|
})
|
||||||
|
},
|
||||||
|
Err(err) => panic!("{err}"),
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue