-
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(dojo-core): add read schema support #2932
Changes from 5 commits
66c882e
dbe3895
30c7d3c
77ea57a
772f1a7
33b5026
790bc56
b95b94b
5dd114c
1ed7b99
5643b53
95bdb30
b3ea517
89883f7
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 |
---|---|---|
|
@@ -3,7 +3,7 @@ use dojo::{ | |
utils::{entity_id_from_serialized_keys, find_model_field_layout, entity_id_from_keys}, | ||
}; | ||
|
||
use super::{ModelDefinition, ModelDef}; | ||
use super::{ModelDefinition, ModelDef, ModelIndex}; | ||
/// Trait `KeyParser` defines a trait for parsing keys from a given model. | ||
/// | ||
/// A pointer to a model, which can be expressed by an entity id. | ||
|
@@ -12,6 +12,20 @@ pub struct ModelPtr<M> { | |
pub id: felt252, | ||
} | ||
|
||
pub trait ModelPtrsTrait<M> { | ||
fn to_indexes(self: Span<ModelPtr<M>>) -> Span<ModelIndex>; | ||
} | ||
|
||
pub impl ModelPtrsImpl<M> of ModelPtrsTrait<M> { | ||
fn to_indexes(self: Span<ModelPtr<M>>) -> Span<ModelIndex> { | ||
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. Could you document this function and why it has been necessary adding it? |
||
let mut ids = ArrayTrait::<ModelIndex>::new(); | ||
for ptr in self { | ||
ids.append(ModelIndex::Id(*ptr.id)); | ||
}; | ||
ids.span() | ||
} | ||
} | ||
|
||
pub trait KeyParser<M, K> { | ||
/// Parses the key from the given model. | ||
fn parse_key(self: @M) -> K; | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,4 +1,4 @@ | ||||||||||||||||||||||||||
use dojo::{model::{ModelPtr, model_value::ModelValueKey}}; | ||||||||||||||||||||||||||
use dojo::{model::{ModelPtr, model_value::ModelValueKey}, meta::Introspect}; | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
// TODO: define the right interface for member accesses. | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
|
@@ -35,10 +35,18 @@ pub trait ModelStorage<S, M> { | |||||||||||||||||||||||||
/// The ptr is mostly used for type inferrence. | ||||||||||||||||||||||||||
fn erase_models_ptrs(ref self: S, ptrs: Span<ModelPtr<M>>); | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
/// Retrieves a model of type `M` using the provided entity idref . | ||||||||||||||||||||||||||
/// Retrieves a model of type `M` using the provided entity id. | ||||||||||||||||||||||||||
fn read_member<T, +Serde<T>>(self: @S, ptr: ModelPtr<M>, field_selector: felt252) -> T; | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
/// Retrieves a model of type `M` using the provided entity id. | ||||||||||||||||||||||||||
/// Retrieves part of a model, matching a schema. | ||||||||||||||||||||||||||
fn read_schema<T, +Serde<T>, +Introspect<T>>(self: @S, ptr: ModelPtr<M>) -> T; | ||||||||||||||||||||||||||
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. Let's add a bit more comments here, to show what a schema is. |
||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
/// Retrieves part of multiple models, matching a schema. | ||||||||||||||||||||||||||
fn read_schemas<T, +Drop<T>, +Serde<T>, +Introspect<T>>( | ||||||||||||||||||||||||||
self: @S, ptrs: Span<ModelPtr<M>> | ||||||||||||||||||||||||||
) -> Array<T>; | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
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. Add missing trailing commas in function definitions In the definitions of Apply this diff to fix the issue: fn read_schema<T, +Serde<T>, +Introspect<T>>(self: @S, ptr: ModelPtr<M>) -> T;
/// Retrieves part of multiple models, matching a schema.
fn read_schemas<T, +Drop<T>, +Serde<T>, +Introspect<T>>(
self: @S, ptrs: Span<ModelPtr<M>>,
) -> Array<T>; 📝 Committable suggestion
Suggested change
🧰 Tools🪛 GitHub Actions: ci[error] 43-46: Missing trailing comma in function parameter list |
||||||||||||||||||||||||||
/// Updates a member of a model. | ||||||||||||||||||||||||||
fn write_member<T, +Serde<T>, +Drop<T>>( | ||||||||||||||||||||||||||
ref self: S, ptr: ModelPtr<M>, field_selector: felt252, value: T, | ||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||
|
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.
Let's use more descriptive names please.