'url_starts_with' replace with 'is_prefix_of' method

This commit is contained in:
baoyachi 2021-09-27 16:41:47 +08:00
parent ae9e1c48ce
commit d78a067b2d
6 changed files with 10 additions and 10 deletions

View File

@ -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://")

View File

@ -18,15 +18,15 @@ pub struct Database;
impl Database {
pub async fn connect(string: &str) -> Result<DatabaseConnection, DbErr> {
#[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")]

View File

@ -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

View File

@ -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<DatabaseConnection, DbErr> {

View File

@ -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<DatabaseConnection, DbErr> {

View File

@ -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<DatabaseConnection, DbErr> {