-
Notifications
You must be signed in to change notification settings - Fork 194
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
feat(torii-sql): granular model indices #3073
base: main
Are you sure you want to change the base?
Changes from 7 commits
098ce9a
fb0488f
f60aeef
795330b
4051f80
80e4ea6
6c636f8
2a01d08
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,6 +51,9 @@ pub struct ToriiArgs { | |
#[command(flatten)] | ||
pub erc: ErcOptions, | ||
|
||
#[command(flatten)] | ||
pub sql: SqlOptions, | ||
|
||
#[cfg(feature = "server")] | ||
#[command(flatten)] | ||
pub metrics: MetricsOptions, | ||
|
@@ -107,6 +110,10 @@ impl ToriiArgs { | |
self.erc = config.erc.unwrap_or_default(); | ||
} | ||
|
||
if self.sql == SqlOptions::default() { | ||
self.sql = config.sql.unwrap_or_default(); | ||
} | ||
|
||
#[cfg(feature = "server")] | ||
{ | ||
if self.server == ServerOptions::default() { | ||
|
@@ -136,6 +143,7 @@ pub struct ToriiArgsConfig { | |
pub indexing: Option<IndexingOptions>, | ||
pub events: Option<EventsOptions>, | ||
pub erc: Option<ErcOptions>, | ||
pub sql: Option<SqlOptions>, | ||
#[cfg(feature = "server")] | ||
pub metrics: Option<MetricsOptions>, | ||
#[cfg(feature = "server")] | ||
|
@@ -167,6 +175,7 @@ impl TryFrom<ToriiArgs> for ToriiArgsConfig { | |
config.events = | ||
if args.events == EventsOptions::default() { None } else { Some(args.events) }; | ||
config.erc = if args.erc == ErcOptions::default() { None } else { Some(args.erc) }; | ||
config.sql = if args.sql == SqlOptions::default() { None } else { Some(args.sql) }; | ||
|
||
#[cfg(feature = "server")] | ||
{ | ||
|
@@ -187,7 +196,7 @@ mod test { | |
use std::net::{IpAddr, Ipv4Addr}; | ||
use std::str::FromStr; | ||
|
||
use torii_sqlite::types::{Contract, ContractType}; | ||
use torii_sqlite::types::{Contract, ContractType, ModelIndices}; | ||
|
||
use super::*; | ||
|
||
|
@@ -208,6 +217,10 @@ mod test { | |
"ns-E", | ||
"ns-EH" | ||
] | ||
|
||
[[sql.model_indices]] | ||
model_tag = "ns-Position" | ||
fields = ["vec.x", "vec.y"] | ||
"#; | ||
let path = std::env::temp_dir().join("torii-config2.json"); | ||
std::fs::write(&path, content).unwrap(); | ||
|
@@ -225,6 +238,8 @@ mod test { | |
"--events.historical", | ||
"a-A", | ||
"--indexing.transactions", | ||
"--sql.model_indices", | ||
"ns-Position:vec.x,vec.y;ns-Moves:player", | ||
"--config", | ||
path_str.as_str(), | ||
]; | ||
|
@@ -238,6 +253,15 @@ mod test { | |
assert_eq!(torii_args.events.historical, vec!["a-A".to_string()]); | ||
assert_eq!(torii_args.server, ServerOptions::default()); | ||
assert!(torii_args.indexing.transactions); | ||
Comment on lines
253
to
255
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix formatting issue flagged by the CI pipeline. The CI pipeline reports a formatting issue on line 253. Please run 🧰 Tools🪛 GitHub Actions: ci[error] 253-253: Rust formatting check failed. The code does not adhere to the expected formatting style. |
||
assert_eq!(torii_args.sql.model_indices, Some(vec![ModelIndices { | ||
model_tag: "ns-Position".to_string(), | ||
fields: vec!["vec.x".to_string(), "vec.y".to_string()], | ||
}, | ||
ModelIndices { | ||
model_tag: "ns-Moves".to_string(), | ||
fields: vec!["player".to_string()], | ||
}, | ||
])); | ||
} | ||
|
||
#[test] | ||
|
@@ -269,6 +293,10 @@ mod test { | |
"erc721:0x5678" | ||
] | ||
namespaces = [] | ||
|
||
[[sql.model_indices]] | ||
model_tag = "ns-Position" | ||
fields = ["vec.x", "vec.y"] | ||
"#; | ||
let path = std::env::temp_dir().join("torii-config.json"); | ||
std::fs::write(&path, content).unwrap(); | ||
|
@@ -303,6 +331,13 @@ mod test { | |
} | ||
] | ||
); | ||
assert_eq!( | ||
torii_args.sql.model_indices, | ||
Some(vec![ModelIndices { | ||
model_tag: "ns-Position".to_string(), | ||
fields: vec!["vec.x".to_string(), "vec.y".to_string()], | ||
}]) | ||
); | ||
assert_eq!(torii_args.server.http_addr, IpAddr::V4(Ipv4Addr::LOCALHOST)); | ||
assert_eq!(torii_args.server.http_port, 7777); | ||
assert_eq!(torii_args.server.http_cors_origins, Some(vec!["*".to_string()])); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Verification agent
🧩 Analysis chain
LGTM! Adding SQL options to the CLI interface.
Ohayo! This change looks good, adding a new
sql
field toToriiArgs
with the#[command(flatten)]
attribute to expose SQL options in the CLI.However, I noticed that while you've added this field to
ToriiArgs
, there's no corresponding update toToriiArgsConfig
or the methods that handle configuration file loading (with_config_file
and theTryFrom<ToriiArgs>
implementation).Run the following script to examine the current pattern of including options in the configuration structure:
🏁 Script executed:
Length of output: 744
Ohayo, Sensei!
Great job adding the new SQL options to the CLI interface using the flattened attribute. However, our verification shows that unlike the other options (e.g.,
indexing
,events
,erc
,metrics
,server
,relay
), thesql
option lacks a corresponding counterpart in the configuration structure and the associated config file loading methods.ToriiArgsConfig
to include an equivalentOption<SqlOptions>
field.with_config_file
and theTryFrom<ToriiArgs>
implementation) to properly process the new SQL options.