@@ -14,8 +14,8 @@ use chrono::{DateTime, Utc};
1414use regex:: Regex ;
1515use sea_orm:: {
1616 ActiveModelTrait , ConnectOptions , ConnectionTrait , Database , DatabaseBackend ,
17- DatabaseConnection , DbBackend , DbConn , DbErr , EntityTrait , ExprTrait , IntoActiveModel ,
18- Statement ,
17+ DatabaseConnection , DatabaseConnectionType , DbBackend , DbConn , DbErr , EntityTrait , ExprTrait ,
18+ IntoActiveModel , Statement ,
1919} ;
2020use sea_orm_migration:: MigratorTrait ;
2121use std:: fmt:: Write as FmtWrites ;
@@ -86,10 +86,10 @@ impl MultiDb {
8686/// This function will return an error if IO fails
8787#[ allow( clippy:: match_wildcard_for_single_variants) ]
8888pub async fn verify_access ( db : & DatabaseConnection ) -> AppResult < ( ) > {
89- match db {
90- DatabaseConnection :: SqlxPostgresPoolConnection ( _) => {
89+ match db. inner {
90+ DatabaseConnectionType :: SqlxPostgresPoolConnection ( _) => {
9191 let res = db
92- . query_all ( Statement :: from_string (
92+ . query_all_raw ( Statement :: from_string (
9393 DatabaseBackend :: Postgres ,
9494 "SELECT * FROM pg_catalog.pg_tables WHERE tableowner = current_user;" ,
9595 ) )
@@ -100,7 +100,7 @@ pub async fn verify_access(db: &DatabaseConnection) -> AppResult<()> {
100100 ) ) ;
101101 }
102102 }
103- DatabaseConnection :: Disconnected => {
103+ DatabaseConnectionType :: Disconnected => {
104104 return Err ( Error :: string ( "connection to database has been closed" ) ) ;
105105 }
106106 _ => { }
@@ -159,7 +159,7 @@ pub async fn connect(config: &config::Database) -> Result<DbConn, sea_orm::DbErr
159159
160160 match db. get_database_backend ( ) {
161161 DatabaseBackend :: Sqlite => {
162- db. execute ( Statement :: from_string (
162+ db. execute_raw ( Statement :: from_string (
163163 DatabaseBackend :: Sqlite ,
164164 config. run_on_start . clone ( ) . unwrap_or_else ( || {
165165 "
@@ -178,7 +178,7 @@ pub async fn connect(config: &config::Database) -> Result<DbConn, sea_orm::DbErr
178178 }
179179 DatabaseBackend :: Postgres | DatabaseBackend :: MySql => {
180180 if let Some ( run_on_start) = & config. run_on_start {
181- db. execute ( Statement :: from_string (
181+ db. execute_raw ( Statement :: from_string (
182182 db. get_database_backend ( ) ,
183183 run_on_start. clone ( ) ,
184184 ) )
@@ -350,7 +350,7 @@ async fn has_id_column(
350350 )"
351351 ) ;
352352 let result = db
353- . query_one ( Statement :: from_string ( DatabaseBackend :: Postgres , query) )
353+ . query_one_raw ( Statement :: from_string ( DatabaseBackend :: Postgres , query) )
354354 . await ?;
355355 result. is_some_and ( |row| row. try_get :: < bool > ( "" , "exists" ) . unwrap_or ( false ) )
356356 }
@@ -361,7 +361,7 @@ async fn has_id_column(
361361 WHERE name = 'id'"
362362 ) ;
363363 let result = db
364- . query_one ( Statement :: from_string ( DatabaseBackend :: Sqlite , query) )
364+ . query_one_raw ( Statement :: from_string ( DatabaseBackend :: Sqlite , query) )
365365 . await ?;
366366 result. is_some_and ( |row| row. try_get :: < i32 > ( "" , "count" ) . unwrap_or ( 0 ) > 0 )
367367 }
@@ -394,15 +394,15 @@ async fn is_auto_increment(
394394 "SELECT pg_get_serial_sequence('{table_name}', 'id') IS NOT NULL as is_serial"
395395 ) ;
396396 let result = db
397- . query_one ( Statement :: from_string ( DatabaseBackend :: Postgres , query) )
397+ . query_one_raw ( Statement :: from_string ( DatabaseBackend :: Postgres , query) )
398398 . await ?;
399399 result. is_some_and ( |row| row. try_get :: < bool > ( "" , "is_serial" ) . unwrap_or ( false ) )
400400 }
401401 DatabaseBackend :: Sqlite => {
402402 let query =
403403 format ! ( "SELECT sql FROM sqlite_master WHERE type='table' AND name='{table_name}'" ) ;
404404 let result = db
405- . query_one ( Statement :: from_string ( DatabaseBackend :: Sqlite , query) )
405+ . query_one_raw ( Statement :: from_string ( DatabaseBackend :: Sqlite , query) )
406406 . await ?;
407407 result. is_some_and ( |row| {
408408 row. try_get :: < String > ( "" , "sql" )
@@ -445,7 +445,7 @@ pub async fn reset_autoincrement(
445445 "SELECT setval(pg_get_serial_sequence('{table_name}', 'id'), COALESCE(MAX(id), 0) \
446446 + 1, false) FROM {table_name}"
447447 ) ;
448- db. execute ( Statement :: from_sql_and_values (
448+ db. execute_raw ( Statement :: from_sql_and_values (
449449 DatabaseBackend :: Postgres ,
450450 & query_str,
451451 vec ! [ ] ,
@@ -457,7 +457,7 @@ pub async fn reset_autoincrement(
457457 "UPDATE sqlite_sequence SET seq = (SELECT MAX(id) FROM {table_name}) WHERE name = \
458458 '{table_name}'"
459459 ) ;
460- db. execute ( Statement :: from_sql_and_values (
460+ db. execute_raw ( Statement :: from_sql_and_values (
461461 DatabaseBackend :: Sqlite ,
462462 & query_str,
463463 vec ! [ ] ,
@@ -729,10 +729,7 @@ async fn create_postgres_database(
729729 )
730730 . limit ( 1 ) ;
731731
732- let ( sql, values) = select. build ( sea_orm:: sea_query:: PostgresQueryBuilder ) ;
733- let statement = Statement :: from_sql_and_values ( DatabaseBackend :: Postgres , sql, values) ;
734-
735- if db. query_one ( statement) . await ?. is_some ( ) {
732+ if db. query_one ( & select) . await ?. is_some ( ) {
736733 tracing:: info!( db_name, "database already exists" ) ;
737734
738735 return Err ( sea_orm:: DbErr :: Custom ( "database already exists" . to_owned ( ) ) ) ;
@@ -743,7 +740,7 @@ async fn create_postgres_database(
743740 let query = format ! ( "CREATE DATABASE {db_name} WITH {with_options}" ) ;
744741 tracing:: info!( query, "creating postgres database" ) ;
745742
746- db. execute ( sea_orm:: Statement :: from_string (
743+ db. execute_raw ( sea_orm:: Statement :: from_string (
747744 sea_orm:: DatabaseBackend :: Postgres ,
748745 query,
749746 ) )
@@ -776,7 +773,7 @@ pub async fn get_tables(db: &DatabaseConnection) -> AppResult<Vec<String>> {
776773 } ;
777774
778775 let result = db
779- . query_all ( Statement :: from_string (
776+ . query_all_raw ( Statement :: from_string (
780777 db. get_database_backend ( ) ,
781778 query. to_string ( ) ,
782779 ) )
@@ -834,7 +831,7 @@ pub async fn dump_tables(
834831 tracing:: info!( table, "get table data" ) ;
835832
836833 let data_result = db
837- . query_all ( Statement :: from_string (
834+ . query_all_raw ( Statement :: from_string (
838835 db. get_database_backend ( ) ,
839836 format ! ( r#"SELECT * FROM "{table}""# ) ,
840837 ) )
@@ -937,7 +934,7 @@ pub async fn dump_schema(ctx: &AppContext, fname: &str) -> crate::Result<()> {
937934 ORDER BY table_name, ordinal_position;
938935 " ;
939936 let stmt = Statement :: from_string ( DbBackend :: Postgres , query. to_owned ( ) ) ;
940- let rows = db. query_all ( stmt) . await ?;
937+ let rows = db. query_all_raw ( stmt) . await ?;
941938 rows. into_iter ( )
942939 . map ( |row| {
943940 // Wrap the closure in a Result to handle errors properly
@@ -957,7 +954,7 @@ pub async fn dump_schema(ctx: &AppContext, fname: &str) -> crate::Result<()> {
957954 ORDER BY TABLE_NAME, ORDINAL_POSITION;
958955 " ;
959956 let stmt = Statement :: from_string ( DbBackend :: MySql , query. to_owned ( ) ) ;
960- let rows = db. query_all ( stmt) . await ?;
957+ let rows = db. query_all_raw ( stmt) . await ?;
961958 rows. into_iter ( )
962959 . map ( |row| {
963960 // Wrap the closure in a Result to handle errors properly
@@ -977,7 +974,7 @@ pub async fn dump_schema(ctx: &AppContext, fname: &str) -> crate::Result<()> {
977974 ORDER BY name;
978975 " ;
979976 let stmt = Statement :: from_string ( DbBackend :: Sqlite , query. to_owned ( ) ) ;
980- let rows = db. query_all ( stmt) . await ?;
977+ let rows = db. query_all_raw ( stmt) . await ?;
981978 rows. into_iter ( )
982979 . map ( |row| {
983980 // Wrap the closure in a Result to handle errors properly
@@ -1256,7 +1253,7 @@ mod tests {
12561253 let backend = db. get_database_backend ( ) ;
12571254
12581255 let table_no_id = "test_table_no_id" ;
1259- db. execute ( Statement :: from_string (
1256+ db. execute_raw ( Statement :: from_string (
12601257 backend,
12611258 format ! ( "CREATE TABLE {table_no_id} (name TEXT);" ) ,
12621259 ) )
@@ -1272,7 +1269,7 @@ mod tests {
12721269 ) ;
12731270
12741271 let table_with_id = "test_table_with_id" ;
1275- db. execute ( Statement :: from_string (
1272+ db. execute_raw ( Statement :: from_string (
12761273 backend,
12771274 format ! ( "CREATE TABLE {table_with_id} (id INTEGER PRIMARY KEY, name TEXT);" ) ,
12781275 ) )
@@ -1288,7 +1285,7 @@ mod tests {
12881285 ) ;
12891286
12901287 let table_with_serial_id = "test_table_with_serial_id" ;
1291- db. execute ( Statement :: from_string (
1288+ db. execute_raw ( Statement :: from_string (
12921289 backend,
12931290 format ! ( "CREATE TABLE {table_with_serial_id} (id SERIAL PRIMARY KEY, name TEXT);" ) ,
12941291 ) )
@@ -1313,7 +1310,7 @@ mod tests {
13131310 assert_eq ! ( backend, DatabaseBackend :: Sqlite ) ;
13141311
13151312 let table_no_id = "test_table_no_id" ;
1316- db. execute ( Statement :: from_string (
1313+ db. execute_raw ( Statement :: from_string (
13171314 backend,
13181315 format ! ( "CREATE TABLE {table_no_id} (name TEXT);" ) ,
13191316 ) )
@@ -1329,7 +1326,7 @@ mod tests {
13291326 ) ;
13301327
13311328 let table_with_id = "test_table_with_id" ;
1332- db. execute ( Statement :: from_string (
1329+ db. execute_raw ( Statement :: from_string (
13331330 backend,
13341331 // SQLite uses INTEGER PRIMARY KEY for rowid alias
13351332 format ! ( "CREATE TABLE {table_with_id} (id INTEGER PRIMARY KEY, name TEXT);" ) ,
@@ -1346,7 +1343,7 @@ mod tests {
13461343 ) ;
13471344
13481345 let table_with_auto_id = "test_table_with_auto_id" ;
1349- db. execute ( Statement :: from_string (
1346+ db. execute_raw ( Statement :: from_string (
13501347 backend,
13511348 // AUTOINCREMENT keyword is important for SQLite's sequence behavior
13521349 format ! ( "CREATE TABLE {table_with_auto_id} (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT);" ) ,
@@ -1374,7 +1371,7 @@ mod tests {
13741371 let backend = db. get_database_backend ( ) ;
13751372
13761373 let table_no_id = "test_table_no_id_auto" ;
1377- db. execute ( Statement :: from_string (
1374+ db. execute_raw ( Statement :: from_string (
13781375 backend,
13791376 format ! ( "CREATE TABLE {table_no_id} (name TEXT);" ) ,
13801377 ) )
@@ -1396,7 +1393,7 @@ mod tests {
13961393 ) ;
13971394
13981395 let table_with_id_not_auto = "test_table_id_not_auto" ;
1399- db. execute ( Statement :: from_string (
1396+ db. execute_raw ( Statement :: from_string (
14001397 backend,
14011398 format ! ( "CREATE TABLE {table_with_id_not_auto} (id INTEGER PRIMARY KEY, name TEXT);" ) ,
14021399 ) )
@@ -1412,7 +1409,7 @@ mod tests {
14121409 ) ;
14131410
14141411 let table_with_serial_id = "test_table_serial_id_auto" ;
1415- db. execute ( Statement :: from_string (
1412+ db. execute_raw ( Statement :: from_string (
14161413 backend,
14171414 format ! ( "CREATE TABLE {table_with_serial_id} (id SERIAL PRIMARY KEY, name TEXT);" ) ,
14181415 ) )
@@ -1441,23 +1438,23 @@ mod tests {
14411438
14421439 // Create test table with SERIAL id
14431440 let table_name = "test_reset_sequence" ;
1444- db. execute ( Statement :: from_string (
1441+ db. execute_raw ( Statement :: from_string (
14451442 backend,
14461443 format ! ( "CREATE TABLE {table_name} (id SERIAL PRIMARY KEY, name TEXT);" ) ,
14471444 ) )
14481445 . await
14491446 . expect ( "Failed to create test table" ) ;
14501447
14511448 // Insert multiple rows in a single query
1452- db. execute ( Statement :: from_string (
1449+ db. execute_raw ( Statement :: from_string (
14531450 backend,
14541451 format ! ( "INSERT INTO {table_name} (name) VALUES ('one'), ('two'), ('three');" ) ,
14551452 ) )
14561453 . await
14571454 . expect ( "Failed to insert test data" ) ;
14581455
14591456 // Delete all rows
1460- db. execute ( Statement :: from_string (
1457+ db. execute_raw ( Statement :: from_string (
14611458 backend,
14621459 format ! ( "DELETE FROM {table_name};" ) ,
14631460 ) )
@@ -1466,7 +1463,7 @@ mod tests {
14661463
14671464 // Insert a new row and check ID (should be 4, continuing the sequence)
14681465 let result = db
1469- . query_one ( Statement :: from_string (
1466+ . query_one_raw ( Statement :: from_string (
14701467 backend,
14711468 format ! ( "INSERT INTO {table_name} (name) VALUES ('test') RETURNING id;" ) ,
14721469 ) )
@@ -1481,7 +1478,7 @@ mod tests {
14811478 ) ;
14821479
14831480 // Delete all rows again
1484- db. execute ( Statement :: from_string (
1481+ db. execute_raw ( Statement :: from_string (
14851482 backend,
14861483 format ! ( "DELETE FROM {table_name};" ) ,
14871484 ) )
@@ -1495,7 +1492,7 @@ mod tests {
14951492
14961493 // Insert a new row and check ID (should be 1 after reset)
14971494 let result = db
1498- . query_one ( Statement :: from_string (
1495+ . query_one_raw ( Statement :: from_string (
14991496 backend,
15001497 format ! ( "INSERT INTO {table_name} (name) VALUES ('reset') RETURNING id;" ) ,
15011498 ) )
@@ -1517,23 +1514,23 @@ mod tests {
15171514
15181515 // Create test table with auto-incrementing id
15191516 let table_name = "test_reset_sequence" ;
1520- db. execute ( Statement :: from_string (
1517+ db. execute_raw ( Statement :: from_string (
15211518 backend,
15221519 format ! ( "CREATE TABLE {table_name} (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT);" ) ,
15231520 ) )
15241521 . await
15251522 . expect ( "Failed to create test table" ) ;
15261523
15271524 // Insert multiple rows in a single query
1528- db. execute ( Statement :: from_string (
1525+ db. execute_raw ( Statement :: from_string (
15291526 backend,
15301527 format ! ( "INSERT INTO {table_name} (name) VALUES ('one'), ('two'), ('three');" ) ,
15311528 ) )
15321529 . await
15331530 . expect ( "Failed to insert test data" ) ;
15341531
15351532 // Delete all rows
1536- db. execute ( Statement :: from_string (
1533+ db. execute_raw ( Statement :: from_string (
15371534 backend,
15381535 format ! ( "DELETE FROM {table_name};" ) ,
15391536 ) )
@@ -1542,7 +1539,7 @@ mod tests {
15421539
15431540 // Insert a new row and check ID (should be 4, continuing the sequence)
15441541 let result = db
1545- . query_one ( Statement :: from_string (
1542+ . query_one_raw ( Statement :: from_string (
15461543 backend,
15471544 format ! ( "INSERT INTO {table_name} (name) VALUES ('test') RETURNING id;" ) ,
15481545 ) )
@@ -1557,7 +1554,7 @@ mod tests {
15571554 ) ;
15581555
15591556 // Delete all rows again
1560- db. execute ( Statement :: from_string (
1557+ db. execute_raw ( Statement :: from_string (
15611558 backend,
15621559 format ! ( "DELETE FROM {table_name};" ) ,
15631560 ) )
@@ -1571,7 +1568,7 @@ mod tests {
15711568
15721569 // Insert a new row and check ID (should be 1 after reset)
15731570 let result = db
1574- . query_one ( Statement :: from_string (
1571+ . query_one_raw ( Statement :: from_string (
15751572 backend,
15761573 format ! ( "INSERT INTO {table_name} (name) VALUES ('reset') RETURNING id;" ) ,
15771574 ) )
0 commit comments