@@ -14,7 +14,8 @@ use chrono::{DateTime, Utc};
1414use regex:: Regex ;
1515use sea_orm:: {
1616 ActiveModelTrait , ConnectOptions , ConnectionTrait , Database , DatabaseBackend ,
17- DatabaseConnection , DbBackend , DbConn , DbErr , EntityTrait , IntoActiveModel , Statement ,
17+ DatabaseConnection , DbBackend , DbConn , DbErr , EntityTrait , ExprTrait , IntoActiveModel ,
18+ Statement ,
1819} ;
1920use sea_orm_migration:: MigratorTrait ;
2021use std:: fmt:: Write as FmtWrites ;
@@ -184,6 +185,13 @@ pub async fn connect(config: &config::Database) -> Result<DbConn, sea_orm::DbErr
184185 . await ?;
185186 }
186187 }
188+ bk => {
189+ return Err ( DbErr :: BackendNotSupported {
190+ db : bk. as_str ( ) ,
191+ ctx : "connect" ,
192+ }
193+ . into ( ) )
194+ }
187195 }
188196
189197 Ok ( db)
@@ -209,9 +217,11 @@ pub fn extract_db_name(conn_str: &str) -> AppResult<&str> {
209217/// Returns a [`sea_orm::DbErr`] if an error occurs during run migration up.
210218pub async fn create ( db_uri : & str ) -> AppResult < ( ) > {
211219 if !db_uri. starts_with ( "postgres://" ) {
212- return Err ( Error :: string (
213- "Only Postgres databases are supported for table creation" ,
214- ) ) ;
220+ return Err ( DbErr :: BackendNotSupported {
221+ db : "Unknown" ,
222+ ctx : "Only Postgres databases are supported for table creation" ,
223+ }
224+ . into ( ) ) ;
215225 }
216226 let db_name = extract_db_name ( db_uri) . map_err ( |_| {
217227 Error :: string ( "The specified table name was not found in the given Postgres database URI" )
@@ -279,8 +289,10 @@ use serde_json::{json, Value};
279289pub async fn seed < A > ( db : & DatabaseConnection , path : & str ) -> crate :: Result < ( ) >
280290where
281291 <<A as ActiveModelTrait >:: Entity as EntityTrait >:: Model : IntoActiveModel < A > ,
282- for < ' de > <<A as ActiveModelTrait >:: Entity as EntityTrait >:: Model : serde:: de:: Deserialize < ' de > ,
292+ for < ' de > <<A as ActiveModelTrait >:: Entity as EntityTrait >:: Model :
293+ serde:: de:: Deserialize < ' de > + serde:: Serialize ,
283294 A : ActiveModelTrait + Send + Sync ,
295+ A : sea_orm:: TryIntoModel < <<A as ActiveModelTrait >:: Entity as EntityTrait >:: Model > ,
284296 sea_orm:: Insert < A > : Send + Sync ,
285297 <A as ActiveModelTrait >:: Entity : EntityName ,
286298{
@@ -353,10 +365,12 @@ async fn has_id_column(
353365 . await ?;
354366 result. is_some_and ( |row| row. try_get :: < i32 > ( "" , "count" ) . unwrap_or ( 0 ) > 0 )
355367 }
356- DatabaseBackend :: MySql => {
357- return Err ( Error :: Message (
358- "Unsupported database backend: MySQL" . to_string ( ) ,
359- ) )
368+ bk => {
369+ return Err ( DbErr :: BackendNotSupported {
370+ db : bk. as_str ( ) ,
371+ ctx : "has_id_column" ,
372+ }
373+ . into ( ) ) ;
360374 }
361375 } ;
362376
@@ -395,10 +409,12 @@ async fn is_auto_increment(
395409 . is_ok_and ( |sql| sql. to_lowercase ( ) . contains ( "autoincrement" ) )
396410 } )
397411 }
398- DatabaseBackend :: MySql => {
399- return Err ( Error :: Message (
400- "Unsupported database backend: MySQL" . to_string ( ) ,
401- ) )
412+ bk => {
413+ return Err ( DbErr :: BackendNotSupported {
414+ db : bk. as_str ( ) ,
415+ ctx : "is_auto_increment" ,
416+ }
417+ . into ( ) ) ;
402418 }
403419 } ;
404420 Ok ( result)
@@ -448,10 +464,12 @@ pub async fn reset_autoincrement(
448464 ) )
449465 . await ?;
450466 }
451- DatabaseBackend :: MySql => {
452- return Err ( Error :: Message (
453- "Unsupported database backend: MySQL" . to_string ( ) ,
454- ) )
467+ bk => {
468+ return Err ( DbErr :: BackendNotSupported {
469+ db : bk. as_str ( ) ,
470+ ctx : "reset_autoincrement" ,
471+ }
472+ . into ( ) ) ;
455473 }
456474 }
457475 Ok ( ( ) )
@@ -742,17 +760,19 @@ async fn create_postgres_database(
742760/// unsupported database backend or a query execution issue.
743761pub async fn get_tables ( db : & DatabaseConnection ) -> AppResult < Vec < String > > {
744762 let query = match db. get_database_backend ( ) {
745- DatabaseBackend :: MySql => {
746- return Err ( Error :: Message (
747- "Unsupported database backend: MySQL" . to_string ( ) ,
748- ) )
749- }
750763 DatabaseBackend :: Postgres => {
751764 "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'"
752765 }
753766 DatabaseBackend :: Sqlite => {
754767 "SELECT name FROM sqlite_master WHERE type='table' AND name NOT LIKE 'sqlite_%'"
755768 }
769+ bk => {
770+ return Err ( DbErr :: BackendNotSupported {
771+ db : bk. as_str ( ) ,
772+ ctx : "get_tables" ,
773+ }
774+ . into ( ) )
775+ }
756776 } ;
757777
758778 let result = db
@@ -766,10 +786,9 @@ pub async fn get_tables(db: &DatabaseConnection) -> AppResult<Vec<String>> {
766786 . into_iter ( )
767787 . filter_map ( |row| {
768788 let col = match db. get_database_backend ( ) {
769- sea_orm:: DatabaseBackend :: MySql | sea_orm:: DatabaseBackend :: Postgres => {
770- "table_name"
771- }
789+ sea_orm:: DatabaseBackend :: Postgres => "table_name" ,
772790 sea_orm:: DatabaseBackend :: Sqlite => "name" ,
791+ _ => unreachable ! ( ) ,
773792 } ;
774793
775794 if let Ok ( table_name) = row. try_get :: < String > ( "" , col) {
@@ -969,6 +988,13 @@ pub async fn dump_schema(ctx: &AppContext, fname: &str) -> crate::Result<()> {
969988 } )
970989 . collect :: < Result < Vec < serde_json:: Value > , DbErr > > ( ) ? // Specify error type explicitly
971990 }
991+ db => {
992+ return Err ( DbErr :: BackendNotSupported {
993+ db : db. as_str ( ) ,
994+ ctx : "dump_schema" ,
995+ }
996+ . into ( ) )
997+ }
972998 } ;
973999 // Serialize schema info to JSON format
9741000 let schema_json = serde_json:: to_string_pretty ( & schema_info) ?;
0 commit comments