Skip to content

Commit

Permalink
add bin support
Browse files Browse the repository at this point in the history
Signed-off-by: zjregee <[email protected]>
  • Loading branch information
zjregee committed Jul 7, 2024
1 parent be9b099 commit bdce2e5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
24 changes: 24 additions & 0 deletions sqllogictest-bin/src/engines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,49 @@ use async_trait::async_trait;
use clap::ValueEnum;
use sqllogictest::{AsyncDB, DBOutput, DefaultColumnType};
use sqllogictest_engines::external::ExternalDriver;
use sqllogictest_engines::mysql::{MySql, MySqlConfig};
use sqllogictest_engines::postgres::{PostgresConfig, PostgresExtended, PostgresSimple};
use tokio::process::Command;

use super::{DBConfig, Result};

#[derive(Copy, Clone, Debug, PartialEq, Eq, ValueEnum)]
pub enum EngineType {
Mysql,
Postgres,
PostgresExtended,
External,
}

#[derive(Clone, Debug)]
pub enum EngineConfig {
MySql,
Postgres,
PostgresExtended,
External(String),
}

pub(crate) enum Engines {
MySql(MySql),
Postgres(PostgresSimple),
PostgresExtended(PostgresExtended),
External(ExternalDriver),
}

impl From<&DBConfig> for MySqlConfig {
fn from(config: &DBConfig) -> Self {
let (host, port) = config.random_addr();

let mysql_config = MySqlConfig::new();
mysql_config
.host(host)
.port(port)
.database(&config.db)
.username(&config.user)
.password(&config.pass)
}
}

impl From<&DBConfig> for PostgresConfig {
fn from(config: &DBConfig) -> Self {
let (host, port) = config.random_addr();
Expand All @@ -54,6 +72,11 @@ pub(crate) async fn connect(
config: &DBConfig,
) -> Result<Engines, EnginesError> {
Ok(match engine {
EngineConfig::MySql => Engines::MySql(
MySql::connect(config.into())
.await
.map_err(|e| EnginesError(e.into()))?,
),
EngineConfig::Postgres => Engines::Postgres(
PostgresSimple::connect(config.into())
.await
Expand Down Expand Up @@ -101,6 +124,7 @@ impl std::error::Error for EnginesError {
macro_rules! dispatch_engines {
($impl:expr, $inner:ident, $body:tt) => {{
match $impl {
Engines::MySql($inner) => $body,
Engines::Postgres($inner) => $body,
Engines::PostgresExtended($inner) => $body,
Engines::External($inner) => $body,
Expand Down
1 change: 1 addition & 0 deletions sqllogictest-bin/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ pub async fn main() -> Result<()> {
let addrs = host.into_iter().zip_eq(port).collect();

let engine = match engine {
EngineType::Mysql => EngineConfig::MySql,
EngineType::Postgres => EngineConfig::Postgres,
EngineType::PostgresExtended => EngineConfig::PostgresExtended,
EngineType::External => {
Expand Down

0 comments on commit bdce2e5

Please sign in to comment.