From 98d79897e7c7d3217880b0ba07c8aab4412abec1 Mon Sep 17 00:00:00 2001 From: Christopher Zeuch Date: Mon, 7 Oct 2024 18:01:17 +0200 Subject: [PATCH 01/10] Split tests out into separate files --- njord/tests/sqlite/delete_test.rs | 78 +++++++++ njord/tests/sqlite/insert_test.rs | 73 +++++++++ njord/tests/sqlite/open_test.rs | 58 +++++++ .../{sqlite_test.rs => sqlite/select_test.rs} | 151 +----------------- njord/tests/sqlite/update_test.rs | 127 +++++++++++++++ 5 files changed, 337 insertions(+), 150 deletions(-) create mode 100644 njord/tests/sqlite/delete_test.rs create mode 100644 njord/tests/sqlite/insert_test.rs create mode 100644 njord/tests/sqlite/open_test.rs rename njord/tests/{sqlite_test.rs => sqlite/select_test.rs} (75%) create mode 100644 njord/tests/sqlite/update_test.rs diff --git a/njord/tests/sqlite/delete_test.rs b/njord/tests/sqlite/delete_test.rs new file mode 100644 index 00000000..67b9ea7b --- /dev/null +++ b/njord/tests/sqlite/delete_test.rs @@ -0,0 +1,78 @@ +// integrations tests for sqlite + +use njord::column::Column; +use njord::condition::Condition; +use njord::keys::{AutoIncrementPrimaryKey, PrimaryKey}; +use njord::sqlite::select::SelectQueryBuilder; +use njord::sqlite::{self}; +use njord::table::Table; +use njord_derive::Table; +use std::collections::HashMap; +use std::path::Path; + +#[derive(Table, Clone)] +#[table_name = "users"] +pub struct User { + id: AutoIncrementPrimaryKey, + username: String, + email: String, + address: String, +} + +#[derive(Table)] +#[table_name = "users"] +pub struct UserWithSubQuery { + id: AutoIncrementPrimaryKey, + username: String, + email: String, + address: String, + additional_address: String, +} + +#[derive(Table)] +#[table_name = "categories"] +pub struct Category { + id: PrimaryKey, + name: String, +} + +#[derive(Table)] +#[table_name = "products"] +pub struct Product { + id: PrimaryKey, + name: String, + description: String, + price: f64, + stock_quantity: usize, + category: Category, // one-to-one relationship + discount: f64, +} + +#[test] +fn delete() { + let db_relative_path = "./db/insert.db"; + let db_path = Path::new(&db_relative_path); + let conn = sqlite::open(db_path); + + let condition = Condition::Eq("address".to_string(), "Some Random Address 1".to_string()); + + let mut order = HashMap::new(); + order.insert(vec!["id".to_string()], "DESC".to_string()); + + match conn { + Ok(c) => { + let result = sqlite::delete(c) + .from(User::default()) + .where_clause(condition) + .order_by(order) + .limit(20) + .offset(0) + .build(); + println!("{:?}", result); + assert!(result.is_ok()); + } + Err(e) => { + panic!("Failed to DELETE: {:?}", e); + } + } +} \ No newline at end of file diff --git a/njord/tests/sqlite/insert_test.rs b/njord/tests/sqlite/insert_test.rs new file mode 100644 index 00000000..3e400d03 --- /dev/null +++ b/njord/tests/sqlite/insert_test.rs @@ -0,0 +1,73 @@ +// integrations tests for sqlite + +use njord::column::Column; +use njord::condition::Condition; +use njord::keys::{AutoIncrementPrimaryKey, PrimaryKey}; +use njord::sqlite::select::SelectQueryBuilder; +use njord::sqlite::{self}; +use njord::table::Table; +use njord_derive::Table; +use std::collections::HashMap; +use std::path::Path; + +#[derive(Table, Clone)] +#[table_name = "users"] +pub struct User { + id: AutoIncrementPrimaryKey, + username: String, + email: String, + address: String, +} + +#[derive(Table)] +#[table_name = "users"] +pub struct UserWithSubQuery { + id: AutoIncrementPrimaryKey, + username: String, + email: String, + address: String, + additional_address: String, +} + +#[derive(Table)] +#[table_name = "categories"] +pub struct Category { + id: PrimaryKey, + name: String, +} + +#[derive(Table)] +#[table_name = "products"] +pub struct Product { + id: PrimaryKey, + name: String, + description: String, + price: f64, + stock_quantity: usize, + category: Category, // one-to-one relationship + discount: f64, +} + +#[test] +fn insert_row() { + let db_relative_path = "./db/insert.db"; + let db_path = Path::new(&db_relative_path); + let conn = sqlite::open(db_path); + + let table_row: User = User { + id: AutoIncrementPrimaryKey::default(), + username: "mjovanc".to_string(), + email: "mjovanc@icloud.com".to_string(), + address: "Some Random Address 1".to_string(), + }; + + match conn { + Ok(c) => { + let result = sqlite::insert(c, vec![table_row]); + assert!(result.is_ok()); + } + Err(e) => { + panic!("Failed to INSERT: {:?}", e); + } + } +} \ No newline at end of file diff --git a/njord/tests/sqlite/open_test.rs b/njord/tests/sqlite/open_test.rs new file mode 100644 index 00000000..0fad6a89 --- /dev/null +++ b/njord/tests/sqlite/open_test.rs @@ -0,0 +1,58 @@ +// integrations tests for sqlite + +use njord::column::Column; +use njord::condition::Condition; +use njord::keys::{AutoIncrementPrimaryKey, PrimaryKey}; +use njord::sqlite::select::SelectQueryBuilder; +use njord::sqlite::{self}; +use njord::table::Table; +use njord_derive::Table; +use std::collections::HashMap; +use std::path::Path; + +#[derive(Table, Clone)] +#[table_name = "users"] +pub struct User { + id: AutoIncrementPrimaryKey, + username: String, + email: String, + address: String, +} + +#[derive(Table)] +#[table_name = "users"] +pub struct UserWithSubQuery { + id: AutoIncrementPrimaryKey, + username: String, + email: String, + address: String, + additional_address: String, +} + +#[derive(Table)] +#[table_name = "categories"] +pub struct Category { + id: PrimaryKey, + name: String, +} + +#[derive(Table)] +#[table_name = "products"] +pub struct Product { + id: PrimaryKey, + name: String, + description: String, + price: f64, + stock_quantity: usize, + category: Category, // one-to-one relationship + discount: f64, +} + +#[test] +fn open_db() { + let db_relative_path = "./db/open.db"; + let db_path = Path::new(&db_relative_path); + + let result = sqlite::open(db_path); + assert!(result.is_ok()); +} \ No newline at end of file diff --git a/njord/tests/sqlite_test.rs b/njord/tests/sqlite/select_test.rs similarity index 75% rename from njord/tests/sqlite_test.rs rename to njord/tests/sqlite/select_test.rs index b21858b4..a0b48142 100644 --- a/njord/tests/sqlite_test.rs +++ b/njord/tests/sqlite/select_test.rs @@ -48,115 +48,6 @@ pub struct Product { discount: f64, } -// #[derive(Table)] -// #[table_name = "orders"] -// pub struct Order { -// id: usize, -// user: User, // one-to-one relationship -// products: Vec, // one-to-many relationship - populates from based on junction table (gets from macro attribute "table_name" and combines them for example, orders_products) -// total_cost: f64, -// } - -#[test] -fn open_db() { - let db_relative_path = "./db/open.db"; - let db_path = Path::new(&db_relative_path); - - let result = sqlite::open(db_path); - assert!(result.is_ok()); -} - -#[test] -fn insert_row() { - let db_relative_path = "./db/insert.db"; - let db_path = Path::new(&db_relative_path); - let conn = sqlite::open(db_path); - - let table_row: User = User { - id: AutoIncrementPrimaryKey::default(), - username: "mjovanc".to_string(), - email: "mjovanc@icloud.com".to_string(), - address: "Some Random Address 1".to_string(), - }; - - match conn { - Ok(c) => { - let result = sqlite::insert(c, vec![table_row]); - assert!(result.is_ok()); - } - Err(e) => { - panic!("Failed to INSERT: {:?}", e); - } - } -} - -#[test] -fn update() { - let db_relative_path = "./db/insert.db"; - let db_path = Path::new(&db_relative_path); - let conn = sqlite::open(db_path); - - let columns = vec!["username".to_string()]; - - let condition = Condition::Eq("username".to_string(), "mjovanc".to_string()); - - let table_row: User = User { - id: AutoIncrementPrimaryKey::::new(Some(0)), - username: "mjovanc".to_string(), - email: "mjovanc@icloud.com".to_string(), - address: "Some Random Address 1".to_string(), - }; - - let mut order = HashMap::new(); - order.insert(vec!["id".to_string()], "DESC".to_string()); - - match conn { - Ok(c) => { - let result = sqlite::update(&c, table_row) - .set(columns) - .where_clause(condition) - .order_by(order) - .limit(4) - .offset(0) - .build(); - println!("{:?}", result); - assert!(result.is_ok()); - } - Err(e) => { - panic!("Failed to UPDATE: {:?}", e); - } - } -} - -#[test] -fn delete() { - let db_relative_path = "./db/insert.db"; - let db_path = Path::new(&db_relative_path); - let conn = sqlite::open(db_path); - - let condition = Condition::Eq("address".to_string(), "Some Random Address 1".to_string()); - - let mut order = HashMap::new(); - order.insert(vec!["id".to_string()], "DESC".to_string()); - - match conn { - Ok(c) => { - let result = sqlite::delete(c) - .from(User::default()) - .where_clause(condition) - .order_by(order) - .limit(20) - .offset(0) - .build(); - println!("{:?}", result); - assert!(result.is_ok()); - } - Err(e) => { - panic!("Failed to DELETE: {:?}", e); - } - } -} - #[test] fn select() { let db_relative_path = "./db/select.db"; @@ -500,46 +391,6 @@ fn select_sub_queries() { }; } -#[test] -fn update_with_sub_queries() { - let db_relative_path = "./db/update.db"; - let db_path = Path::new(&db_relative_path); - let conn = sqlite::open(db_path); - - let table_row: User = User { - id: AutoIncrementPrimaryKey::::new(Some(0)), - username: "mjovanc".to_string(), - email: "mjovanc@icloud.com".to_string(), - address: "Some Random Address 1".to_string(), - }; - - let columns = vec!["username".to_string()]; - - match conn { - Ok(c) => { - let sub_query = SelectQueryBuilder::new(&c, vec![Column::Text("email".to_string())]) - .from(User::default()) - .where_clause(Condition::Eq( - "email".to_string(), - "mjovanc@icloud.com".to_string(), - )) - .limit(1); - - let set_subqueries = HashMap::from([("email".to_string(), sub_query)]); - - let result = sqlite::update(&c, table_row) - .set(columns) - .set_subqueries(set_subqueries) - .where_clause(Condition::Eq("username".to_owned(), "otheruser".to_owned())) - .build(); - - println!("{:?}", result); - assert!(result.is_ok()); - } - Err(e) => panic!("Failed to UPDATE: {:?}", e), - }; -} - fn select_in() { let db_relative_path = "./db/select.db"; let db_path = Path::new(&db_relative_path); @@ -577,4 +428,4 @@ fn select_in() { } Err(e) => panic!("Failed to SELECT: {:?}", e), }; -} +} \ No newline at end of file diff --git a/njord/tests/sqlite/update_test.rs b/njord/tests/sqlite/update_test.rs new file mode 100644 index 00000000..5a0c7708 --- /dev/null +++ b/njord/tests/sqlite/update_test.rs @@ -0,0 +1,127 @@ +// integrations tests for sqlite + +use njord::column::Column; +use njord::condition::Condition; +use njord::keys::{AutoIncrementPrimaryKey, PrimaryKey}; +use njord::sqlite::select::SelectQueryBuilder; +use njord::sqlite::{self}; +use njord::table::Table; +use njord_derive::Table; +use std::collections::HashMap; +use std::path::Path; + +#[derive(Table, Clone)] +#[table_name = "users"] +pub struct User { + id: AutoIncrementPrimaryKey, + username: String, + email: String, + address: String, +} + +#[derive(Table)] +#[table_name = "users"] +pub struct UserWithSubQuery { + id: AutoIncrementPrimaryKey, + username: String, + email: String, + address: String, + additional_address: String, +} + +#[derive(Table)] +#[table_name = "categories"] +pub struct Category { + id: PrimaryKey, + name: String, +} + +#[derive(Table)] +#[table_name = "products"] +pub struct Product { + id: PrimaryKey, + name: String, + description: String, + price: f64, + stock_quantity: usize, + category: Category, // one-to-one relationship + discount: f64, +} + +#[test] +fn update() { + let db_relative_path = "./db/insert.db"; + let db_path = Path::new(&db_relative_path); + let conn = sqlite::open(db_path); + + let columns = vec!["username".to_string()]; + + let condition = Condition::Eq("username".to_string(), "mjovanc".to_string()); + + let table_row: User = User { + id: AutoIncrementPrimaryKey::::new(Some(0)), + username: "mjovanc".to_string(), + email: "mjovanc@icloud.com".to_string(), + address: "Some Random Address 1".to_string(), + }; + + let mut order = HashMap::new(); + order.insert(vec!["id".to_string()], "DESC".to_string()); + + match conn { + Ok(c) => { + let result = sqlite::update(&c, table_row) + .set(columns) + .where_clause(condition) + .order_by(order) + .limit(4) + .offset(0) + .build(); + println!("{:?}", result); + assert!(result.is_ok()); + } + Err(e) => { + panic!("Failed to UPDATE: {:?}", e); + } + } +} + +#[test] +fn update_with_sub_queries() { + let db_relative_path = "./db/update.db"; + let db_path = Path::new(&db_relative_path); + let conn = sqlite::open(db_path); + + let table_row: User = User { + id: AutoIncrementPrimaryKey::::new(Some(0)), + username: "mjovanc".to_string(), + email: "mjovanc@icloud.com".to_string(), + address: "Some Random Address 1".to_string(), + }; + + let columns = vec!["username".to_string()]; + + match conn { + Ok(c) => { + let sub_query = SelectQueryBuilder::new(&c, vec![Column::Text("email".to_string())]) + .from(User::default()) + .where_clause(Condition::Eq( + "email".to_string(), + "mjovanc@icloud.com".to_string(), + )) + .limit(1); + + let set_subqueries = HashMap::from([("email".to_string(), sub_query)]); + + let result = sqlite::update(&c, table_row) + .set(columns) + .set_subqueries(set_subqueries) + .where_clause(Condition::Eq("username".to_owned(), "otheruser".to_owned())) + .build(); + + println!("{:?}", result); + assert!(result.is_ok()); + } + Err(e) => panic!("Failed to UPDATE: {:?}", e), + }; +} \ No newline at end of file From 7d4faff62b1b8acad6529b4f2b4a7fe1e699ecee Mon Sep 17 00:00:00 2001 From: Christopher Zeuch Date: Mon, 7 Oct 2024 18:54:57 +0200 Subject: [PATCH 02/10] Updated cargo.toml --- njord/Cargo.toml | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/njord/Cargo.toml b/njord/Cargo.toml index 224435e7..ba93320a 100644 --- a/njord/Cargo.toml +++ b/njord/Cargo.toml @@ -33,3 +33,27 @@ njord_derive = { version = "0.3.0", path = "../njord_derive" } [features] default = ["sqlite"] sqlite = [] + +[[test]] +name = "open_test" +path = "tests/sqlite/open_test.rs" + +[[test]] +name = "insert_test" +path = "tests/sqlite/insert_test.rs" + +[[test]] +name = "update_test" +path = "tests/sqlite/update_test.rs" + +[[test]] +name = "delete_test" +path = "tests/sqlite/delete_test.rs" + +[[test]] +name = "select_test" +path = "tests/sqlite/select_test.rs" + +[[test]] +name = "all_sqlite_tests" +path = "tests/sqlite/mod.rs" From 3093820351c64bc2f7ad7ddf588614b54a92cbd7 Mon Sep 17 00:00:00 2001 From: Christopher Zeuch Date: Mon, 7 Oct 2024 18:55:42 +0200 Subject: [PATCH 03/10] Created mod file --- njord/tests/sqlite/mod.rs | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 njord/tests/sqlite/mod.rs diff --git a/njord/tests/sqlite/mod.rs b/njord/tests/sqlite/mod.rs new file mode 100644 index 00000000..f0469a8d --- /dev/null +++ b/njord/tests/sqlite/mod.rs @@ -0,0 +1,5 @@ +mod open_test; +mod insert_test; +mod update_test; +mod delete_test; +mod select_test; \ No newline at end of file From 39ab930a2c35ef195504ab81daa54eb9e31849d7 Mon Sep 17 00:00:00 2001 From: Christopher Zeuch Date: Mon, 7 Oct 2024 19:09:59 +0200 Subject: [PATCH 04/10] Addressed all warnings --- njord/tests/sqlite/delete_test.rs | 4 ---- njord/tests/sqlite/insert_test.rs | 6 ------ njord/tests/sqlite/open_test.rs | 6 ------ njord/tests/sqlite/select_test.rs | 4 +--- njord/tests/sqlite/update_test.rs | 2 -- 5 files changed, 1 insertion(+), 21 deletions(-) diff --git a/njord/tests/sqlite/delete_test.rs b/njord/tests/sqlite/delete_test.rs index 67b9ea7b..36c23ee2 100644 --- a/njord/tests/sqlite/delete_test.rs +++ b/njord/tests/sqlite/delete_test.rs @@ -1,9 +1,5 @@ -// integrations tests for sqlite - -use njord::column::Column; use njord::condition::Condition; use njord::keys::{AutoIncrementPrimaryKey, PrimaryKey}; -use njord::sqlite::select::SelectQueryBuilder; use njord::sqlite::{self}; use njord::table::Table; use njord_derive::Table; diff --git a/njord/tests/sqlite/insert_test.rs b/njord/tests/sqlite/insert_test.rs index 3e400d03..c8f9e414 100644 --- a/njord/tests/sqlite/insert_test.rs +++ b/njord/tests/sqlite/insert_test.rs @@ -1,13 +1,7 @@ -// integrations tests for sqlite - -use njord::column::Column; -use njord::condition::Condition; use njord::keys::{AutoIncrementPrimaryKey, PrimaryKey}; -use njord::sqlite::select::SelectQueryBuilder; use njord::sqlite::{self}; use njord::table::Table; use njord_derive::Table; -use std::collections::HashMap; use std::path::Path; #[derive(Table, Clone)] diff --git a/njord/tests/sqlite/open_test.rs b/njord/tests/sqlite/open_test.rs index 0fad6a89..edb4b191 100644 --- a/njord/tests/sqlite/open_test.rs +++ b/njord/tests/sqlite/open_test.rs @@ -1,13 +1,7 @@ -// integrations tests for sqlite - -use njord::column::Column; -use njord::condition::Condition; use njord::keys::{AutoIncrementPrimaryKey, PrimaryKey}; -use njord::sqlite::select::SelectQueryBuilder; use njord::sqlite::{self}; use njord::table::Table; use njord_derive::Table; -use std::collections::HashMap; use std::path::Path; #[derive(Table, Clone)] diff --git a/njord/tests/sqlite/select_test.rs b/njord/tests/sqlite/select_test.rs index a0b48142..4e6e0690 100644 --- a/njord/tests/sqlite/select_test.rs +++ b/njord/tests/sqlite/select_test.rs @@ -1,9 +1,6 @@ -// integrations tests for sqlite - use njord::column::Column; use njord::condition::Condition; use njord::keys::{AutoIncrementPrimaryKey, PrimaryKey}; -use njord::sqlite::select::SelectQueryBuilder; use njord::sqlite::{self}; use njord::table::Table; use njord_derive::Table; @@ -391,6 +388,7 @@ fn select_sub_queries() { }; } +#[test] fn select_in() { let db_relative_path = "./db/select.db"; let db_path = Path::new(&db_relative_path); diff --git a/njord/tests/sqlite/update_test.rs b/njord/tests/sqlite/update_test.rs index 5a0c7708..881bc192 100644 --- a/njord/tests/sqlite/update_test.rs +++ b/njord/tests/sqlite/update_test.rs @@ -1,5 +1,3 @@ -// integrations tests for sqlite - use njord::column::Column; use njord::condition::Condition; use njord::keys::{AutoIncrementPrimaryKey, PrimaryKey}; From 1a18856f1453c38657029d4399a5597501702a08 Mon Sep 17 00:00:00 2001 From: Christopher Zeuch Date: Mon, 7 Oct 2024 19:13:18 +0200 Subject: [PATCH 05/10] Made the implementation scalable --- njord/Cargo.toml | 22 +--------------------- tests/sqlite/mod.rs | 6 ++++++ 2 files changed, 7 insertions(+), 21 deletions(-) create mode 100644 tests/sqlite/mod.rs diff --git a/njord/Cargo.toml b/njord/Cargo.toml index ba93320a..a1ec037c 100644 --- a/njord/Cargo.toml +++ b/njord/Cargo.toml @@ -35,25 +35,5 @@ default = ["sqlite"] sqlite = [] [[test]] -name = "open_test" -path = "tests/sqlite/open_test.rs" - -[[test]] -name = "insert_test" -path = "tests/sqlite/insert_test.rs" - -[[test]] -name = "update_test" -path = "tests/sqlite/update_test.rs" - -[[test]] -name = "delete_test" -path = "tests/sqlite/delete_test.rs" - -[[test]] -name = "select_test" -path = "tests/sqlite/select_test.rs" - -[[test]] -name = "all_sqlite_tests" +name = "sqlite_tests" path = "tests/sqlite/mod.rs" diff --git a/tests/sqlite/mod.rs b/tests/sqlite/mod.rs new file mode 100644 index 00000000..1c464d13 --- /dev/null +++ b/tests/sqlite/mod.rs @@ -0,0 +1,6 @@ +mod open_test; +mod insert_test; +mod update_test; +mod delete_test; +mod select_test; +// Add more test modules as needed \ No newline at end of file From 6b197366d6293fbde4da3d630cb1fd887c527325 Mon Sep 17 00:00:00 2001 From: Christopher Zeuch Date: Mon, 7 Oct 2024 19:15:59 +0200 Subject: [PATCH 06/10] Deleted duplicate mod file --- tests/sqlite/mod.rs | 6 ------ 1 file changed, 6 deletions(-) delete mode 100644 tests/sqlite/mod.rs diff --git a/tests/sqlite/mod.rs b/tests/sqlite/mod.rs deleted file mode 100644 index 1c464d13..00000000 --- a/tests/sqlite/mod.rs +++ /dev/null @@ -1,6 +0,0 @@ -mod open_test; -mod insert_test; -mod update_test; -mod delete_test; -mod select_test; -// Add more test modules as needed \ No newline at end of file From cc0e0dcd39eeec6c779968d7e09f861b63257030 Mon Sep 17 00:00:00 2001 From: Christopher Zeuch Date: Mon, 7 Oct 2024 19:25:47 +0200 Subject: [PATCH 07/10] Added testing section to README --- README.md | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/README.md b/README.md index 8da82560..6a4b9c0c 100644 --- a/README.md +++ b/README.md @@ -322,6 +322,36 @@ ORDER BY email DESC ``` +## Testing + +### Running tests + +**Run all tests** + +```bash +cargo test +``` + +**Run specific test folders** + +```bash +cargo test --test sqlite_tests +``` + +**Run specific test files** + +```bash +cargo test --test sqlite_tests -- update_test +``` + +### Adding tests + +Once your new test folder and tests have been created: + +1. Create a `mod.rs` file in your test folder. +2. Add your tests to the `mod.rs` file. +3. Update `Cargo.toml` with a new `[[test]]` section containing your desired name and the test path. + ## Getting Help Are you having trouble with Njord? We want to help! From 15de7adb6d7d24b41989a800d1fc910d5bb4237c Mon Sep 17 00:00:00 2001 From: Christopher Zeuch Date: Mon, 7 Oct 2024 20:52:03 +0200 Subject: [PATCH 08/10] Moved structs into mod & updated test files --- njord/tests/sqlite/delete_test.rs | 44 ++---------------------------- njord/tests/sqlite/insert_test.rs | 45 +++---------------------------- njord/tests/sqlite/mod.rs | 44 +++++++++++++++++++++++++++++- njord/tests/sqlite/open_test.rs | 43 +---------------------------- njord/tests/sqlite/select_test.rs | 45 +++---------------------------- njord/tests/sqlite/update_test.rs | 43 ++--------------------------- 6 files changed, 54 insertions(+), 210 deletions(-) diff --git a/njord/tests/sqlite/delete_test.rs b/njord/tests/sqlite/delete_test.rs index 36c23ee2..513cc65c 100644 --- a/njord/tests/sqlite/delete_test.rs +++ b/njord/tests/sqlite/delete_test.rs @@ -1,48 +1,8 @@ use njord::condition::Condition; -use njord::keys::{AutoIncrementPrimaryKey, PrimaryKey}; -use njord::sqlite::{self}; -use njord::table::Table; -use njord_derive::Table; +use njord::sqlite; use std::collections::HashMap; use std::path::Path; - -#[derive(Table, Clone)] -#[table_name = "users"] -pub struct User { - id: AutoIncrementPrimaryKey, - username: String, - email: String, - address: String, -} - -#[derive(Table)] -#[table_name = "users"] -pub struct UserWithSubQuery { - id: AutoIncrementPrimaryKey, - username: String, - email: String, - address: String, - additional_address: String, -} - -#[derive(Table)] -#[table_name = "categories"] -pub struct Category { - id: PrimaryKey, - name: String, -} - -#[derive(Table)] -#[table_name = "products"] -pub struct Product { - id: PrimaryKey, - name: String, - description: String, - price: f64, - stock_quantity: usize, - category: Category, // one-to-one relationship - discount: f64, -} +use super::User; #[test] fn delete() { diff --git a/njord/tests/sqlite/insert_test.rs b/njord/tests/sqlite/insert_test.rs index c8f9e414..48aa2b3f 100644 --- a/njord/tests/sqlite/insert_test.rs +++ b/njord/tests/sqlite/insert_test.rs @@ -1,46 +1,7 @@ -use njord::keys::{AutoIncrementPrimaryKey, PrimaryKey}; -use njord::sqlite::{self}; -use njord::table::Table; -use njord_derive::Table; +use njord::keys::AutoIncrementPrimaryKey; +use njord::sqlite; use std::path::Path; - -#[derive(Table, Clone)] -#[table_name = "users"] -pub struct User { - id: AutoIncrementPrimaryKey, - username: String, - email: String, - address: String, -} - -#[derive(Table)] -#[table_name = "users"] -pub struct UserWithSubQuery { - id: AutoIncrementPrimaryKey, - username: String, - email: String, - address: String, - additional_address: String, -} - -#[derive(Table)] -#[table_name = "categories"] -pub struct Category { - id: PrimaryKey, - name: String, -} - -#[derive(Table)] -#[table_name = "products"] -pub struct Product { - id: PrimaryKey, - name: String, - description: String, - price: f64, - stock_quantity: usize, - category: Category, // one-to-one relationship - discount: f64, -} +use super::User; #[test] fn insert_row() { diff --git a/njord/tests/sqlite/mod.rs b/njord/tests/sqlite/mod.rs index f0469a8d..c4bf4e54 100644 --- a/njord/tests/sqlite/mod.rs +++ b/njord/tests/sqlite/mod.rs @@ -2,4 +2,46 @@ mod open_test; mod insert_test; mod update_test; mod delete_test; -mod select_test; \ No newline at end of file +mod select_test; + +use njord::keys::{AutoIncrementPrimaryKey, PrimaryKey}; +use njord::table::Table; +use njord_derive::Table; + +#[derive(Table, Clone)] +#[table_name = "users"] +pub struct User { + pub id: AutoIncrementPrimaryKey, + pub username: String, + pub email: String, + pub address: String, +} + +#[derive(Table)] +#[table_name = "users"] +pub struct UserWithSubQuery { + pub id: AutoIncrementPrimaryKey, + pub username: String, + pub email: String, + pub address: String, + pub additional_address: String, +} + +#[derive(Table)] +#[table_name = "categories"] +pub struct Category { + pub id: PrimaryKey, + pub name: String, +} + +#[derive(Table)] +#[table_name = "products"] +pub struct Product { + pub id: PrimaryKey, + pub name: String, + pub description: String, + pub price: f64, + pub stock_quantity: usize, + pub category: Category, // one-to-one relationship + pub discount: f64, +} \ No newline at end of file diff --git a/njord/tests/sqlite/open_test.rs b/njord/tests/sqlite/open_test.rs index edb4b191..3ec057ec 100644 --- a/njord/tests/sqlite/open_test.rs +++ b/njord/tests/sqlite/open_test.rs @@ -1,47 +1,6 @@ -use njord::keys::{AutoIncrementPrimaryKey, PrimaryKey}; -use njord::sqlite::{self}; -use njord::table::Table; -use njord_derive::Table; +use njord::sqlite; use std::path::Path; -#[derive(Table, Clone)] -#[table_name = "users"] -pub struct User { - id: AutoIncrementPrimaryKey, - username: String, - email: String, - address: String, -} - -#[derive(Table)] -#[table_name = "users"] -pub struct UserWithSubQuery { - id: AutoIncrementPrimaryKey, - username: String, - email: String, - address: String, - additional_address: String, -} - -#[derive(Table)] -#[table_name = "categories"] -pub struct Category { - id: PrimaryKey, - name: String, -} - -#[derive(Table)] -#[table_name = "products"] -pub struct Product { - id: PrimaryKey, - name: String, - description: String, - price: f64, - stock_quantity: usize, - category: Category, // one-to-one relationship - discount: f64, -} - #[test] fn open_db() { let db_relative_path = "./db/open.db"; diff --git a/njord/tests/sqlite/select_test.rs b/njord/tests/sqlite/select_test.rs index 4e6e0690..f574734c 100644 --- a/njord/tests/sqlite/select_test.rs +++ b/njord/tests/sqlite/select_test.rs @@ -1,49 +1,10 @@ use njord::column::Column; use njord::condition::Condition; -use njord::keys::{AutoIncrementPrimaryKey, PrimaryKey}; -use njord::sqlite::{self}; -use njord::table::Table; -use njord_derive::Table; +use njord::sqlite; +use njord::keys::AutoIncrementPrimaryKey; use std::collections::HashMap; use std::path::Path; - -#[derive(Table, Clone)] -#[table_name = "users"] -pub struct User { - id: AutoIncrementPrimaryKey, - username: String, - email: String, - address: String, -} - -#[derive(Table)] -#[table_name = "users"] -pub struct UserWithSubQuery { - id: AutoIncrementPrimaryKey, - username: String, - email: String, - address: String, - additional_address: String, -} - -#[derive(Table)] -#[table_name = "categories"] -pub struct Category { - id: PrimaryKey, - name: String, -} - -#[derive(Table)] -#[table_name = "products"] -pub struct Product { - id: PrimaryKey, - name: String, - description: String, - price: f64, - stock_quantity: usize, - category: Category, // one-to-one relationship - discount: f64, -} +use super::{User, UserWithSubQuery}; #[test] fn select() { diff --git a/njord/tests/sqlite/update_test.rs b/njord/tests/sqlite/update_test.rs index 881bc192..42fdf726 100644 --- a/njord/tests/sqlite/update_test.rs +++ b/njord/tests/sqlite/update_test.rs @@ -1,50 +1,11 @@ use njord::column::Column; use njord::condition::Condition; -use njord::keys::{AutoIncrementPrimaryKey, PrimaryKey}; +use njord::keys::AutoIncrementPrimaryKey; use njord::sqlite::select::SelectQueryBuilder; use njord::sqlite::{self}; -use njord::table::Table; -use njord_derive::Table; use std::collections::HashMap; use std::path::Path; - -#[derive(Table, Clone)] -#[table_name = "users"] -pub struct User { - id: AutoIncrementPrimaryKey, - username: String, - email: String, - address: String, -} - -#[derive(Table)] -#[table_name = "users"] -pub struct UserWithSubQuery { - id: AutoIncrementPrimaryKey, - username: String, - email: String, - address: String, - additional_address: String, -} - -#[derive(Table)] -#[table_name = "categories"] -pub struct Category { - id: PrimaryKey, - name: String, -} - -#[derive(Table)] -#[table_name = "products"] -pub struct Product { - id: PrimaryKey, - name: String, - description: String, - price: f64, - stock_quantity: usize, - category: Category, // one-to-one relationship - discount: f64, -} +use super::{User}; #[test] fn update() { From 8a94cd95c20191e0fd4e95d7bcbf8bbfe089d4fe Mon Sep 17 00:00:00 2001 From: Christopher Zeuch Date: Mon, 7 Oct 2024 20:52:21 +0200 Subject: [PATCH 09/10] Added pic to README --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 6a4b9c0c..8f359360 100644 --- a/README.md +++ b/README.md @@ -399,6 +399,7 @@ being awesome contributors to this project. **We'd like to take a moment to reco [SvMak](https://github.com/SvMak) [TomasWild](https://github.com/TomasWild) [chaseWillden](https://github.com/chaseWillden) +[Hiccup-za](https://github.com/Hiccup-za) ## License From 6b1416f05766b8f0eab8560e2f407911bf458e3f Mon Sep 17 00:00:00 2001 From: Christopher Zeuch Date: Mon, 7 Oct 2024 20:54:22 +0200 Subject: [PATCH 10/10] Updated README TOC --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 8f359360..573a64b7 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,9 @@ A lightweight and extensible ORM library for Rust. - [Update data](#update-data) - [Delete data](#delete-data) - [Select data](#select-data) +- [Testing](#testing) + - [Running tests](#running-tests) + - [Adding tests](#adding-tests) - [Getting Help](#getting-help) - [Reporting Issues](#reporting-issues) - [Contributing](#contributing)