Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Larkooo committed Apr 24, 2024
1 parent 37b8d4b commit 53547b8
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
15 changes: 12 additions & 3 deletions crates/torii/core/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Ty>, entities_table: &str, entity_relation_column: &str) -> Result<String, Error> {
pub fn build_sql_query(
model_schemas: &Vec<Ty>,
entities_table: &str,
entity_relation_column: &str,
) -> Result<String, Error> {
fn parse_struct(
path: &str,
schema: &Struct,
Expand Down Expand Up @@ -223,11 +227,16 @@ pub fn build_sql_query(model_schemas: &Vec<Ty>, 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::<Vec<_>>()
.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.
Expand Down
5 changes: 4 additions & 1 deletion crates/torii/grpc/src/server/subscriptions/entity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")?

Check warning on line 107 in crates/torii/grpc/src/server/subscriptions/entity.rs

View check run for this annotation

Codecov / codecov/patch

crates/torii/grpc/src/server/subscriptions/entity.rs#L105-L107

Added lines #L105 - L107 were not covered by tests
);
let row = sqlx::query(&entity_query).bind(hashed_keys).fetch_one(&pool).await?;

let models = schemas
Expand Down
6 changes: 4 additions & 2 deletions crates/torii/grpc/src/server/subscriptions/event_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")?

Check warning on line 106 in crates/torii/grpc/src/server/subscriptions/event_message.rs

View check run for this annotation

Codecov / codecov/patch

crates/torii/grpc/src/server/subscriptions/event_message.rs#L104-L106

Added lines #L104 - L106 were not covered by tests
);
let row = sqlx::query(&entity_query).bind(hashed_keys).fetch_one(&pool).await?;

let models = schemas
Expand Down

0 comments on commit 53547b8

Please sign in to comment.