Skip to content

Commit bac2581

Browse files
committed
Bump sea-orm
Use *_raw API
1 parent 307a7b6 commit bac2581

File tree

4 files changed

+62
-54
lines changed

4 files changed

+62
-54
lines changed

src/db.rs

Lines changed: 42 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ use chrono::{DateTime, Utc};
1414
use regex::Regex;
1515
use 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
};
2020
use sea_orm_migration::MigratorTrait;
2121
use 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)]
8888
pub 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![],
@@ -750,10 +750,7 @@ async fn create_postgres_database(
750750
)
751751
.limit(1);
752752

753-
let (sql, values) = select.build(sea_orm::sea_query::PostgresQueryBuilder);
754-
let statement = Statement::from_sql_and_values(DatabaseBackend::Postgres, sql, values);
755-
756-
if db.query_one(statement).await?.is_some() {
753+
if db.query_one(&select).await?.is_some() {
757754
tracing::info!(db_name, "database already exists");
758755

759756
return Err(sea_orm::DbErr::Custom("database already exists".to_owned()));
@@ -764,7 +761,7 @@ async fn create_postgres_database(
764761
let query = format!("CREATE DATABASE {db_name} WITH {with_options}");
765762
tracing::info!(query, "creating postgres database");
766763

767-
db.execute(sea_orm::Statement::from_string(
764+
db.execute_raw(sea_orm::Statement::from_string(
768765
sea_orm::DatabaseBackend::Postgres,
769766
query,
770767
))
@@ -797,7 +794,7 @@ pub async fn get_tables(db: &DatabaseConnection) -> AppResult<Vec<String>> {
797794
};
798795

799796
let result = db
800-
.query_all(Statement::from_string(
797+
.query_all_raw(Statement::from_string(
801798
db.get_database_backend(),
802799
query.to_string(),
803800
))
@@ -855,7 +852,7 @@ pub async fn dump_tables(
855852
tracing::info!(table, "get table data");
856853

857854
let data_result = db
858-
.query_all(Statement::from_string(
855+
.query_all_raw(Statement::from_string(
859856
db.get_database_backend(),
860857
format!(r#"SELECT * FROM "{table}""#),
861858
))
@@ -958,7 +955,7 @@ pub async fn dump_schema(ctx: &AppContext, fname: &str) -> crate::Result<()> {
958955
ORDER BY table_name, ordinal_position;
959956
";
960957
let stmt = Statement::from_string(DbBackend::Postgres, query.to_owned());
961-
let rows = db.query_all(stmt).await?;
958+
let rows = db.query_all_raw(stmt).await?;
962959
rows.into_iter()
963960
.map(|row| {
964961
// Wrap the closure in a Result to handle errors properly
@@ -978,7 +975,7 @@ pub async fn dump_schema(ctx: &AppContext, fname: &str) -> crate::Result<()> {
978975
ORDER BY TABLE_NAME, ORDINAL_POSITION;
979976
";
980977
let stmt = Statement::from_string(DbBackend::MySql, query.to_owned());
981-
let rows = db.query_all(stmt).await?;
978+
let rows = db.query_all_raw(stmt).await?;
982979
rows.into_iter()
983980
.map(|row| {
984981
// Wrap the closure in a Result to handle errors properly
@@ -998,7 +995,7 @@ pub async fn dump_schema(ctx: &AppContext, fname: &str) -> crate::Result<()> {
998995
ORDER BY name;
999996
";
1000997
let stmt = Statement::from_string(DbBackend::Sqlite, query.to_owned());
1001-
let rows = db.query_all(stmt).await?;
998+
let rows = db.query_all_raw(stmt).await?;
1002999
rows.into_iter()
10031000
.map(|row| {
10041001
// Wrap the closure in a Result to handle errors properly
@@ -1277,7 +1274,7 @@ mod tests {
12771274
let backend = db.get_database_backend();
12781275

12791276
let table_no_id = "test_table_no_id";
1280-
db.execute(Statement::from_string(
1277+
db.execute_raw(Statement::from_string(
12811278
backend,
12821279
format!("CREATE TABLE {table_no_id} (name TEXT);"),
12831280
))
@@ -1293,7 +1290,7 @@ mod tests {
12931290
);
12941291

12951292
let table_with_id = "test_table_with_id";
1296-
db.execute(Statement::from_string(
1293+
db.execute_raw(Statement::from_string(
12971294
backend,
12981295
format!("CREATE TABLE {table_with_id} (id INTEGER PRIMARY KEY, name TEXT);"),
12991296
))
@@ -1309,7 +1306,7 @@ mod tests {
13091306
);
13101307

13111308
let table_with_serial_id = "test_table_with_serial_id";
1312-
db.execute(Statement::from_string(
1309+
db.execute_raw(Statement::from_string(
13131310
backend,
13141311
format!("CREATE TABLE {table_with_serial_id} (id SERIAL PRIMARY KEY, name TEXT);"),
13151312
))
@@ -1334,7 +1331,7 @@ mod tests {
13341331
assert_eq!(backend, DatabaseBackend::Sqlite);
13351332

13361333
let table_no_id = "test_table_no_id";
1337-
db.execute(Statement::from_string(
1334+
db.execute_raw(Statement::from_string(
13381335
backend,
13391336
format!("CREATE TABLE {table_no_id} (name TEXT);"),
13401337
))
@@ -1350,7 +1347,7 @@ mod tests {
13501347
);
13511348

13521349
let table_with_id = "test_table_with_id";
1353-
db.execute(Statement::from_string(
1350+
db.execute_raw(Statement::from_string(
13541351
backend,
13551352
// SQLite uses INTEGER PRIMARY KEY for rowid alias
13561353
format!("CREATE TABLE {table_with_id} (id INTEGER PRIMARY KEY, name TEXT);"),
@@ -1367,7 +1364,7 @@ mod tests {
13671364
);
13681365

13691366
let table_with_auto_id = "test_table_with_auto_id";
1370-
db.execute(Statement::from_string(
1367+
db.execute_raw(Statement::from_string(
13711368
backend,
13721369
// AUTOINCREMENT keyword is important for SQLite's sequence behavior
13731370
format!("CREATE TABLE {table_with_auto_id} (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT);"),
@@ -1395,7 +1392,7 @@ mod tests {
13951392
let backend = db.get_database_backend();
13961393

13971394
let table_no_id = "test_table_no_id_auto";
1398-
db.execute(Statement::from_string(
1395+
db.execute_raw(Statement::from_string(
13991396
backend,
14001397
format!("CREATE TABLE {table_no_id} (name TEXT);"),
14011398
))
@@ -1417,7 +1414,7 @@ mod tests {
14171414
);
14181415

14191416
let table_with_id_not_auto = "test_table_id_not_auto";
1420-
db.execute(Statement::from_string(
1417+
db.execute_raw(Statement::from_string(
14211418
backend,
14221419
format!("CREATE TABLE {table_with_id_not_auto} (id INTEGER PRIMARY KEY, name TEXT);"),
14231420
))
@@ -1433,7 +1430,7 @@ mod tests {
14331430
);
14341431

14351432
let table_with_serial_id = "test_table_serial_id_auto";
1436-
db.execute(Statement::from_string(
1433+
db.execute_raw(Statement::from_string(
14371434
backend,
14381435
format!("CREATE TABLE {table_with_serial_id} (id SERIAL PRIMARY KEY, name TEXT);"),
14391436
))
@@ -1462,23 +1459,23 @@ mod tests {
14621459

14631460
// Create test table with SERIAL id
14641461
let table_name = "test_reset_sequence";
1465-
db.execute(Statement::from_string(
1462+
db.execute_raw(Statement::from_string(
14661463
backend,
14671464
format!("CREATE TABLE {table_name} (id SERIAL PRIMARY KEY, name TEXT);"),
14681465
))
14691466
.await
14701467
.expect("Failed to create test table");
14711468

14721469
// Insert multiple rows in a single query
1473-
db.execute(Statement::from_string(
1470+
db.execute_raw(Statement::from_string(
14741471
backend,
14751472
format!("INSERT INTO {table_name} (name) VALUES ('one'), ('two'), ('three');"),
14761473
))
14771474
.await
14781475
.expect("Failed to insert test data");
14791476

14801477
// Delete all rows
1481-
db.execute(Statement::from_string(
1478+
db.execute_raw(Statement::from_string(
14821479
backend,
14831480
format!("DELETE FROM {table_name};"),
14841481
))
@@ -1487,7 +1484,7 @@ mod tests {
14871484

14881485
// Insert a new row and check ID (should be 4, continuing the sequence)
14891486
let result = db
1490-
.query_one(Statement::from_string(
1487+
.query_one_raw(Statement::from_string(
14911488
backend,
14921489
format!("INSERT INTO {table_name} (name) VALUES ('test') RETURNING id;"),
14931490
))
@@ -1502,7 +1499,7 @@ mod tests {
15021499
);
15031500

15041501
// Delete all rows again
1505-
db.execute(Statement::from_string(
1502+
db.execute_raw(Statement::from_string(
15061503
backend,
15071504
format!("DELETE FROM {table_name};"),
15081505
))
@@ -1516,7 +1513,7 @@ mod tests {
15161513

15171514
// Insert a new row and check ID (should be 1 after reset)
15181515
let result = db
1519-
.query_one(Statement::from_string(
1516+
.query_one_raw(Statement::from_string(
15201517
backend,
15211518
format!("INSERT INTO {table_name} (name) VALUES ('reset') RETURNING id;"),
15221519
))
@@ -1538,23 +1535,23 @@ mod tests {
15381535

15391536
// Create test table with auto-incrementing id
15401537
let table_name = "test_reset_sequence";
1541-
db.execute(Statement::from_string(
1538+
db.execute_raw(Statement::from_string(
15421539
backend,
15431540
format!("CREATE TABLE {table_name} (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT);"),
15441541
))
15451542
.await
15461543
.expect("Failed to create test table");
15471544

15481545
// Insert multiple rows in a single query
1549-
db.execute(Statement::from_string(
1546+
db.execute_raw(Statement::from_string(
15501547
backend,
15511548
format!("INSERT INTO {table_name} (name) VALUES ('one'), ('two'), ('three');"),
15521549
))
15531550
.await
15541551
.expect("Failed to insert test data");
15551552

15561553
// Delete all rows
1557-
db.execute(Statement::from_string(
1554+
db.execute_raw(Statement::from_string(
15581555
backend,
15591556
format!("DELETE FROM {table_name};"),
15601557
))
@@ -1563,7 +1560,7 @@ mod tests {
15631560

15641561
// Insert a new row and check ID (should be 4, continuing the sequence)
15651562
let result = db
1566-
.query_one(Statement::from_string(
1563+
.query_one_raw(Statement::from_string(
15671564
backend,
15681565
format!("INSERT INTO {table_name} (name) VALUES ('test') RETURNING id;"),
15691566
))
@@ -1578,7 +1575,7 @@ mod tests {
15781575
);
15791576

15801577
// Delete all rows again
1581-
db.execute(Statement::from_string(
1578+
db.execute_raw(Statement::from_string(
15821579
backend,
15831580
format!("DELETE FROM {table_name};"),
15841581
))
@@ -1592,7 +1589,7 @@ mod tests {
15921589

15931590
// Insert a new row and check ID (should be 1 after reset)
15941591
let result = db
1595-
.query_one(Statement::from_string(
1592+
.query_one_raw(Statement::from_string(
15961593
backend,
15971594
format!("INSERT INTO {table_name} (name) VALUES ('reset') RETURNING id;"),
15981595
))

src/model/query/dsl/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,9 @@ pub fn date_range<T: ColumnTrait>(col: T) -> date_range::DateRangeBuilder<T> {
164164
date_range::DateRangeBuilder::new(condition(), col)
165165
}
166166

167-
impl IntoCondition for ConditionBuilder {
168-
fn into_condition(self) -> Condition {
169-
self.build()
167+
impl From<ConditionBuilder> for Condition {
168+
fn from(cond: ConditionBuilder) -> Condition {
169+
cond.build()
170170
}
171171
}
172172

0 commit comments

Comments
 (0)