-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
8 changed files
with
248 additions
and
194 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
use njord::condition::Condition; | ||
use njord::sqlite; | ||
use std::collections::HashMap; | ||
use std::path::Path; | ||
use super::User; | ||
|
||
#[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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
use njord::keys::AutoIncrementPrimaryKey; | ||
use njord::sqlite; | ||
use std::path::Path; | ||
use super::User; | ||
|
||
#[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: "[email protected]".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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
mod open_test; | ||
mod insert_test; | ||
mod update_test; | ||
mod delete_test; | ||
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<usize>, | ||
pub username: String, | ||
pub email: String, | ||
pub address: String, | ||
} | ||
|
||
#[derive(Table)] | ||
#[table_name = "users"] | ||
pub struct UserWithSubQuery { | ||
pub id: AutoIncrementPrimaryKey<usize>, | ||
pub username: String, | ||
pub email: String, | ||
pub address: String, | ||
pub additional_address: String, | ||
} | ||
|
||
#[derive(Table)] | ||
#[table_name = "categories"] | ||
pub struct Category { | ||
pub id: PrimaryKey<usize>, | ||
pub name: String, | ||
} | ||
|
||
#[derive(Table)] | ||
#[table_name = "products"] | ||
pub struct Product { | ||
pub id: PrimaryKey<usize>, | ||
pub name: String, | ||
pub description: String, | ||
pub price: f64, | ||
pub stock_quantity: usize, | ||
pub category: Category, // one-to-one relationship | ||
pub discount: f64, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
use njord::sqlite; | ||
use std::path::Path; | ||
|
||
#[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()); | ||
} |
Oops, something went wrong.