Add a tag model
This commit is contained in:
parent
e16acf8436
commit
2b7a5bee93
2
migrations/2018-09-05-174106_create_tags/down.sql
Normal file
2
migrations/2018-09-05-174106_create_tags/down.sql
Normal file
@ -0,0 +1,2 @@
|
||||
-- This file should undo anything in `up.sql`
|
||||
DROP TABLE tags;
|
7
migrations/2018-09-05-174106_create_tags/up.sql
Normal file
7
migrations/2018-09-05-174106_create_tags/up.sql
Normal file
@ -0,0 +1,7 @@
|
||||
-- Your SQL goes here
|
||||
CREATE TABLE tags (
|
||||
id SERIAL PRIMARY KEY,
|
||||
tag TEXT NOT NULL DEFAULT '',
|
||||
is_hastag BOOLEAN NOT NULL DEFAULT 'f',
|
||||
post_id INTEGER REFERENCES posts(id) ON DELETE CASCADE NOT NULL
|
||||
)
|
@ -119,4 +119,5 @@ pub mod posts;
|
||||
pub mod reshares;
|
||||
pub mod safe_string;
|
||||
pub mod schema;
|
||||
pub mod tags;
|
||||
pub mod users;
|
||||
|
@ -139,6 +139,15 @@ table! {
|
||||
}
|
||||
}
|
||||
|
||||
table! {
|
||||
tags (id) {
|
||||
id -> Int4,
|
||||
tag -> Text,
|
||||
is_hastag -> Bool,
|
||||
post_id -> Int4,
|
||||
}
|
||||
}
|
||||
|
||||
table! {
|
||||
users (id) {
|
||||
id -> Int4,
|
||||
@ -178,6 +187,7 @@ joinable!(post_authors -> users (author_id));
|
||||
joinable!(posts -> blogs (blog_id));
|
||||
joinable!(reshares -> posts (post_id));
|
||||
joinable!(reshares -> users (user_id));
|
||||
joinable!(tags -> posts (post_id));
|
||||
joinable!(users -> instances (instance_id));
|
||||
|
||||
allow_tables_to_appear_in_same_query!(
|
||||
@ -193,5 +203,6 @@ allow_tables_to_appear_in_same_query!(
|
||||
post_authors,
|
||||
posts,
|
||||
reshares,
|
||||
tags,
|
||||
users,
|
||||
);
|
||||
|
23
plume-models/src/tags.rs
Normal file
23
plume-models/src/tags.rs
Normal file
@ -0,0 +1,23 @@
|
||||
use diesel::{self, PgConnection, ExpressionMethods, RunQueryDsl, QueryDsl};
|
||||
use schema::tags;
|
||||
|
||||
#[derive(Queryable)]
|
||||
pub struct Tag {
|
||||
pub id: i32,
|
||||
pub tag: String,
|
||||
pub is_hastag: bool,
|
||||
pub post_id: i32
|
||||
}
|
||||
|
||||
#[derive(Insertable)]
|
||||
#[table_name = "tags"]
|
||||
pub struct NewTag {
|
||||
pub tag: String,
|
||||
pub is_hastag: bool,
|
||||
pub post_id: i32
|
||||
}
|
||||
|
||||
impl Tag {
|
||||
insert!(tags, NewTag);
|
||||
get!(tags);
|
||||
}
|
Loading…
Reference in New Issue
Block a user