This commit is contained in:
Dominic Grimm 2023-02-12 09:18:56 +01:00
parent 501b9d3093
commit 964534d0d9
No known key found for this signature in database
GPG key ID: 6F294212DEAAC530
21 changed files with 762 additions and 207 deletions

View file

@ -10,8 +10,11 @@ pub mod models;
pub mod schema;
pub type DbPool = Pool<ConnectionManager<PgConnection>>;
pub type Connection = PgConnection;
pub fn establish_connection() -> ConnectionResult<PgConnection> {
use diesel::Connection;
PgConnection::establish(&config::CONFIG.db_url)
}

View file

@ -52,3 +52,20 @@ pub struct UpdatePost<'a> {
pub edited_at: Option<Option<NaiveDate>>,
pub active: Option<bool>,
}
#[derive(Associations, Identifiable, Queryable, Debug)]
#[diesel(belongs_to(Post))]
#[diesel(belongs_to(Tag))]
#[diesel(table_name = schema::post_tags)]
pub struct PostTag {
pub id: i32,
pub post_id: i32,
pub tag_id: i32,
}
#[derive(Insertable, Debug)]
#[diesel(table_name = schema::post_tags)]
pub struct NewPostTag {
pub post_id: i32,
pub tag_id: i32,
}

View file

@ -17,3 +17,11 @@ diesel::table! {
active -> Bool,
}
}
diesel::table! {
post_tags {
id -> Integer,
post_id -> Integer,
tag_id -> Integer,
}
}