impls more DbApi actions, adds a test

This commit is contained in:
2019-07-16 14:56:54 +02:00
parent 441b7f5ad6
commit 21369535e8
2 changed files with 106 additions and 11 deletions

View File

@@ -14,9 +14,9 @@ type OwnedBy = Select<OwnedLoot, ItemColumns>;
/// Or maybe this is a little too confusing ??
#[derive(Debug, Queryable, Serialize)]
pub struct Item {
id: i32,
name: String,
base_price: i32,
pub id: i32,
pub name: String,
pub base_price: i32,
}
impl Item {
@@ -35,7 +35,7 @@ type OwnedLoot = Filter<looted::table, WithOwner>;
pub(crate) struct Loot {
id: i32,
name: String,
base_value: i32,
base_price: i32,
owner: i32,
}
@@ -45,13 +45,17 @@ impl Loot {
looted::table.filter(looted::owner_id.eq(id))
}
pub(crate) fn owns(player: i32, item: i32) -> Exists<Find<OwnedLoot, i32>> {
exists(Loot::owned_by(player).find(item))
}
pub(crate) fn exists(id: i32) -> Exists<Find<looted::table, i32>> {
exists(looted::table.find(id))
}
}
/// Description of an item : (name, value in gold)
type ItemDesc<'a> = (&'a str, i32);
pub type ItemDesc<'a> = (&'a str, i32);
/// An item being looted or bought.
///