(opt: C)
| 98 | /// if the database is not available. |
| 99 | #[instrument(level = "trace", skip(opt))] |
| 100 | pub async fn connect<C>(opt: C) -> Result<DatabaseConnection, DbErr> |
| 101 | where |
| 102 | C: Into<ConnectOptions>, |
| 103 | { |
| 104 | let opt: ConnectOptions = opt.into(); |
| 105 | |
| 106 | if url::Url::parse(&opt.url).is_err() { |
| 107 | return Err(conn_err(format!( |
| 108 | "The connection string '{}' cannot be parsed.", |
| 109 | opt.url |
| 110 | ))); |
| 111 | } |
| 112 | |
| 113 | #[cfg(feature = "sqlx-mysql")] |
| 114 | if DbBackend::MySql.is_prefix_of(&opt.url) { |
| 115 | return crate::SqlxMySqlConnector::connect(opt).await; |
| 116 | } |
| 117 | #[cfg(feature = "sqlx-postgres")] |
| 118 | if DbBackend::Postgres.is_prefix_of(&opt.url) { |
| 119 | return crate::SqlxPostgresConnector::connect(opt).await; |
| 120 | } |
| 121 | #[cfg(feature = "sqlx-sqlite")] |
| 122 | if DbBackend::Sqlite.is_prefix_of(&opt.url) { |
| 123 | return crate::SqlxSqliteConnector::connect(opt).await; |
| 124 | } |
| 125 | #[cfg(feature = "mock")] |
| 126 | if crate::MockDatabaseConnector::accepts(&opt.url) { |
| 127 | return crate::MockDatabaseConnector::connect(&opt.url).await; |
| 128 | } |
| 129 | |
| 130 | Err(conn_err(format!( |
| 131 | "The connection string '{}' has no supporting driver.", |
| 132 | opt.url |
| 133 | ))) |
| 134 | } |
| 135 | |
| 136 | /// Method to create a [DatabaseConnection] on a proxy database |
| 137 | #[cfg(feature = "proxy")] |
nothing calls this directly
no test coverage detected