@@ -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{
@@ -355,10 +367,12 @@ async fn has_id_column(
355367 . await ?;
356368 result. is_some_and ( |row| row. try_get :: < i32 > ( "" , "count" ) . unwrap_or ( 0 ) > 0 )
357369 }
358- DatabaseBackend :: MySql => {
359- return Err ( Error :: Message (
360- "Unsupported database backend: MySQL" . to_string ( ) ,
361- ) ) ;
370+ bk => {
371+ return Err ( DbErr :: BackendNotSupported {
372+ db : bk. as_str ( ) ,
373+ ctx : "has_id_column" ,
374+ }
375+ . into ( ) ) ;
362376 }
363377 } ;
364378
@@ -397,10 +411,12 @@ async fn is_auto_increment(
397411 . is_ok_and ( |sql| sql. to_lowercase ( ) . contains ( "autoincrement" ) )
398412 } )
399413 }
400- DatabaseBackend :: MySql => {
401- return Err ( Error :: Message (
402- "Unsupported database backend: MySQL" . to_string ( ) ,
403- ) ) ;
414+ bk => {
415+ return Err ( DbErr :: BackendNotSupported {
416+ db : bk. as_str ( ) ,
417+ ctx : "is_auto_increment" ,
418+ }
419+ . into ( ) ) ;
404420 }
405421 } ;
406422 Ok ( result)
@@ -450,10 +466,12 @@ pub async fn reset_autoincrement(
450466 ) )
451467 . await ?;
452468 }
453- DatabaseBackend :: MySql => {
454- return Err ( Error :: Message (
455- "Unsupported database backend: MySQL" . to_string ( ) ,
456- ) ) ;
469+ bk => {
470+ return Err ( DbErr :: BackendNotSupported {
471+ db : bk. as_str ( ) ,
472+ ctx : "reset_autoincrement" ,
473+ }
474+ . into ( ) ) ;
457475 }
458476 }
459477 Ok ( ( ) )
@@ -765,17 +783,19 @@ async fn create_postgres_database(
765783/// unsupported database backend or a query execution issue.
766784pub async fn get_tables ( db : & DatabaseConnection ) -> AppResult < Vec < String > > {
767785 let query = match db. get_database_backend ( ) {
768- DatabaseBackend :: MySql => {
769- return Err ( Error :: Message (
770- "Unsupported database backend: MySQL" . to_string ( ) ,
771- ) ) ;
772- }
773786 DatabaseBackend :: Postgres => {
774787 "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'"
775788 }
776789 DatabaseBackend :: Sqlite => {
777790 "SELECT name FROM sqlite_master WHERE type='table' AND name NOT LIKE 'sqlite_%'"
778791 }
792+ bk => {
793+ return Err ( DbErr :: BackendNotSupported {
794+ db : bk. as_str ( ) ,
795+ ctx : "get_tables" ,
796+ }
797+ . into ( ) )
798+ }
779799 } ;
780800
781801 let result = db
@@ -789,10 +809,9 @@ pub async fn get_tables(db: &DatabaseConnection) -> AppResult<Vec<String>> {
789809 . into_iter ( )
790810 . filter_map ( |row| {
791811 let col = match db. get_database_backend ( ) {
792- sea_orm:: DatabaseBackend :: MySql | sea_orm:: DatabaseBackend :: Postgres => {
793- "table_name"
794- }
812+ sea_orm:: DatabaseBackend :: Postgres => "table_name" ,
795813 sea_orm:: DatabaseBackend :: Sqlite => "name" ,
814+ _ => unreachable ! ( ) ,
796815 } ;
797816
798817 if let Ok ( table_name) = row. try_get :: < String > ( "" , col) {
@@ -1058,6 +1077,13 @@ pub async fn dump_schema(ctx: &AppContext, fname: &str) -> crate::Result<()> {
10581077 } )
10591078 . collect :: < Result < Vec < serde_json:: Value > , DbErr > > ( ) ? // Specify error type explicitly
10601079 }
1080+ db => {
1081+ return Err ( DbErr :: BackendNotSupported {
1082+ db : db. as_str ( ) ,
1083+ ctx : "dump_schema" ,
1084+ }
1085+ . into ( ) )
1086+ }
10611087 } ;
10621088 // Serialize schema info to JSON format
10631089 let schema_json = serde_json:: to_string_pretty ( & schema_info) ?;
0 commit comments