Skip to content

Commit

Permalink
fix(torii): exact key matching issue (#861)
Browse files Browse the repository at this point in the history
  • Loading branch information
broody authored Sep 4, 2023
1 parent e095113 commit d2fce1a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
5 changes: 2 additions & 3 deletions crates/torii/core/src/sql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,11 +238,10 @@ impl State for Sql {
.fetch_optional(&self.pool)
.await?;

// TODO: map keys to individual columns
let keys_str = keys.iter().map(|k| format!("{:#x}", k)).collect::<Vec<String>>().join(",");
let keys_str = keys.iter().map(|k| format!("{:#x}", k)).collect::<Vec<String>>().join("/");
let component_names = component_names(entity_result, &component)?;
let insert_entities = format!(
"INSERT INTO entities (id, keys, component_names) VALUES ('{}', '{}', '{}') ON \
"INSERT INTO entities (id, keys, component_names) VALUES ('{}', '{}/', '{}') ON \
CONFLICT(id) DO UPDATE SET
component_names=excluded.component_names,
updated_at=CURRENT_TIMESTAMP",
Expand Down
8 changes: 5 additions & 3 deletions crates/torii/graphql/src/object/entity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ impl Default for EntityObject {
}
}
}

impl EntityObject {
pub fn value_mapping(entity: Entity) -> ValueMapping {
let keys: Vec<&str> = entity.keys.split(',').map(|s| s.trim()).collect();
let keys: Vec<&str> = entity.keys.split('/').filter(|&k| !k.is_empty()).collect();
IndexMap::from([
(Name::new("id"), Value::from(entity.id)),
(Name::new("keys"), Value::from(keys)),
Expand Down Expand Up @@ -172,8 +173,9 @@ async fn entities_by_sk(
let mut conditions = Vec::new();

if let Some(keys) = &keys {
conditions.push(format!("keys LIKE '{}%'", keys.join(",")));
count_query.push_str(&format!(" WHERE keys LIKE '{}%'", keys.join(",")));
let keys_str = keys.join("/");
conditions.push(format!("keys LIKE '{}/%'", keys_str));
count_query.push_str(&format!(" WHERE keys LIKE '{}/%'", keys_str));
}

if let Some(after_cursor) = &args.after {
Expand Down

0 comments on commit d2fce1a

Please sign in to comment.