diff --git a/.gitignore b/.gitignore index 950c227c..3eaf3f74 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ target Cargo.lock *.sublime* -.vscode \ No newline at end of file +.vscode +.idea/* \ No newline at end of file diff --git a/sea-orm-cli/src/main.rs b/sea-orm-cli/src/main.rs index e7041ef0..527e1264 100644 --- a/sea-orm-cli/src/main.rs +++ b/sea-orm-cli/src/main.rs @@ -56,7 +56,7 @@ async fn run_generate_command(matches: &ArgMatches<'_>) -> Result<(), Box bool { + match self { + DbScheme::Postgres => { + base_url.starts_with("postgres://") || base_url.starts_with("postgresql://") + } + DbScheme::Mysql => base_url.starts_with("mysql://"), + DbScheme::Sqlite => base_url.starts_with("sqlite:"), + } + } +} + #[derive(Debug, Default)] pub struct Database; impl Database { pub async fn connect(string: &str) -> Result { #[cfg(feature = "sqlx-mysql")] - if crate::SqlxMySqlConnector::accepts(string) { + if DbScheme::Mysql::starts_with(string) { return crate::SqlxMySqlConnector::connect(string).await; } #[cfg(feature = "sqlx-postgres")] - if crate::SqlxPostgresConnector::accepts(string) { + if DbScheme::Postgres::starts_with(string) { return crate::SqlxPostgresConnector::connect(string).await; } #[cfg(feature = "sqlx-sqlite")] - if crate::SqlxSqliteConnector::accepts(string) { + if DbScheme::Sqlite::starts_with(string) { return crate::SqlxSqliteConnector::connect(string).await; } #[cfg(feature = "mock")] diff --git a/src/driver/mock.rs b/src/driver/mock.rs index 823ddb32..f3bbe6f8 100644 --- a/src/driver/mock.rs +++ b/src/driver/mock.rs @@ -1,6 +1,6 @@ use crate::{ - debug_print, error::*, DatabaseConnection, DbBackend, ExecResult, MockDatabase, QueryResult, - Statement, Transaction, + debug_print, error::*, DatabaseConnection, DbBackend, ExecResult, MockDatabase, + QueryResult, Statement, Transaction, }; use std::fmt::Debug; use std::sync::{ @@ -31,15 +31,15 @@ impl MockDatabaseConnector { #[allow(unused_variables)] pub fn accepts(string: &str) -> bool { #[cfg(feature = "sqlx-mysql")] - if crate::SqlxMySqlConnector::accepts(string) { + if DbScheme::Mysql::accepts(string) { return true; } #[cfg(feature = "sqlx-postgres")] - if crate::SqlxPostgresConnector::accepts(string) { + if DbScheme::Postgres::accepts(string) { return true; } #[cfg(feature = "sqlx-sqlite")] - if crate::SqlxSqliteConnector::accepts(string) { + if DbScheme::Sqlite::accepts(string) { return true; } false diff --git a/src/driver/sqlx_mysql.rs b/src/driver/sqlx_mysql.rs index be590b6e..41365c88 100644 --- a/src/driver/sqlx_mysql.rs +++ b/src/driver/sqlx_mysql.rs @@ -6,7 +6,7 @@ use sqlx::{ sea_query::sea_query_driver_mysql!(); use sea_query_driver_mysql::bind_query; -use crate::{debug_print, error::*, executor::*, DatabaseConnection, Statement}; +use crate::{debug_print, error::*, executor::*, DatabaseConnection, DbScheme, Statement}; use super::sqlx_common::*; @@ -20,7 +20,7 @@ pub struct SqlxMySqlPoolConnection { impl SqlxMySqlConnector { pub fn accepts(string: &str) -> bool { - string.starts_with("mysql://") + DbScheme::Mysql::starts_with(string) } pub async fn connect(string: &str) -> Result { diff --git a/src/driver/sqlx_postgres.rs b/src/driver/sqlx_postgres.rs index e7b9032a..8dd28808 100644 --- a/src/driver/sqlx_postgres.rs +++ b/src/driver/sqlx_postgres.rs @@ -6,7 +6,7 @@ use sqlx::{ sea_query::sea_query_driver_postgres!(); use sea_query_driver_postgres::bind_query; -use crate::{debug_print, error::*, executor::*, DatabaseConnection, Statement}; +use crate::{debug_print, error::*, executor::*, DatabaseConnection, DbScheme, Statement}; use super::sqlx_common::*; @@ -20,7 +20,7 @@ pub struct SqlxPostgresPoolConnection { impl SqlxPostgresConnector { pub fn accepts(string: &str) -> bool { - string.starts_with("postgres://") + DbScheme::Postgres::starts_with(string) } pub async fn connect(string: &str) -> Result { diff --git a/src/driver/sqlx_sqlite.rs b/src/driver/sqlx_sqlite.rs index bd6f0399..5f865ef2 100644 --- a/src/driver/sqlx_sqlite.rs +++ b/src/driver/sqlx_sqlite.rs @@ -6,7 +6,7 @@ use sqlx::{ sea_query::sea_query_driver_sqlite!(); use sea_query_driver_sqlite::bind_query; -use crate::{debug_print, error::*, executor::*, DatabaseConnection, Statement}; +use crate::{debug_print, error::*, executor::*, DatabaseConnection, DbScheme, Statement}; use super::sqlx_common::*; @@ -20,7 +20,7 @@ pub struct SqlxSqlitePoolConnection { impl SqlxSqliteConnector { pub fn accepts(string: &str) -> bool { - string.starts_with("sqlite:") + DbScheme::Sqlite::starts_with(string) } pub async fn connect(string: &str) -> Result {