diff --git a/crates/torii/core/src/model.rs b/crates/torii/core/src/model.rs index f194bacab0..2c60fd344e 100644 --- a/crates/torii/core/src/model.rs +++ b/crates/torii/core/src/model.rs @@ -173,7 +173,11 @@ pub fn parse_sql_model_members(model: &str, model_members_all: &[SqlModelMember] } /// Creates a query that fetches all models and their nested data. -pub fn build_sql_query(model_schemas: &Vec, entities_table: &str, entity_relation_column: &str) -> Result { +pub fn build_sql_query( + model_schemas: &Vec, + entities_table: &str, + entity_relation_column: &str, +) -> Result { fn parse_struct( path: &str, schema: &Struct, @@ -223,11 +227,16 @@ pub fn build_sql_query(model_schemas: &Vec, entities_table: &str, entity_rel let selections_clause = global_selections.join(", "); let join_clause = global_tables .into_iter() - .map(|table| format!(" JOIN {table} ON {entities_table}.id = {table}.{entity_relation_column}")) + .map(|table| { + format!(" JOIN {table} ON {entities_table}.id = {table}.{entity_relation_column}") + }) .collect::>() .join(" "); - Ok(format!("SELECT {entities_table}.id, {entities_table}.keys, {selections_clause} FROM {entities_table}{join_clause}")) + Ok(format!( + "SELECT {entities_table}.id, {entities_table}.keys, {selections_clause} FROM \ + {entities_table}{join_clause}" + )) } /// Populate the values of a Ty (schema) from SQLite row. diff --git a/crates/torii/grpc/src/server/subscriptions/entity.rs b/crates/torii/grpc/src/server/subscriptions/entity.rs index 1e9d851f62..a92b88543d 100644 --- a/crates/torii/grpc/src/server/subscriptions/entity.rs +++ b/crates/torii/grpc/src/server/subscriptions/entity.rs @@ -102,7 +102,10 @@ impl Service { let model_ids: Vec<&str> = model_ids.split(',').collect(); let schemas = cache.schemas(model_ids).await?; - let entity_query = format!("{} WHERE entities.id = ?", build_sql_query(&schemas, "entities", "entity_id")?); + let entity_query = format!( + "{} WHERE entities.id = ?", + build_sql_query(&schemas, "entities", "entity_id")? + ); let row = sqlx::query(&entity_query).bind(hashed_keys).fetch_one(&pool).await?; let models = schemas diff --git a/crates/torii/grpc/src/server/subscriptions/event_message.rs b/crates/torii/grpc/src/server/subscriptions/event_message.rs index c807a22a00..faf3518d0f 100644 --- a/crates/torii/grpc/src/server/subscriptions/event_message.rs +++ b/crates/torii/grpc/src/server/subscriptions/event_message.rs @@ -101,8 +101,10 @@ impl Service { let model_ids: Vec<&str> = model_ids.split(',').collect(); let schemas = cache.schemas(model_ids).await?; - let entity_query = - format!("{} WHERE event_messages.id = ?", build_sql_query(&schemas, "event_messages", "event_message_id")?); + let entity_query = format!( + "{} WHERE event_messages.id = ?", + build_sql_query(&schemas, "event_messages", "event_message_id")? + ); let row = sqlx::query(&entity_query).bind(hashed_keys).fetch_one(&pool).await?; let models = schemas