From 85df91a80b2a63c0bed98a209be2744581859449 Mon Sep 17 00:00:00 2001 From: tedison Date: Fri, 13 Dec 2024 20:28:45 -0500 Subject: [PATCH] fix timestamp issue --- crates/torii/core/src/model.rs | 3 +-- crates/torii/grpc/src/server/mod.rs | 12 +++++++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/crates/torii/core/src/model.rs b/crates/torii/core/src/model.rs index 8f9e683c2a..f89d5217a8 100644 --- a/crates/torii/core/src/model.rs +++ b/crates/torii/core/src/model.rs @@ -184,8 +184,7 @@ pub fn build_sql_query( )); if internal_updated_at > 0 { - internal_updated_at_clause - .push(format!("[{model_table}].internal_updated_at > {}", internal_updated_at)); + internal_updated_at_clause.push(format!("[{model_table}].internal_updated_at > ?")); } // Collect columns with table prefix diff --git a/crates/torii/grpc/src/server/mod.rs b/crates/torii/grpc/src/server/mod.rs index 8eff829e14..538e21e8b5 100644 --- a/crates/torii/grpc/src/server/mod.rs +++ b/crates/torii/grpc/src/server/mod.rs @@ -27,6 +27,7 @@ use proto::world::{ use rayon::iter::{IntoParallelRefIterator, ParallelIterator}; use sqlx::prelude::FromRow; use sqlx::sqlite::SqliteRow; +use sqlx::types::chrono::{DateTime, Utc}; use sqlx::{Pool, Row, Sqlite}; use starknet::core::types::Felt; use starknet::providers::jsonrpc::HttpTransport; @@ -361,7 +362,16 @@ impl DojoWorld { internal_updated_at, )?; - let query = sqlx::query(&entity_query).bind(models_str); + let mut query = sqlx::query(&entity_query).bind(models_str); + if internal_updated_at > 0 { + for _ in 0..schemas.len() { + query = query.bind( + DateTime::::from_timestamp(internal_updated_at as i64, 0) + .ok_or_else(|| Error::from(QueryError::UnsupportedQuery))? + .to_rfc3339(), + ); + } + } let rows = query.fetch_all(&mut *tx).await?; let schemas = Arc::new(schemas);