From e89a1aaaf23677d5ef7a805617933d54309de4db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Joly?= Date: Mon, 18 Mar 2024 23:50:46 +0000 Subject: [PATCH] WIP --- examples/async/src/main.rs | 17 ++++++++------- .../tests/multiline_test.rs | 21 ++++++++++++++++--- 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/examples/async/src/main.rs b/examples/async/src/main.rs index 91374b1..65c3831 100644 --- a/examples/async/src/main.rs +++ b/examples/async/src/main.rs @@ -55,29 +55,32 @@ async fn main() { // Apply some PRAGMA. These are often better applied outside of migrations, as some needs to be // executed for each connection (like `foreign_keys`) or to be executed outside transactions // (`journal_mode` is a noop in a transaction). - async_conn - .call(|conn| conn.pragma_update(None, "journal_mode", "WAL")) +async_conn + .call(|conn| Ok(conn.pragma_update(None, "journal_mode", "WAL"))) .await .unwrap(); async_conn - .call(|conn| conn.pragma_update(None, "foreign_keys", "ON")) + .call(|conn| Ok(conn.pragma_update(None, "foreign_keys", "ON"))) .await + .unwrap() .unwrap(); // Use the db 🥳 async_conn .call(|conn| { - conn.execute( + Ok(conn.execute( "INSERT INTO friend (name, birthday) VALUES (?1, ?2)", params!["John", "1970-01-01"], - ) + )) }) .await + .unwrap() .unwrap(); async_conn - .call(|conn| conn.execute("INSERT INTO animal (name) VALUES (?1)", params!["dog"])) + .call(|conn| Ok(conn.execute("INSERT INTO animal (name) VALUES (?1)", params!["dog"]))) .await + .unwrap() .unwrap(); // If we want to revert the last migration @@ -85,7 +88,7 @@ async fn main() { // The table was removed async_conn - .call(|conn| conn.execute("INSERT INTO animal (name) VALUES (?1)", params!["cat"])) + .call(|conn| Ok(conn.execute("INSERT INTO animal (name) VALUES (?1)", params!["cat"]))) .await .unwrap_err(); } diff --git a/rusqlite_migration_tests/tests/multiline_test.rs b/rusqlite_migration_tests/tests/multiline_test.rs index e7f211e..aad6205 100644 --- a/rusqlite_migration_tests/tests/multiline_test.rs +++ b/rusqlite_migration_tests/tests/multiline_test.rs @@ -20,9 +20,24 @@ fn main_test() { let mut conn = Connection::open(&db_file).unwrap(); let migrations = Migrations::new(ms.clone()); - migrations.to_latest(&mut conn).unwrap(); - - conn.pragma_update(None, "journal_mode", "WAL").unwrap(); + // Will be improved with https://github.com/cljoly/rusqlite_migration/issues/134. For now, + // just make sure the right error is returned + assert!(matches!( + migrations.to_latest(&mut conn), + Err(rusqlite_migration::Error::RusqliteError { + query: _, + err: rusqlite::Error::ExecuteReturnedResults + }) + )); + + conn.pragma_update_and_check(None, "journal_mode", "WAL", |r| { + if let Ok(v) = r.get(0) { + Ok(()) + } else { + assert!(false, "unexpected journal_mode after setting it") + } + }) + .unwrap(); conn.pragma_update(None, "foreign_keys", "ON").unwrap(); assert_eq!(