| 160 | } |
| 161 | |
| 162 | pub(crate) async fn has_table<C, T>(conn: &C, _table: T) -> Result<bool, DbErr> |
| 163 | where |
| 164 | C: ConnectionTrait, |
| 165 | T: AsRef<str>, |
| 166 | { |
| 167 | let _stmt: SelectStatement = match conn.get_database_backend() { |
| 168 | #[cfg(feature = "sqlx-mysql")] |
| 169 | DbBackend::MySql => sea_schema::mysql::MySql.has_table(_table), |
| 170 | #[cfg(feature = "sqlx-postgres")] |
| 171 | DbBackend::Postgres => sea_schema::postgres::Postgres.has_table(_table), |
| 172 | #[cfg(feature = "sqlx-sqlite")] |
| 173 | DbBackend::Sqlite => sea_schema::sqlite::Sqlite.has_table(_table), |
| 174 | #[allow(unreachable_patterns)] |
| 175 | other => panic!("{other:?} feature is off"), |
| 176 | }; |
| 177 | |
| 178 | #[allow(unreachable_code)] |
| 179 | let builder = conn.get_database_backend(); |
| 180 | let res = conn |
| 181 | .query_one(builder.build(&_stmt)) |
| 182 | .await? |
| 183 | .ok_or_else(|| DbErr::Custom("Failed to check table exists".to_owned()))?; |
| 184 | |
| 185 | res.try_get("", "has_table") |
| 186 | } |