diff --git a/src/database/db_connection.rs b/src/database/db_connection.rs index 476fe8e09..ab9d734a1 100644 --- a/src/database/db_connection.rs +++ b/src/database/db_connection.rs @@ -292,22 +292,6 @@ impl DatabaseConnection { } } -impl DatabaseConnection { - /// Get database version - pub fn version(&self) -> String { - match self { - #[cfg(feature = "sqlx-mysql")] - DatabaseConnection::SqlxMySqlPoolConnection(conn) => conn.version.to_string(), - #[cfg(feature = "sqlx-postgres")] - DatabaseConnection::SqlxPostgresPoolConnection(_) => "".to_string(), - #[cfg(feature = "sqlx-sqlite")] - DatabaseConnection::SqlxSqlitePoolConnection(conn) => conn.version.to_string(), - DatabaseConnection::Disconnected => panic!("Disconnected"), - _ => unimplemented!(), - } - } -} - impl DbBackend { /// Check if the URI is the same as the specified database backend. /// Returns true if they match. diff --git a/src/database/transaction.rs b/src/database/transaction.rs index 168461c48..cfce9d58a 100644 --- a/src/database/transaction.rs +++ b/src/database/transaction.rs @@ -367,37 +367,13 @@ impl<'a> ConnectionTrait<'a> for DatabaseTransaction { } fn returning_on_insert(&self) -> bool { - match self.backend { - DbBackend::MySql => { - // Supported if it's MariaDB on or after version 10.5.0 - // Not supported in all MySQL versions - self.support_returning - } - DbBackend::Postgres => { - // Supported by all Postgres versions - true - } - DbBackend::Sqlite => { - // Supported by SQLite on or after version 3.35.0 (2021-03-12) - self.support_returning - } - } + self.support_returning } fn returning_on_update(&self) -> bool { match self.backend { - DbBackend::MySql => { - // Not supported in all MySQL & MariaDB versions - false - } - DbBackend::Postgres => { - // Supported by all Postgres versions - true - } - DbBackend::Sqlite => { - // Supported by SQLite on or after version 3.35.0 (2021-03-12) - self.support_returning - } + DbBackend::MySql => false, + _ => self.support_returning, } } } diff --git a/src/driver/sqlx_mysql.rs b/src/driver/sqlx_mysql.rs index 44efdc0ba..e29ee9f80 100644 --- a/src/driver/sqlx_mysql.rs +++ b/src/driver/sqlx_mysql.rs @@ -24,7 +24,6 @@ pub struct SqlxMySqlConnector; #[derive(Debug, Clone)] pub struct SqlxMySqlPoolConnection { pool: MySqlPool, - pub(crate) version: String, pub(crate) support_returning: bool, } @@ -186,17 +185,16 @@ pub(crate) fn sqlx_query(stmt: &Statement) -> sqlx::query::Query<'_, MySql, MySq } async fn into_db_connection(pool: MySqlPool) -> Result { - let (version, support_returning) = parse_support_returning(&pool).await?; + let support_returning = parse_support_returning(&pool).await?; Ok(DatabaseConnection::SqlxMySqlPoolConnection( SqlxMySqlPoolConnection { pool, - version, support_returning, }, )) } -async fn parse_support_returning(pool: &MySqlPool) -> Result<(String, bool), DbErr> { +async fn parse_support_returning(pool: &MySqlPool) -> Result { let stmt = Statement::from_string( DbBackend::MySql, r#"SHOW VARIABLES LIKE "version""#.to_owned(), @@ -232,5 +230,5 @@ async fn parse_support_returning(pool: &MySqlPool) -> Result<(String, bool), DbE }; debug_print!("db_version: {}", version); debug_print!("db_support_returning: {}", support_returning); - Ok((version, support_returning)) + Ok(support_returning) } diff --git a/src/driver/sqlx_sqlite.rs b/src/driver/sqlx_sqlite.rs index 4cbdc2318..4ea160e85 100644 --- a/src/driver/sqlx_sqlite.rs +++ b/src/driver/sqlx_sqlite.rs @@ -24,7 +24,6 @@ pub struct SqlxSqliteConnector; #[derive(Debug, Clone)] pub struct SqlxSqlitePoolConnection { pool: SqlitePool, - pub(crate) version: String, pub(crate) support_returning: bool, } @@ -190,17 +189,16 @@ pub(crate) fn sqlx_query(stmt: &Statement) -> sqlx::query::Query<'_, Sqlite, Sql } async fn into_db_connection(pool: SqlitePool) -> Result { - let (version, support_returning) = parse_support_returning(&pool).await?; + let support_returning = parse_support_returning(&pool).await?; Ok(DatabaseConnection::SqlxSqlitePoolConnection( SqlxSqlitePoolConnection { pool, - version, support_returning, }, )) } -async fn parse_support_returning(pool: &SqlitePool) -> Result<(String, bool), DbErr> { +async fn parse_support_returning(pool: &SqlitePool) -> Result { let stmt = Statement::from_string( DbBackend::Sqlite, r#"SELECT sqlite_version() AS version"#.to_owned(), @@ -229,5 +227,5 @@ async fn parse_support_returning(pool: &SqlitePool) -> Result<(String, bool), Db let support_returning = ver_major >= 3 && ver_minor >= 35; debug_print!("db_version: {}", version); debug_print!("db_support_returning: {}", support_returning); - Ok((version, support_returning)) + Ok(support_returning) } diff --git a/tests/returning_tests.rs b/tests/returning_tests.rs index 94e8a3990..55506399f 100644 --- a/tests/returning_tests.rs +++ b/tests/returning_tests.rs @@ -36,7 +36,6 @@ async fn main() -> Result<(), DbErr> { returning.columns(vec![Column::Id, Column::Name, Column::ProfitMargin]); create_tables(db).await?; - println!("db_version: {:#?}", db.version()); if db.returning_on_insert() { insert.returning(returning.clone());