Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
cljoly committed Mar 18, 2024
1 parent 4afc581 commit e89a1aa
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
17 changes: 10 additions & 7 deletions examples/async/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,37 +55,40 @@ 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
MIGRATIONS.to_version(&mut async_conn, 2).await.unwrap();

// 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();
}
21 changes: 18 additions & 3 deletions rusqlite_migration_tests/tests/multiline_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Check failure on line 37 in rusqlite_migration_tests/tests/multiline_test.rs

View workflow job for this annotation

GitHub Actions / Code coverage

`if` may be missing an `else` clause

Check failure on line 37 in rusqlite_migration_tests/tests/multiline_test.rs

View workflow job for this annotation

GitHub Actions / Code coverage

`if` may be missing an `else` clause
}
})
.unwrap();
conn.pragma_update(None, "foreign_keys", "ON").unwrap();

assert_eq!(
Expand Down

0 comments on commit e89a1aa

Please sign in to comment.