clippy/cleanup
This commit is contained in:
@@ -24,7 +24,7 @@ impl ChatDatabase {
|
||||
db.run_pending_migrations(MIGRATIONS)
|
||||
.map_err(|e| anyhow::anyhow!("Error running migrations: {}", e))?;
|
||||
|
||||
return Ok(Self { db });
|
||||
Ok(Self { db })
|
||||
}
|
||||
|
||||
pub fn insert_conversation(&mut self, conversation: Conversation) -> Result<()> {
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
use diesel::prelude::*;
|
||||
use chrono::NaiveDateTime;
|
||||
use crate::models::{Conversation, Participant};
|
||||
use crate::models::{
|
||||
Conversation,
|
||||
db::participant::InsertableRecord as InsertableParticipant,
|
||||
};
|
||||
|
||||
#[derive(Queryable, Selectable, Insertable, AsChangeset, Clone, Identifiable)]
|
||||
#[diesel(table_name = crate::schema::conversations)]
|
||||
@@ -26,14 +29,15 @@ impl From<Conversation> for Record {
|
||||
}
|
||||
|
||||
// This implementation returns the insertable data types for the conversation and participants
|
||||
impl From<Conversation> for (Record, Vec<Participant>) {
|
||||
impl From<Conversation> for (Record, Vec<InsertableParticipant>) {
|
||||
fn from(conversation: Conversation) -> Self {
|
||||
(
|
||||
Record::from(conversation.clone()),
|
||||
|
||||
// Keep in mind, db::participant::Record is the selectable data type for the
|
||||
// participants table, whereas Participant is the insertable model type.
|
||||
conversation.participants
|
||||
.into_iter()
|
||||
.map(InsertableParticipant::from)
|
||||
.collect()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,13 +2,27 @@ use diesel::prelude::*;
|
||||
use crate::models::Participant;
|
||||
use crate::schema::conversation_participants;
|
||||
|
||||
#[derive(Queryable, Selectable, AsChangeset, Clone, PartialEq, Debug, Identifiable)]
|
||||
#[derive(Queryable, Selectable, AsChangeset, Identifiable)]
|
||||
#[diesel(table_name = crate::schema::participants)]
|
||||
pub struct Record {
|
||||
pub id: i32,
|
||||
pub display_name: String
|
||||
}
|
||||
|
||||
#[derive(Insertable)]
|
||||
#[diesel(table_name = crate::schema::participants)]
|
||||
pub struct InsertableRecord {
|
||||
pub display_name: String
|
||||
}
|
||||
|
||||
impl From<Participant> for InsertableRecord {
|
||||
fn from(participant: Participant) -> Self {
|
||||
InsertableRecord {
|
||||
display_name: participant.display_name
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Identifiable, Selectable, Queryable, Associations, Debug)]
|
||||
#[diesel(belongs_to(super::conversation::Record, foreign_key = conversation_id))]
|
||||
#[diesel(belongs_to(Record, foreign_key = participant_id))]
|
||||
|
||||
@@ -2,6 +2,5 @@ pub mod conversation;
|
||||
pub mod participant;
|
||||
pub mod db;
|
||||
|
||||
// Re-export the public types
|
||||
pub use conversation::Conversation;
|
||||
pub use participant::Participant;
|
||||
@@ -1,7 +1,4 @@
|
||||
use diesel::prelude::*;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Insertable)]
|
||||
#[diesel(table_name = crate::schema::participants)]
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct Participant {
|
||||
pub display_name: String,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user