-
Notifications
You must be signed in to change notification settings - Fork 66
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
enhancement: implement find on entity #1446
Conversation
20b071a
to
7f65ed1
Compare
0ae23a6
to
a0f158d
Compare
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.
- Wow @lostman very well done 👏🏼
- Very clean and sets us up in a good spot to extend and continue the ORM work
- ⭐ ⭐⭐⭐⭐
- I left a comment about the syntax of your order clause. That's my only real feedback
- The rustdoc comments make this pretty easy to follow thankfully 🙏🏼
Co-authored-by: rashad <spam.rashad@protonmail.com>
c26e05e
to
f1bab60
Compare
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.
🥇
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.
Looks great, just left one comment about the usage of .unwrap()
.
fn find(query: impl Into<QueryFragment<Self>>) -> Option<Self> { | ||
let query: QueryFragment<Self> = query.into(); | ||
unsafe { | ||
let buff = bincode::serialize(&query.to_string()).unwrap(); | ||
let mut bufflen = (buff.len() as u32).to_le_bytes(); | ||
|
||
let ptr = | ||
ff_single_select(Self::TYPE_ID, buff.as_ptr(), bufflen.as_mut_ptr()); | ||
|
||
if !ptr.is_null() { | ||
let len = u32::from_le_bytes(bufflen) as usize; | ||
let bytes = Vec::from_raw_parts(ptr, len, len); | ||
let data = deserialize(&bytes).unwrap(); | ||
Some(Self::from_row(data)) | ||
} else { | ||
None | ||
} | ||
} | ||
} |
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.
Can we get rid of the .unwrap()
s here? From what I can tell, the other functions in this module don't use them.
Description
Closes #1437.
Example usage:
This PR extends the codegen to generate field selectors for an
@entity
, e.g.:Field<T>
structs implement methods such aseq
,gt
,lt
, etc., which return aFilter<T>
, which, in turn, can be combined usingand
andor
to produce a mode complexFilter<T>
. Finally, aFilter<T>
can be ordered ascending or descending, turning it into aQueryFragment<T>
.The
find
function onEntity
takes aFilter
orQueryFragment
and fetches the corresponding object from the database, if any exists.Testing steps
CI testing. This PR includes an integration test for added functionality.
Changelog
find(query: impl Into<QueryFragment<Self>>) -> Option<Self>
toEntity
.ff_single_select
to FFI, andsingle_select
to the indexer.fuel_indexer_plugin::find
module, which contains the code for generating SQL query fragments.field_selectors
, e.g.,pub fn base_chain_height() -> Field<ChainInfo, U32>
which are used to construct queries