forked from Roflin/gamenight
Splits database into a separate crate
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
use diesel::{ExpressionMethods, Insertable, PgConnection, QueryDsl, Queryable, RunQueryDsl};
|
||||
use serde::{Serialize, Deserialize};
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::schema::gamenight_participant;
|
||||
|
||||
use super::error::DatabaseError;
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Insertable, Queryable)]
|
||||
#[diesel(belongs_to(Gamenight))]
|
||||
#[diesel(belongs_to(User))]
|
||||
#[diesel(table_name = gamenight_participant)]
|
||||
pub struct GamenightParticipants {
|
||||
pub gamenight_id: Uuid,
|
||||
pub user_id: Uuid,
|
||||
}
|
||||
|
||||
pub fn gamenight_participants(conn: &mut PgConnection, id: Uuid) -> Result<Vec<GamenightParticipants>, DatabaseError> {
|
||||
Ok(gamenight_participant::table
|
||||
.filter(gamenight_participant::gamenight_id.eq(id))
|
||||
.get_results(conn)?)
|
||||
}
|
||||
Reference in New Issue
Block a user