Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(torii-sqlite): deleting entity #2961

Merged
merged 7 commits into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions crates/torii/sqlite/src/executor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ pub enum BrokerMessage {
#[derive(Debug, Clone)]
pub struct DeleteEntityQuery {
pub entity_id: String,
pub model_id: String,
pub event_id: String,
pub block_timestamp: String,
pub ty: Ty,
Expand Down Expand Up @@ -474,6 +475,12 @@ impl<'c, P: Provider + Sync + Send + 'static> Executor<'c, P> {
return Ok(());
}

sqlx::query("DELETE FROM entity_model WHERE entity_id = ? AND model_id = ?")
.bind(entity.entity_id.clone())
.bind(entity.model_id)
.execute(&mut **tx)
.await?;

let row = sqlx::query(
"UPDATE entities SET updated_at=CURRENT_TIMESTAMP, executed_at=?, event_id=? \
WHERE id = ? RETURNING *",
Expand Down
10 changes: 4 additions & 6 deletions crates/torii/sqlite/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,16 +441,14 @@ impl Sql {
block_timestamp: u64,
) -> Result<()> {
let entity_id = format!("{:#x}", entity_id);
let model_id = format!("{:#x}", model_id);
let model_table = entity.name();

self.executor.send(QueryMessage::new(
format!(
"DELETE FROM [{model_table}] WHERE internal_id = ?; DELETE FROM entity_model \
WHERE entity_id = ? AND model_id = ?"
)
.to_string(),
vec![Argument::String(entity_id.clone()), Argument::String(format!("{:#x}", model_id))],
format!("DELETE FROM [{model_table}] WHERE internal_id = ?").to_string(),
vec![Argument::String(entity_id.clone())],
QueryType::DeleteEntity(DeleteEntityQuery {
model_id: model_id.clone(),
entity_id: entity_id.clone(),
event_id: event_id.to_string(),
block_timestamp: utc_dt_string_from_timestamp(block_timestamp),
Expand Down
Loading