Skip to content

Commit

Permalink
polish
Browse files Browse the repository at this point in the history
  • Loading branch information
jiacai2050 committed Sep 28, 2023
1 parent 5f867b0 commit 3c3e64a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ clippy:
cd $(DIR); cargo clippy --all-targets --all-features --workspace -- -D warnings

cli-test:
cd $(DIR)/sqlness-cli; cargo run -- -c tests/mysql -i 127.0.0.1 -p 3306 -u root -P 1a2b3c -d public
cd $(DIR)/sqlness-cli; cargo run -- -c tests/postgresql -i localhost -p 5432 -u postgres -P postgres -d postgres -r postgresql
cd $(DIR)/sqlness-cli; cargo run -- -t mysql -c tests/mysql -i 127.0.0.1 -p 3306 -u root -P 1a2b3c -d public
cd $(DIR)/sqlness-cli; cargo run -- -t postgresql -c tests/postgresql -i 127.0.0.1 -p 5432 -u postgres -P postgres -d postgres

example: good-example bad-example

Expand Down
21 changes: 10 additions & 11 deletions sqlness-cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright 2023 CeresDB Project Authors. Licensed under Apache-2.0.

use std::{error::Error, fmt::Display, path::Path};
use std::{fmt::Display, path::Path};

use async_trait::async_trait;
use clap::Parser;
Expand Down Expand Up @@ -40,8 +40,8 @@ struct Args {
db: Option<String>,

/// Which DBMS to test against
#[clap(short('r'), long)]
#[arg(value_enum, default_value_t = DBType::Mysql)]
#[clap(short('t'), long("type"))]
#[arg(value_enum, default_value_t)]
db_type: DBType,
}

Expand All @@ -64,16 +64,15 @@ impl Database for DBProxy {
}

impl DBProxy {
pub fn try_new(db_config: DatabaseConfig, db_type: DBType) -> Result<Self, Box<dyn Error>> {
let db = match db_type {
DBType::Mysql => {
Box::new(MysqlDatabase::try_new(db_config).expect("build db")) as Box<_>
}
pub fn new(db_config: DatabaseConfig, db_type: DBType) -> Self {
let database: Box<dyn Database + Sync + Send> = match db_type {
DBType::Mysql => Box::new(MysqlDatabase::try_new(db_config).expect("build mysql db")),
DBType::Postgresql => {
Box::new(PostgresqlDatabase::try_new(&db_config).expect("build db")) as Box<_>
Box::new(PostgresqlDatabase::try_new(&db_config).expect("build postgresql db"))
}
};
Ok(DBProxy { database: db })

DBProxy { database }
}
}

Expand All @@ -93,7 +92,7 @@ impl EnvController for CliController {
type DB = DBProxy;

async fn start(&self, _env: &str, _config: Option<&Path>) -> Self::DB {
DBProxy::try_new(self.db_config.clone(), self.db_type).expect("build db")
DBProxy::new(self.db_config.clone(), self.db_type)
}

async fn stop(&self, _env: &str, _db: Self::DB) {}
Expand Down

0 comments on commit 3c3e64a

Please sign in to comment.