55 lines
1.1 KiB
Rust
55 lines
1.1 KiB
Rust
use serde::{Deserialize, Serialize};
|
|
use crate::error::SirenResult;
|
|
|
|
const TABLE_NAME: &str = "messages";
|
|
|
|
#[derive(Debug, Serialize, Deserialize, sqlx::FromRow)]
|
|
pub struct MessageCache {
|
|
pub id: String,
|
|
pub guild_id: i64,
|
|
pub channel_id: i64,
|
|
pub user_id: i64,
|
|
pub created: i64,
|
|
pub model: String,
|
|
pub request: String,
|
|
pub response: String,
|
|
pub request_tags: Vec<String>,
|
|
pub response_tags: Vec<String>,
|
|
}
|
|
|
|
impl MessageCache {
|
|
pub async fn insert(&self) -> SirenResult<()> {
|
|
let pool = crate::database::pool();
|
|
sqlx::query(&format!(
|
|
"INSERT INTO {} (
|
|
id,
|
|
guild_id,
|
|
channel_id,
|
|
user_id,
|
|
created,
|
|
model,
|
|
request,
|
|
response,
|
|
request_tags,
|
|
response_tags
|
|
) VALUES (
|
|
$1, $2, $3, $4, $5, $6, $7, $8, $9, $10
|
|
)",
|
|
TABLE_NAME
|
|
))
|
|
.bind(&self.id)
|
|
.bind(self.guild_id)
|
|
.bind(self.channel_id)
|
|
.bind(self.user_id)
|
|
.bind(self.created)
|
|
.bind(&self.model)
|
|
.bind(&self.request)
|
|
.bind(&self.response)
|
|
.bind(&self.request_tags)
|
|
.bind(&self.response_tags)
|
|
.execute(pool)
|
|
.await?;
|
|
Ok(())
|
|
}
|
|
}
|