adds notifications table and models
This commit is contained in:
@@ -0,0 +1 @@
|
|||||||
|
DROP TABLE notifications;
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
CREATE TABLE notifications (
|
||||||
|
id INTEGER PRIMARY KEY NOT NULL,
|
||||||
|
player_id INTEGER NOT NULL,
|
||||||
|
text VARCHAR NOT NULL,
|
||||||
|
FOREIGN KEY (player_id) REFERENCES players(id)
|
||||||
|
);
|
||||||
@@ -2,6 +2,7 @@ use crate::schema::players;
|
|||||||
use crate::{DbConnection, QueryResult};
|
use crate::{DbConnection, QueryResult};
|
||||||
use diesel::prelude::*;
|
use diesel::prelude::*;
|
||||||
|
|
||||||
|
mod notification;
|
||||||
pub mod wealth;
|
pub mod wealth;
|
||||||
pub use wealth::Wealth;
|
pub use wealth::Wealth;
|
||||||
|
|
||||||
|
|||||||
35
lootalot_db/src/models/player/notification.rs
Normal file
35
lootalot_db/src/models/player/notification.rs
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
use diesel::prelude::*;
|
||||||
|
use crate::{
|
||||||
|
DbConnection,
|
||||||
|
schema::notifications,
|
||||||
|
models::player::Player,
|
||||||
|
};
|
||||||
|
|
||||||
|
#[derive(Identifiable, Queryable, Associations, Serialize, Debug)]
|
||||||
|
#[belongs_to(Player)]
|
||||||
|
struct Notification {
|
||||||
|
pub id: i32,
|
||||||
|
pub player_id: i32,
|
||||||
|
pub text: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Notification {
|
||||||
|
fn add<'a, S: Into<&'a str>>(conn: &DbConnection, id: i32, text: S) -> QueryResult<Notification> {
|
||||||
|
diesel::insert_into(notifications::table)
|
||||||
|
.values(&NewNotification {
|
||||||
|
player_id: id,
|
||||||
|
text: text.into(),
|
||||||
|
})
|
||||||
|
.execute(conn)?;
|
||||||
|
notifications::table
|
||||||
|
.order(notifications::dsl::id.desc())
|
||||||
|
.first(conn)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Insertable)]
|
||||||
|
#[table_name="notifications"]
|
||||||
|
struct NewNotification<'a> {
|
||||||
|
player_id: i32,
|
||||||
|
text: &'a str,
|
||||||
|
}
|
||||||
@@ -24,6 +24,14 @@ table! {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
table! {
|
||||||
|
notifications (id) {
|
||||||
|
id -> Integer,
|
||||||
|
player_id -> Integer,
|
||||||
|
text -> Text,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
table! {
|
table! {
|
||||||
players (id) {
|
players (id) {
|
||||||
id -> Integer,
|
id -> Integer,
|
||||||
@@ -39,5 +47,12 @@ table! {
|
|||||||
joinable!(claims -> looted (loot_id));
|
joinable!(claims -> looted (loot_id));
|
||||||
joinable!(claims -> players (player_id));
|
joinable!(claims -> players (player_id));
|
||||||
joinable!(looted -> players (owner_id));
|
joinable!(looted -> players (owner_id));
|
||||||
|
joinable!(notifications -> players (player_id));
|
||||||
|
|
||||||
allow_tables_to_appear_in_same_query!(claims, items, looted, players,);
|
allow_tables_to_appear_in_same_query!(
|
||||||
|
claims,
|
||||||
|
items,
|
||||||
|
looted,
|
||||||
|
notifications,
|
||||||
|
players,
|
||||||
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user