refactor PlayerView, plans to replace ApiStorage.js by lootalot.js api module
This commit is contained in:
@@ -3,7 +3,7 @@ use crate::{DbConnection, QueryResult};
|
||||
use diesel::prelude::*;
|
||||
|
||||
/// Representation of a player in database
|
||||
#[derive(Queryable, Serialize, Deserialize, Debug)]
|
||||
#[derive(Identifiable, Queryable, Serialize, Deserialize, Debug)]
|
||||
pub struct Player {
|
||||
/// DB Identitier
|
||||
pub id: i32,
|
||||
@@ -29,6 +29,10 @@ impl<'q> Players<'q> {
|
||||
players::table.load(self.0)
|
||||
}
|
||||
|
||||
pub fn find(&self, id: i32) -> QueryResult<Player> {
|
||||
players::table.find(id).first(self.0)
|
||||
}
|
||||
|
||||
pub fn add(&self, name: &str, wealth: f32) -> QueryResult<Player> {
|
||||
diesel::insert_into(players::table)
|
||||
.values(&NewPlayer::create(name, wealth))
|
||||
|
||||
Reference in New Issue
Block a user