|
@@ -110,7 +110,7 @@ mod manual_test_db {
|
|
|
|
|
|
impl Entity for SimpleEntity {
|
|
impl Entity for SimpleEntity {
|
|
type Parts = SimpleEntityName;
|
|
type Parts = SimpleEntityName;
|
|
- type Uniques = SimpleEntityName;
|
|
|
|
|
|
+ type Keys = SimpleEntityName;
|
|
type ID = SimpleEntityID;
|
|
type ID = SimpleEntityID;
|
|
|
|
|
|
fn build(name: String) -> Self {
|
|
fn build(name: String) -> Self {
|
|
@@ -203,7 +203,7 @@ mod derive_tests {
|
|
|
|
|
|
#[derive(Entity)]
|
|
#[derive(Entity)]
|
|
struct Person {
|
|
struct Person {
|
|
- #[unique]
|
|
|
|
|
|
+ #[key]
|
|
name: String,
|
|
name: String,
|
|
roles: AssocMap<Role>,
|
|
roles: AssocMap<Role>,
|
|
}
|
|
}
|
|
@@ -230,13 +230,7 @@ mod derive_tests {
|
|
// let db = PeopleDB::open_path(":memory:").expect("couldn't open database");
|
|
// let db = PeopleDB::open_path(":memory:").expect("couldn't open database");
|
|
let name_string = "name_here".to_string();
|
|
let name_string = "name_here".to_string();
|
|
// check that it isn't in the database before we insert it
|
|
// check that it isn't in the database before we insert it
|
|
- assert!(db
|
|
|
|
- .people
|
|
|
|
- .unique(&name_string)
|
|
|
|
- .get()
|
|
|
|
- .ok()
|
|
|
|
- .flatten()
|
|
|
|
- .is_none());
|
|
|
|
|
|
+ assert!(db.people.keyed(&name_string).get().ok().flatten().is_none());
|
|
|
|
|
|
db.people
|
|
db.people
|
|
.insert(Person {
|
|
.insert(Person {
|
|
@@ -246,13 +240,7 @@ mod derive_tests {
|
|
.expect("failed to insert");
|
|
.expect("failed to insert");
|
|
|
|
|
|
// check that it is in the database after we insert it
|
|
// check that it is in the database after we insert it
|
|
- assert!(db
|
|
|
|
- .people
|
|
|
|
- .unique(&name_string)
|
|
|
|
- .get()
|
|
|
|
- .ok()
|
|
|
|
- .flatten()
|
|
|
|
- .is_some());
|
|
|
|
|
|
+ assert!(db.people.keyed(&name_string).get().ok().flatten().is_some());
|
|
}
|
|
}
|
|
|
|
|
|
#[test]
|
|
#[test]
|
|
@@ -269,7 +257,7 @@ mod derive_tests {
|
|
|
|
|
|
let person = db
|
|
let person = db
|
|
.people
|
|
.people
|
|
- .unique(&name_string)
|
|
|
|
|
|
+ .keyed(&name_string)
|
|
.get()
|
|
.get()
|
|
.ok()
|
|
.ok()
|
|
.flatten()
|
|
.flatten()
|
|
@@ -297,7 +285,7 @@ mod derive_tests {
|
|
|
|
|
|
let person = db
|
|
let person = db
|
|
.people
|
|
.people
|
|
- .unique(&name_string)
|
|
|
|
|
|
+ .keyed(&name_string)
|
|
.get()
|
|
.get()
|
|
.ok()
|
|
.ok()
|
|
.flatten()
|
|
.flatten()
|
|
@@ -673,16 +661,16 @@ mod query_equivalence {
|
|
use test_log::test;
|
|
use test_log::test;
|
|
#[derive(Entity)]
|
|
#[derive(Entity)]
|
|
struct SingleItem {
|
|
struct SingleItem {
|
|
- #[unique]
|
|
|
|
|
|
+ #[key]
|
|
s: String,
|
|
s: String,
|
|
v: Vec<u8>,
|
|
v: Vec<u8>,
|
|
}
|
|
}
|
|
|
|
|
|
#[derive(Entity)]
|
|
#[derive(Entity)]
|
|
struct DoubleItem {
|
|
struct DoubleItem {
|
|
- #[unique]
|
|
|
|
|
|
+ #[key]
|
|
s: String,
|
|
s: String,
|
|
- #[unique]
|
|
|
|
|
|
+ #[key]
|
|
t: String,
|
|
t: String,
|
|
v: usize,
|
|
v: usize,
|
|
}
|
|
}
|
|
@@ -713,26 +701,26 @@ mod query_equivalence {
|
|
|
|
|
|
assert!(db
|
|
assert!(db
|
|
.single_items
|
|
.single_items
|
|
- .unique("string 2")
|
|
|
|
|
|
+ .keyed("string 2")
|
|
.get()
|
|
.get()
|
|
.expect("couldn't query db")
|
|
.expect("couldn't query db")
|
|
.is_some());
|
|
.is_some());
|
|
assert!(db
|
|
assert!(db
|
|
.single_items
|
|
.single_items
|
|
- .unique("string 3")
|
|
|
|
|
|
+ .keyed("string 3")
|
|
.get()
|
|
.get()
|
|
.expect("couldn't query db")
|
|
.expect("couldn't query db")
|
|
.is_none());
|
|
.is_none());
|
|
|
|
|
|
assert!(db
|
|
assert!(db
|
|
.single_items
|
|
.single_items
|
|
- .unique(String::from("string 2"))
|
|
|
|
|
|
+ .keyed(String::from("string 2"))
|
|
.get()
|
|
.get()
|
|
.expect("couldn't query db")
|
|
.expect("couldn't query db")
|
|
.is_some());
|
|
.is_some());
|
|
assert!(db
|
|
assert!(db
|
|
.single_items
|
|
.single_items
|
|
- .unique(String::from("string 3"))
|
|
|
|
|
|
+ .keyed(String::from("string 3"))
|
|
.get()
|
|
.get()
|
|
.expect("couldn't query db")
|
|
.expect("couldn't query db")
|
|
.is_none());
|
|
.is_none());
|
|
@@ -760,26 +748,26 @@ mod query_equivalence {
|
|
|
|
|
|
assert!(db
|
|
assert!(db
|
|
.double_items
|
|
.double_items
|
|
- .unique(("string 2", "second string 2"))
|
|
|
|
|
|
+ .keyed(("string 2", "second string 2"))
|
|
.get()
|
|
.get()
|
|
.expect("couldn't query db")
|
|
.expect("couldn't query db")
|
|
.is_some());
|
|
.is_some());
|
|
assert!(db
|
|
assert!(db
|
|
.double_items
|
|
.double_items
|
|
- .unique(("string 3", "second string 3"))
|
|
|
|
|
|
+ .keyed(("string 3", "second string 3"))
|
|
.get()
|
|
.get()
|
|
.expect("couldn't query db")
|
|
.expect("couldn't query db")
|
|
.is_none());
|
|
.is_none());
|
|
|
|
|
|
assert!(db
|
|
assert!(db
|
|
.double_items
|
|
.double_items
|
|
- .unique((String::from("string 2"), String::from("second string 2")))
|
|
|
|
|
|
+ .keyed((String::from("string 2"), String::from("second string 2")))
|
|
.get()
|
|
.get()
|
|
.expect("couldn't query db")
|
|
.expect("couldn't query db")
|
|
.is_some());
|
|
.is_some());
|
|
assert!(db
|
|
assert!(db
|
|
.double_items
|
|
.double_items
|
|
- .unique((String::from("string 3"), String::from("second string 3")))
|
|
|
|
|
|
+ .keyed((String::from("string 3"), String::from("second string 3")))
|
|
.get()
|
|
.get()
|
|
.expect("couldn't query db")
|
|
.expect("couldn't query db")
|
|
.is_none());
|
|
.is_none());
|