MCPcopy Create free account
hub / github.com/SeaQL/sea-orm / connect

Method connect

src/database/mod.rs:100–134  ·  view source on GitHub ↗
(opt: C)

Source from the content-addressed store, hash-verified

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")]

Callers

nothing calls this directly

Calls 2

conn_errFunction · 0.85
is_prefix_ofMethod · 0.80

Tested by

no test coverage detected