Update for schema 12

This commit is contained in:
Mike Dilger 2023-01-16 13:01:33 +13:00
parent fde7bff420
commit 2a5abebff2
2 changed files with 10 additions and 10 deletions

View File

@ -6,7 +6,7 @@ use tokio::task::spawn_blocking;
#[derive(Debug, Serialize, Deserialize)] #[derive(Debug, Serialize, Deserialize)]
pub struct DbEventRelationship { pub struct DbEventRelationship {
pub original: String, pub original: String,
pub referring: String, pub refers_to: String,
pub relationship: String, pub relationship: String,
pub content: Option<String>, pub content: Option<String>,
} }
@ -14,15 +14,15 @@ pub struct DbEventRelationship {
impl DbEventRelationship { impl DbEventRelationship {
pub async fn insert(&self) -> Result<(), Error> { pub async fn insert(&self) -> Result<(), Error> {
let original = self.original.clone(); let original = self.original.clone();
let referring = self.referring.clone(); let refers_to = self.refers_to.clone();
let relationship = self.relationship.clone(); let relationship = self.relationship.clone();
let content = self.content.clone(); let content = self.content.clone();
let sql = "INSERT OR IGNORE INTO event_relationship (original, referring, relationship, content) VALUES (?, ?, ?, ?)"; let sql = "INSERT OR IGNORE INTO event_relationship (original, refers_to, relationship, content) VALUES (?, ?, ?, ?)";
spawn_blocking(move || { spawn_blocking(move || {
let maybe_db = GLOBALS.db.blocking_lock(); let maybe_db = GLOBALS.db.blocking_lock();
let db = maybe_db.as_ref().unwrap(); let db = maybe_db.as_ref().unwrap();
let mut stmt = db.prepare(sql)?; let mut stmt = db.prepare(sql)?;
stmt.execute((&original, &referring, &relationship, &content))?; stmt.execute((&original, &refers_to, &relationship, &content))?;
Ok::<(), Error>(()) Ok::<(), Error>(())
}) })
.await??; .await??;
@ -30,9 +30,9 @@ impl DbEventRelationship {
} }
/* /*
pub async fn get_events_referring_to(id: Id) -> Result<Vec<DbEventRelationship>, Error> { pub async fn get_events_refers_to(id: Id) -> Result<Vec<DbEventRelationship>, Error> {
let sql = let sql =
"SELECT referring, relationship, content FROM event_relationship WHERE original=?"; "SELECT refers_to, relationship, content FROM event_relationship WHERE original=?";
let output: Result<Vec<DbEventRelationship>, Error> = spawn_blocking(move || { let output: Result<Vec<DbEventRelationship>, Error> = spawn_blocking(move || {
let maybe_db = GLOBALS.db.blocking_lock(); let maybe_db = GLOBALS.db.blocking_lock();
let db = maybe_db.as_ref().unwrap(); let db = maybe_db.as_ref().unwrap();
@ -40,7 +40,7 @@ impl DbEventRelationship {
let rows = stmt.query_map([id.as_hex_string()], |row| { let rows = stmt.query_map([id.as_hex_string()], |row| {
Ok(DbEventRelationship { Ok(DbEventRelationship {
original: id.as_hex_string(), original: id.as_hex_string(),
referring: row.get(0)?, refers_to: row.get(0)?,
relationship: row.get(1)?, relationship: row.get(1)?,
content: row.get(2)?, content: row.get(2)?,
}) })

View File

@ -129,7 +129,7 @@ pub async fn process_new_event(
if from_relay { if from_relay {
let db_event_relationship = DbEventRelationship { let db_event_relationship = DbEventRelationship {
original: event.id.as_hex_string(), original: event.id.as_hex_string(),
referring: id.as_hex_string(), refers_to: id.as_hex_string(),
relationship: "reply".to_string(), relationship: "reply".to_string(),
content: None, content: None,
}; };
@ -145,7 +145,7 @@ pub async fn process_new_event(
if from_relay { if from_relay {
let db_event_relationship = DbEventRelationship { let db_event_relationship = DbEventRelationship {
original: event.id.as_hex_string(), original: event.id.as_hex_string(),
referring: id.as_hex_string(), refers_to: id.as_hex_string(),
relationship: "reaction".to_string(), relationship: "reaction".to_string(),
content: Some(reaction.clone()), content: Some(reaction.clone()),
}; };
@ -162,7 +162,7 @@ pub async fn process_new_event(
if from_relay { if from_relay {
let db_event_relationship = DbEventRelationship { let db_event_relationship = DbEventRelationship {
original: event.id.as_hex_string(), original: event.id.as_hex_string(),
referring: id.as_hex_string(), refers_to: id.as_hex_string(),
relationship: "deletion".to_string(), relationship: "deletion".to_string(),
content: Some(reason.clone()), content: Some(reason.clone()),
// FIXME: this table should have one more column for optional data // FIXME: this table should have one more column for optional data