diff --git a/src/database/connection.rs b/src/database/connection.rs index 382872e2..c673fca9 100644 --- a/src/database/connection.rs +++ b/src/database/connection.rs @@ -129,7 +129,7 @@ impl DatabaseConnection { } impl DbBackend { - pub(crate) fn url_starts_with(self, base_url: &str) -> bool { + pub(crate) fn is_prefix_of(self, base_url: &str) -> bool { match self { Self::Postgres => { base_url.starts_with("postgres://") || base_url.starts_with("postgresql://") diff --git a/src/database/mod.rs b/src/database/mod.rs index 2e0f9ac8..f61343c1 100644 --- a/src/database/mod.rs +++ b/src/database/mod.rs @@ -18,15 +18,15 @@ pub struct Database; impl Database { pub async fn connect(string: &str) -> Result { #[cfg(feature = "sqlx-mysql")] - if DbBackend::MySql.url_starts_with(string) { + if DbBackend::MySql.is_prefix_of(string) { return crate::SqlxMySqlConnector::connect(string).await; } #[cfg(feature = "sqlx-postgres")] - if DbBackend::Postgres.url_starts_with(string) { + if DbBackend::Postgres.is_prefix_of(string) { return crate::SqlxPostgresConnector::connect(string).await; } #[cfg(feature = "sqlx-sqlite")] - if DbBackend::Sqlite.url_starts_with(string) { + if DbBackend::Sqlite.is_prefix_of(string) { return crate::SqlxSqliteConnector::connect(string).await; } #[cfg(feature = "mock")] diff --git a/src/driver/mock.rs b/src/driver/mock.rs index 45e521a5..0e398586 100644 --- a/src/driver/mock.rs +++ b/src/driver/mock.rs @@ -31,15 +31,15 @@ impl MockDatabaseConnector { #[allow(unused_variables)] pub fn accepts(string: &str) -> bool { #[cfg(feature = "sqlx-mysql")] - if DbBackend::MySql.url_starts_with(string) { + if DbBackend::MySql.is_prefix_of(string) { return true; } #[cfg(feature = "sqlx-postgres")] - if DbBackend::Postgres.url_starts_with(string) { + if DbBackend::Postgres.is_prefix_of(string) { return true; } #[cfg(feature = "sqlx-sqlite")] - if DbBackend::Sqlite.url_starts_with(string) { + if DbBackend::Sqlite.is_prefix_of(string) { return true; } false diff --git a/src/driver/sqlx_mysql.rs b/src/driver/sqlx_mysql.rs index f754edaf..c542a9b4 100644 --- a/src/driver/sqlx_mysql.rs +++ b/src/driver/sqlx_mysql.rs @@ -20,7 +20,7 @@ pub struct SqlxMySqlPoolConnection { impl SqlxMySqlConnector { pub fn accepts(string: &str) -> bool { - DbBackend::MySql.url_starts_with(string) + DbBackend::MySql.is_prefix_of(string) } pub async fn connect(string: &str) -> Result { diff --git a/src/driver/sqlx_postgres.rs b/src/driver/sqlx_postgres.rs index 4a1aa807..fb5402eb 100644 --- a/src/driver/sqlx_postgres.rs +++ b/src/driver/sqlx_postgres.rs @@ -20,7 +20,7 @@ pub struct SqlxPostgresPoolConnection { impl SqlxPostgresConnector { pub fn accepts(string: &str) -> bool { - DbBackend::Postgres.url_starts_with(string) + DbBackend::Postgres.is_prefix_of(string) } pub async fn connect(string: &str) -> Result { diff --git a/src/driver/sqlx_sqlite.rs b/src/driver/sqlx_sqlite.rs index a083929a..b02f4408 100644 --- a/src/driver/sqlx_sqlite.rs +++ b/src/driver/sqlx_sqlite.rs @@ -20,7 +20,7 @@ pub struct SqlxSqlitePoolConnection { impl SqlxSqliteConnector { pub fn accepts(string: &str) -> bool { - DbBackend::Sqlite.url_starts_with(string) + DbBackend::Sqlite.is_prefix_of(string) } pub async fn connect(string: &str) -> Result {