Skip to content

Commit

Permalink
Added type enum col to torii indexer
Browse files Browse the repository at this point in the history
  • Loading branch information
broody committed Oct 3, 2023
1 parent cb79f2b commit b8bc50a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
3 changes: 2 additions & 1 deletion crates/dojo-types/src/schema.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use itertools::Itertools;
use serde::{Deserialize, Serialize};
use starknet::core::types::FieldElement;
use strum_macros::AsRefStr;

use crate::primitive::{Primitive, PrimitiveError};

Expand Down Expand Up @@ -33,7 +34,7 @@ pub struct ModelMetadata {
}

/// Represents all possible types in Cairo
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
#[derive(AsRefStr, Clone, Debug, Serialize, Deserialize, PartialEq)]
pub enum Ty {
Primitive(Primitive),
Struct(Struct),
Expand Down
5 changes: 3 additions & 2 deletions crates/torii/core/src/sql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,10 +335,11 @@ impl Sql {

self.query_queue.push(format!(
"INSERT OR IGNORE INTO model_members (id, model_id, model_idx, member_idx, \
name, type, key) VALUES ('{table_id}', '{}', '{model_idx}', '{member_idx}', \
'{name}', '{}', {})",
name, type, type_enum, key) VALUES ('{table_id}', '{}', '{model_idx}', \
'{member_idx}', '{name}', '{}', '{}', {})",
path[0],
member.ty.name(),
member.ty.as_ref(),
member.key,
));
}
Expand Down
1 change: 1 addition & 0 deletions crates/torii/migrations/20230316154230_setup.sql
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ CREATE TABLE model_members(
model_id TEXT NOT NULL,
name TEXT NOT NULL,
type TEXT NOT NULL,
type_enum TEXT DEFAULT 'Primitive' CHECK(type_enum IN ('Primitive', 'Struct', 'Enum', 'Tuple')) NOT NULL,
key BOOLEAN NOT NULL,
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (id, member_idx) FOREIGN KEY (model_id) REFERENCES models(id)
Expand Down

0 comments on commit b8bc50a

Please sign in to comment.