From b7b83c7ec4dfcec54eb4435cc4b7771dcf50fc6f Mon Sep 17 00:00:00 2001 From: Eran Boodnero Date: Sun, 15 Dec 2024 09:19:13 -0800 Subject: [PATCH] renamed Error and Result --- .../multiple_databases/03-many-to-many.rs | 4 +- .../multiple_databases/04-one-to-many.rs | 4 +- .../multiple_databases/main.rs | 14 ++--- ormlite/tests/multifile/main.rs | 16 ++---- ormlite/tests/sqlite/03-many-to-one-join.rs | 55 +++++++++++-------- .../sqlite/04-allow-clone-primary-key.rs | 17 ++---- 6 files changed, 50 insertions(+), 60 deletions(-) diff --git a/ormlite/tests/incomplete_tests/multiple_databases/03-many-to-many.rs b/ormlite/tests/incomplete_tests/multiple_databases/03-many-to-many.rs index c33e05b1..9c502fe9 100644 --- a/ormlite/tests/incomplete_tests/multiple_databases/03-many-to-many.rs +++ b/ormlite/tests/incomplete_tests/multiple_databases/03-many-to-many.rs @@ -9,9 +9,7 @@ pub struct Person { age: u8, } - -pub static CREATE_TABLE_SQL: &str = - "CREATE TABLE person (id text PRIMARY KEY, name TEXT, age INTEGER)"; +pub static CREATE_TABLE_SQL: &str = "CREATE TABLE person (id text PRIMARY KEY, name TEXT, age INTEGER)"; #[tokio::main] async fn main() -> Result<(), Box> { diff --git a/ormlite/tests/incomplete_tests/multiple_databases/04-one-to-many.rs b/ormlite/tests/incomplete_tests/multiple_databases/04-one-to-many.rs index 59e836aa..e8403d03 100644 --- a/ormlite/tests/incomplete_tests/multiple_databases/04-one-to-many.rs +++ b/ormlite/tests/incomplete_tests/multiple_databases/04-one-to-many.rs @@ -9,9 +9,7 @@ pub struct Person { age: u8, } - -pub static CREATE_TABLE_SQL: &str = - "CREATE TABLE person (id text PRIMARY KEY, name TEXT, age INTEGER)"; +pub static CREATE_TABLE_SQL: &str = "CREATE TABLE person (id text PRIMARY KEY, name TEXT, age INTEGER)"; #[tokio::main] async fn main() -> Result<(), Box> { diff --git a/ormlite/tests/incomplete_tests/multiple_databases/main.rs b/ormlite/tests/incomplete_tests/multiple_databases/main.rs index 8285db04..59985600 100644 --- a/ormlite/tests/incomplete_tests/multiple_databases/main.rs +++ b/ormlite/tests/incomplete_tests/multiple_databases/main.rs @@ -15,7 +15,6 @@ pub struct Person { age: u8, } - #[tokio::main] async fn main() -> Result<(), Box> { env_logger::init(); @@ -23,21 +22,18 @@ async fn main() -> Result<(), Box> { let migration = crate::setup::migrate_self(&[file!()]); for s in migration.statements { let sql = s.to_sql(sqlmo::Dialect::Sqlite); - ormlite::query(&sql) - .execute(&mut db) - .await?; + ormlite::query(&sql).execute(&mut db).await?; } let p = Person { id: Uuid::new_v4(), name: "John".to_string(), age: 99, - }.insert(&mut db).await?; + } + .insert(&mut db) + .await?; - let p = p.update_partial() - .age(100) - .update(&mut db) - .await?; + let p = p.update_partial().age(100).update(&mut db).await?; assert_eq!(p.age, 100); Ok(()) diff --git a/ormlite/tests/multifile/main.rs b/ormlite/tests/multifile/main.rs index b4819379..07132d4d 100644 --- a/ormlite/tests/multifile/main.rs +++ b/ormlite/tests/multifile/main.rs @@ -1,28 +1,24 @@ #[path = "../setup.rs"] mod setup; -mod user; mod organization; +mod user; -pub use user::User; pub use organization::Organization; -use uuid::Uuid; use ormlite::model::*; use ormlite::sqlite::SqliteConnection; use ormlite::Connection; use sqlmo::ToSql; +pub use user::User; +use uuid::Uuid; #[tokio::main] async fn main() -> Result<(), Box> { let mut conn = SqliteConnection::connect(":memory:").await?; - let migration = setup::migrate_self(&[ - &std::path::Path::new(file!()).parent().unwrap().display().to_string(), - ]); + let migration = setup::migrate_self(&[&std::path::Path::new(file!()).parent().unwrap().display().to_string()]); for s in migration.statements { let sql = s.to_sql(sqlmo::Dialect::Sqlite); - ormlite::query(&sql) - .execute(&mut conn) - .await?; + ormlite::query(&sql).execute(&mut conn).await?; } let org_id = Uuid::new_v4(); @@ -40,4 +36,4 @@ async fn main() -> Result<(), Box> { let user = user.insert(&mut conn).await?; assert_eq!(user.organization.id, org_id); Ok(()) -} \ No newline at end of file +} diff --git a/ormlite/tests/sqlite/03-many-to-one-join.rs b/ormlite/tests/sqlite/03-many-to-one-join.rs index 14254766..9489559f 100644 --- a/ormlite/tests/sqlite/03-many-to-one-join.rs +++ b/ormlite/tests/sqlite/03-many-to-one-join.rs @@ -18,22 +18,16 @@ pub struct Organization { name: String, } -pub static CREATE_PERSON_SQL: &str = - "CREATE TABLE person (id text PRIMARY KEY, name TEXT, age INTEGER, org_id text)"; +pub static CREATE_PERSON_SQL: &str = "CREATE TABLE person (id text PRIMARY KEY, name TEXT, age INTEGER, org_id text)"; -pub static CREATE_ORG_SQL: &str = - "CREATE TABLE orgs (id text PRIMARY KEY, name TEXT)"; +pub static CREATE_ORG_SQL: &str = "CREATE TABLE orgs (id text PRIMARY KEY, name TEXT)"; #[tokio::main] async fn main() -> Result<(), Box> { env_logger::init(); let mut db = ormlite::sqlite::SqliteConnection::connect(":memory:").await.unwrap(); - ormlite::query(CREATE_PERSON_SQL) - .execute(&mut db) - .await?; - ormlite::query(CREATE_ORG_SQL) - .execute(&mut db) - .await?; + ormlite::query(CREATE_PERSON_SQL).execute(&mut db).await?; + ormlite::query(CREATE_ORG_SQL).execute(&mut db).await?; let org = Organization { id: Uuid::new_v4(), @@ -44,41 +38,54 @@ async fn main() -> Result<(), Box> { name: "John".to_string(), age: 102, organization: Join::new(org.clone()), - }.insert(&mut db).await.unwrap(); - assert_eq!(p1.organization.id, org.id, "setting the org object should overwrite the org_id field on insert."); + } + .insert(&mut db) + .await + .unwrap(); + assert_eq!( + p1.organization.id, org.id, + "setting the org object should overwrite the org_id field on insert." + ); assert_eq!(p1.organization._id(), org.id); let org = Organization::select() .where_bind("id = ?", &org.id) .fetch_one(&mut db) - .await.unwrap(); - assert_eq!(org.name, "my org", "org gets inserted even though we didn't manually insert it."); + .await + .unwrap(); + assert_eq!( + org.name, "my org", + "org gets inserted even though we didn't manually insert it." + ); let p2 = Person { id: Uuid::new_v4(), name: "p2".to_string(), age: 98, organization: Join::new(org.clone()), - }.insert(&mut db).await.unwrap(); - assert_eq!(p2.organization.id, org.id, "we can do insertion with an existing join obj, and it will pass the error."); + } + .insert(&mut db) + .await + .unwrap(); + assert_eq!( + p2.organization.id, org.id, + "we can do insertion with an existing join obj, and it will pass the error." + ); - let orgs = Organization::select() - .fetch_all(&mut db) - .await.unwrap(); + let orgs = Organization::select().fetch_all(&mut db).await.unwrap(); assert_eq!(orgs.len(), 1, "exactly 1 orgs"); - let people = Person::select() - .fetch_all(&mut db) - .await.unwrap(); + let people = Person::select().fetch_all(&mut db).await.unwrap(); assert_eq!(people.len(), 2, "exactly 2 people"); let people = Person::select() .join(Person::organization()) .fetch_all(&mut db) - .await.unwrap(); + .await + .unwrap(); assert_eq!(people.len(), 2, "exactly 2 people"); for person in &people { assert_eq!(person.organization.name, "my org", "we can join on the org"); } Ok(()) -} \ No newline at end of file +} diff --git a/ormlite/tests/sqlite/04-allow-clone-primary-key.rs b/ormlite/tests/sqlite/04-allow-clone-primary-key.rs index 5db295d6..e94163c5 100644 --- a/ormlite/tests/sqlite/04-allow-clone-primary-key.rs +++ b/ormlite/tests/sqlite/04-allow-clone-primary-key.rs @@ -10,28 +10,23 @@ pub struct Person { age: u8, } - -pub static CREATE_TABLE_SQL: &str = - "CREATE TABLE person (id text PRIMARY KEY, name TEXT, age INTEGER)"; +pub static CREATE_TABLE_SQL: &str = "CREATE TABLE person (id text PRIMARY KEY, name TEXT, age INTEGER)"; #[tokio::main] async fn main() -> Result<(), Box> { env_logger::init(); let mut db = ormlite::sqlite::SqliteConnection::connect(":memory:").await.unwrap(); - ormlite::query(CREATE_TABLE_SQL) - .execute(&mut db) - .await?; + ormlite::query(CREATE_TABLE_SQL).execute(&mut db).await?; let p = Person { id: Uuid::new_v4(), name: "John".to_string(), age: 99, - }.insert(&mut db).await?; + } + .insert(&mut db) + .await?; - let p = p.update_partial() - .age(100) - .update(&mut db) - .await?; + let p = p.update_partial().age(100).update(&mut db).await?; assert_eq!(p.age, 100);