From bdce2e56d4e7cfd4b0697b0477658729d799c2f0 Mon Sep 17 00:00:00 2001 From: zjregee Date: Sat, 6 Jul 2024 21:42:17 +0800 Subject: [PATCH] add bin support Signed-off-by: zjregee --- sqllogictest-bin/src/engines.rs | 24 ++++++++++++++++++++++++ sqllogictest-bin/src/main.rs | 1 + 2 files changed, 25 insertions(+) diff --git a/sqllogictest-bin/src/engines.rs b/sqllogictest-bin/src/engines.rs index 748e816..d678507 100644 --- a/sqllogictest-bin/src/engines.rs +++ b/sqllogictest-bin/src/engines.rs @@ -5,6 +5,7 @@ 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; @@ -12,6 +13,7 @@ use super::{DBConfig, Result}; #[derive(Copy, Clone, Debug, PartialEq, Eq, ValueEnum)] pub enum EngineType { + Mysql, Postgres, PostgresExtended, External, @@ -19,17 +21,33 @@ pub enum EngineType { #[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(); @@ -54,6 +72,11 @@ pub(crate) async fn connect( config: &DBConfig, ) -> Result { 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 @@ -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, diff --git a/sqllogictest-bin/src/main.rs b/sqllogictest-bin/src/main.rs index 4ea5655..0398c84 100644 --- a/sqllogictest-bin/src/main.rs +++ b/sqllogictest-bin/src/main.rs @@ -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 => {